Using the Parsec library

Jose Romildo Malaquias romildo@uber.com.br
Mon, 9 Sep 2002 20:34:15 -0300


Hello.

Can anyone help me writing a parser for parsing a simplified
list of ABC fields (http://www.gre.ac.uk/~c.walshaw/abc/).

The grammar I want to test with is the following

------------------
file ::= *field

field ::= fieldA | fieldB

fieldA ::= "A:" text endOfLine

fieldB ::= "B:" text endOfLine restTextB

restTextB ::= (text endOfLine) 'not starting with "A:" or "B:"'

text ::= *(LETTER | DIGIT | SPACE | ":")

endOfLine ::= LF | CR LF
------------------

The parser I am trying:

------------------
file = many field

field = fieldA <|> fieldB

fieldA = do string "A:"
            text
	    endOfLine

fieldB = do string "B:"
            text
            endOfLine
            restTextB -- not starting with "A:" or "B:"

restTextB = do text
               endOfLine

text = many (letter <|> digit <|> space <|> char ':')

endOfLine = string "\n" | string "\r\n"
------------------

Example of input:

------------------
A:1
B:Traditional
A:2
B:Line 1
  Line 2
A Line 3
BBLine 4
A:3
------------------


Any sugestion on how to implement the 'not starting with
"A:" or "B:"' problem?

Romildo
-- 
Prof. José Romildo Malaquias
Departamento de Computação - Universidade Federal de Ouro Preto
http://www.decom.ufop.br/prof/romildo/	malaquias@iceb.ufop.br
http://uber.com.br/romildo/		romildo@uber.com.br