[il-antlr-interest: 31169] [antlr-interest] a range as single token?

2011-01-15 Thread fikin
most likely this is obviously stupid question, pardon me in advance please.

what exactly is wrong with this grammar?

lines   :   line (NEWLINE line)*;
line:   '\u0020'..'\u007F'*;
NEWLINE :   '\r'? '\n';

...
[12:40:17] warning(200): dd.g:4:9: Decision can match input such as
EOF using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
...
[12:40:17] Interpreting...
[12:40:17] problem matching token at 1:1
NoViableAltException('1'@[1:1: Tokens : ( T__5 | T__6 | NEWLINE );])
...

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
il-antlr-interest group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31170] Re: [antlr-interest] a range as single token?

2011-01-15 Thread Bart Kiers
On Sat, Jan 15, 2011 at 11:43 AM, fikin nikolai.fii...@gmail.com wrote:

 most likely this is obviously stupid question, pardon me in advance please.

 what exactly is wrong with this grammar?

 lines   :   line (NEWLINE line)*;
 line:   '\u0020'..'\u007F'*;
 NEWLINE :   '\r'? '\n';


The range operator works differently inside a parser-rule.
For example, the rule *foo*:

foo
  :  A..C
  ;

A : 'a';
Z : 'z';
C : 'c';


will match one of the tokens A, Z or C (not one of the characters 'a', 'b'
or 'c'!).

Just as the `.` (DOT meta character) that has a different meaning depending
in which rule it is used: it means 'any character' inside lexer rules, while
it means 'any token' inside parser rules.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
il-antlr-interest group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31172] Re: [antlr-interest] a range as single token?

2011-01-15 Thread Bart Kiers

 i also noticed that following works just fine:
 lines   :   line (NEWLINE line)*;
 line:   CHAR*;
 NEWLINE :   '\r'? '\n';
 CHAR:   '\u0020'..'\u007F';


Yes, because you are now using the range operator inside a lexer rule (I
presume you know the difference between parser- and lexer rules?).



 is there a way i can make a rule token is a sequence of values as
 opposing a sequence of tokens?


I don't know what you mean by that.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
il-antlr-interest group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31173] Re: [antlr-interest] a range as single token?

2011-01-15 Thread Bart Kiers
On Sat, Jan 15, 2011 at 1:23 PM, fikin nikolai.fii...@gmail.com wrote:

 right. is there a way to make the lexer provide line content as
 single token as opposing to a container of char tokens?


Sure, like this:

lines   :   CHARS (NEWLINE CHARS)*;
NEWLINE :   '\r'? '\n';
CHARS   :   '\u0020'..'\u007F'+;


And if there can be empty lines, do:

lines   :   CHARS? (NEWLINE CHARS?)*;


Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
il-antlr-interest group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.