[antlr-interest] Parsing Question

Chris Wegener chris at wegenerconsulting.com
Thu Jul 7 17:15:26 PDT 2011


Dear Friends-

 

I am attempting to define a language that will let me parse knitting
instructions.  (Don't ask.)

 

By and large it is a well understood convention with standard abbreviations
and phrases.  Occasionally the originator will insert a phrase in the
instructions that are not directly relevant.  What I would like is to parse
out those words and deal with them around the issue of reading the
instructions.  I have tried:

 

text :    (letter)+;

letter :  ('a'..'z' | 'A'..'Z');

WS   :    (' ' | '\n' | '\r');

 

And it doesn't work at all.  I changed it to:

 

text :   (letter)+;

letter :~('"' | '\\');

WS   :   (' ' | '\n' | '\r');


That works, but becomes unweildy very quickly when I start including all of
the things I do know to scan for. I have attached the KnittingGrammer.g file
with my rules.

For example:

"1st Section: Cast on 63 stitches (sts) and work in pattern as follows:" is
parsed into '1st Section:' and 'Cast on 63 stitches (sts)' which leaves the
text until the colon which is the stop character.  I would like to parse the
'and work in pattern as follows' into the parse tree under text so I can
inspect it or lex it seperately or even display to the user.

What am I missing or doing wrong?

My thanks for your help in advance.

Regards,

Chris

 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: KnittingGrammer.g
Type: application/octet-stream
Size: 1175 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20110707/eb7f5c40/attachment.obj 


More information about the antlr-interest mailing list