[antlr-interest] Default token?
stephen at perceptisys.co.uk
Sun Apr 8 12:06:42 PDT 2012
Yes there is, "simply use":
OTHER : . ;
BUT beware of using .+ as this might gobble up all the rest of the
characters in your parse.
The best discussion of this topic and this example, comes from Terence's
excellent book: "The Definitive ANTLR reference". It is well worth the
cost as it is a very good introduction.
If you have the book search for "greedy" and/or look on page 290.
On 08/04/2012 18:27, Tangeleno wrote:
> I'm having a bit of trouble with my lexer, the language I'm working on
> building a parser for does not require strings to be surrounded by
> quotes, for example all of these are valid
> string1:Set[This is string 1,this is not string 1] //commas separate
> params, string1:Set takes one, any extras are thrown away
> strin1:Set[This is all one string] //I end on the right square bracket
> string1:Set["This is string 1,this is all string 1"] // standard string,
> surrounded in quotes to ignore the comma
> variable string string1 = This is string 1 //Ends on the new line
> variable ComplexType ct = "Param1" 2 "Param3" //Param1 and 3 are strings
> but param2 is an int
> echo "This is string 1" "This would be a separate string" //Quoted
> strings are separated by a space or comma
> echo This is all one string
> echo \t\t I also accept \r\n escape sequences!
> SomeCommand0(This is all one string)
> SomeCommand2(1,2,3,4,Those are all ints)
> SomeCommand3(I can be anywhere!,1,2,3)
> I am wondering if there is a way to set a lexer rule to the default
> option if no other lexer rule matches, or any other tips on how to
> handle this.
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest