I try define iniFile grammer(keys contains few subvalues).
I defined it from C# Regex:
Regex commentLine = new Regex(@"^\s*#(?<comment>.*)", RegexOptions.Compiled);
Regex sectionLine = new Regex(@"^\s*\[(?<section>.*)\].*", 
RegexOptions.Compiled);
//Regex recordLine = new 
Regex(@"^\s*(?<key>[^#[=\s]+)\s*=?\s*(?<values>[^#]*)(#(?<comment>.*))?", 
RegexOptions.Compiled);
Regex recordLine2 = new 
Regex(@"^\s*(?<key>[^#[=\s]+)\s*=?\s*((?<value>[^;\#]*);)*(?<endValue>[^;\#]*[^;\s\#]+)?\s*(#(?<comment>.*))?",
 RegexOptions.Compiled);
foreach(var c in recordLine2.Math(string).Groups["value"].Captures)
        //access to each value of key
Sample ini struct:
#comment
[section]
key1
key2=
key3= # this and earlier lines contains 0 values
key4=a# 1 values
key5=;# 1 empty values
key6=a;f # 2 values
key7= a ; f;; # 3 values
[section2]
..
But I don't know how implement endValue(without semicolon) and get lot of 
warnings from my grammer. 
This grammer return wrong parse tree([section2] as keyLine).
I testet grammer in ANTLRWork 1.4.3

grammar test;
WS      :       (' '|'\t')      {$channel=HIDDEN;};
EOL     :       ('\r\n'|'\n'|'\r') ;
SHARP   :       '#' {System.out.println("#");};
EQUAL   :       '=' {System.out.println("=");};
SEMICOLON       :       ';' {System.out.println(";");};         
COMMENT :       SHARP .* EOL ;//{System.out.println("COM");};
SECTION :       '[' .* ']' {System.out.println("SEC");};
ANY     :       . {System.out.println("ANY");};
iniFile 
        :       section* EOF;
section 
        : commentLine* sectionLine COMMENT* (keyLine COMMENT?)*;
commentLine     
        : COMMENT;
sectionLine
        : SECTION (EOL|COMMENT);
keyLine 
        :       key keyValues* (EOL|COMMENT);
key     
        :       ~('='|'#'|'['|EOL)+  {System.out.println("key");};
keyValues
        : '=' (keyValue';')*;
keyValue:       ~(';'|'#'|EOL)* ;       

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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to