[antlr-interest] 3.0b5: help with parse puzzle
Paul Shaffer
antlr1 at cyberplasm.com
Thu Nov 23 22:39:51 PST 2006
Ok, thank you. "in the parser" seemed to be a clue -- I am an idiot. This
works for now:
grammar s1;
options {
language = CSharp;
//filter=true;
}
program: string_def*
;
string_def: s = LINE
{ Console.Out.WriteLine("string_def: " + s.Text); }
;
LINE: ID WS* '=' (~'\n')+ '\n' ;
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
;
WS : (' '|'\n'|'\r')+ {$channel=HIDDEN;}
;
At 10:41 PM 11/23/2006, you wrote:
>hi. ~'\n' won't do you much good in the parser. ;)
>
>That error is saying it found EOF.
>
>Ter
>On Nov 23, 2006, at 9:11 PM, Paul Shaffer wrote:
>
>>Can you suggest a fix for this?
>>
>>g file:
>>
>>grammar s1;
>>options {
>> language = CSharp;
>> filter=true;
>>}
>>program: string_def+ ;
>>
>>string_def: ID '=' (~'\n')+ '\n' { Console.Out.WriteLine ("found
>>string_def"); } ;
>>
>>ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')* ;
>>
>>WS : (' '|'\n'|'\r')+ {$channel=HIDDEN;} ;
>>
>>
>>Input line, it can contain a '\' followed by a 'n' anywhere. Line
>>is terminated in 0D 0A.
>>
>>testline = "This is a test line I am working on "with difficulty".\n
>>\nSometimes we meet some troublesome characters.\n\nTime's a wastin'."
>>
>>
>>Runtime error message:
>>
>>[string_def]: line 0:-1 mismatched token: [@0,0:0='<no text>',<-1>,
>>0:-1]; expecting type '\n'
>>
>>Can someone interpret what this line says? I don't know how to read
>>it.
>>
>>If I turn off filtering, I also get a "no viable alt line" error on
>>every . \ and " in the input.
More information about the antlr-interest
mailing list