[antlr-interest] multi line identifiers

向秦贤 fyaoxy at gmail.com
Wed Sep 12 22:43:37 PDT 2007


OK, again, the myself pool english man ON:)
1, I not sure why only focus on lexer.
2, NewLine process. from your follow form NewLine should ignore, I
cannot see why of NewLine in lexer rule.
3, gunit can help you do better.


2007/9/13, Putrycz, Erik <Erik.Putrycz at nrc-cnrc.gc.ca>:
> I'm having great trouble trying to implement multi line identifiers in
> antlr 3.
> In Cobol, one of the wild cases is that an identifier can have the
> following form
>      CALL 'DSNHADDR' USING SQL-VPARMPTR OF SQL-PLIST7 SQL-PVAR-LIS
> -    T7.
> This is equivalent to CALL 'DSNHADDR' USING SQL-VPARMPTR OF SQL-PLIST7
> SQL-PVAR-LIST7
>
> My identifier rule is
> fragment
> NameElem
>         : Letter | Digit | '-';
>
> fragment
> ContinuedName   :
>         NewLine ContinuedLine Space*
>         ;
>
> fragment
> ContinuedLine
>         :{getCharPositionInLine() == 0 }? '-'
>         ;
>
> Name    : (Letter ~(NameElem)) => Letter
>         | (NameElem+ ContinuedName NameElem) => NameElem+ ContinuedName
> NameElem+
>         | (Digit (Digit|'-')*)? Letter NameElem*
>         ;
>
> This works fine for recognizing multi line identifiers but it is causing
> a very strange side effect.
> The last token of the last line of the input gets recognized as Name
> instead of a literal. If I remove the second alternative (the multi line
> case) to the Name then the last token is recognized correctly as a
> literal. This defies my logic how the second alternative can affect the
> third one and fail the literal recognition.
>
> Erik
>
>


-- 
致敬
向秦贤


More information about the antlr-interest mailing list