Context sensitive 'whitespace' ?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jack_Hyde
Posted On:   Wednesday, January 4, 2006 02:21 PM

I am constructing a parser that is line based, some lines are commands and have rigorous syntax, other lines are just plain text and do *not* have a grammar. In the command lines 'whitespace' is not relevant. In the 'plain text' lines I need to retain 'whitespace'. The following lexical rules have been described: WS : (' ' | ' ')+; PTEXT : (~(' '|' '))+; The command lines all start with a keyword, thus there are additional lexical rules have been described: KEY1 : "key1"; KEY2 : "key2"; ... The basic grammar rule is as foll   More>>

I am constructing a parser that is line based, some lines are commands and have rigorous syntax, other lines are just plain text and do *not* have a grammar.


In the command lines 'whitespace' is not relevant.


In the 'plain text' lines I need to retain 'whitespace'.


The following lexical rules have been described:


WS : (' ' | ' ')+;


PTEXT : (~('
'|'
'))+;


The command lines all start with a keyword, thus there are additional lexical rules have been described:


KEY1 : "key1";


KEY2 : "key2";


...


The basic grammar rule is as follows:


line : ((WS)? KEY1 ...)


| ((WS)? KEY2 ...)


| ...


| (PTEXT)


If the keywords appear without any leading 'whitespace' all works well, however if 'whitespace' is present then there are recognition failures.


I have, in addition, tried placing the optional 'whitespace' as a part of the lexical rules, as follows:


protected WS : (' ' | ' ')+;


KEY1 : (WS)? "key1";


Fails in the same manner.


Any help in resolving how to deal with this issue would be welcome.

   <<Less
About | Sitemap | Contact