dcsimg
Parsing property values
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Roland_Hochmuth
Posted On:   Wednesday, February 24, 2010 11:11 AM

Hi Guys, I'm an ANTLR newbie. Not sure why, but so far, I'm having a blast. One problem I'm running into is I'm trying to parse a program config file that looks something like this. Property.Property1=value1 Property.Property2=val ue2 Property.Property3=val ue3 Note, the space characeters in "val ue2" and newline in "val ue3". The delimiter for a property value is the start of another property. The value, is any and all characters including space and newlines, up to the start of a new "Property'. I've tried to write a nongreedy grammar, that will skip over any characters, until it matches 'Property', but it isn't worki   More>>


Hi Guys, I'm an ANTLR newbie. Not sure why, but so far, I'm having a blast. One problem I'm running into is I'm trying to parse a program config file that looks something like this.



			
Property.Property1=value1
Property.Property2=val ue2
Property.Property3=val
ue3



Note, the space characeters in "val ue2" and newline in "val
ue3". The delimiter for a property value is the start of another property. The value, is any and all characters including space and newlines, up to the start of a new "Property'.




I've tried to write a nongreedy grammar, that will skip over any characters, until it matches 'Property', but it isn't working. I get a NoViableAltException.




Any ideas? My grammar is below. Regards --Roland



			
grammar ProgramConfig;

statements
: propertyStatement*
;

propertyStatement
: PROPERTY_PREFIX PROPERTY_SUFFIX '=' PROPERTY_VALUE
;

PROPERTY_PREFIX
: '-'? 'Property'
;

PROPERTY_SUFFIX
: ('.' ('a'..'z' | 'A'..'Z' | '0'..'9')+)+
;

PROPERTY_VALUE
: (options {greedy=false; k=10;} : .+ )+ PROPERTY_PREFIX
;
   <<Less
About | Sitemap | Contact