Having a bit of difficulty in figuring out how to unambiguously parse this into an AST. Order of the elements is significant, the parens are significant, and the leading dot is significant.

  (.buf_unittest.complex_opt1).foo;
  .buf_unittest.complex_opt1.fum;
  (buf_unittest.complex_opt1).(.buf_unittest.quux);
  (.buf_unittest.complex_opt1).(buf_unittest.corge).qux;
  (complex_opt2).baz;
  (complex_opt2).(grault);
  (complex_opt2).bar.foo;
  (complex_opt2).bar.(quux);
  (complex_opt2).bar.(buf_unittest.corge).qux;
  (complex_opt2).(garply).foo;
  (complex_opt2).(garply).(.buf_unittest.quux);
  (complex_opt2).(buf_unittest.garply).(corge).qux;
  (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo;
  (complex_opt2).fred.waldo;
  (buf_unittest.complex_opt3).qux;
  (complex_opt3).complexoptiontype5.plugh;
  (complexopt6).xyzzy;

The rule ident_parens following appears to work, but Antlr is complaining "Decision can match input such as "'.' ID" using multiple alternatives: 1, 2" on both identN and identO. I can see the theoretical overlap, but cannot tell if the warning is actually significant or how to fix the rules to avoid the warning.

ident_parens
    : (identM | identN | identO ) ('.' ( identM | identO ) )*
    ;

identM
    :  '(' '.' ipd+=ID ( '.' ipd+=ID )* ')'   -> ^( IDENT_PARENSDOT $ipd+ )
    |  '(' ip+=ID ( '.' ip+=ID )* ')'         -> ^( IDENT_PARENS $ip+ )
    ;

identN
    : '.' id+=ID ( '.' id+=ID )*              -> ^( IDENT_DOT $id+ )
    ;

identO
    : i+=ID ( '.' i+=ID )*                    -> ^( IDENT $i+ )
    ;


Thanks...

grammar PBTest ;

options { 
        ASTLabelType = CommonTree;
        output = AST;
}

tokens { 
        MAIN;
        IDENT = 'ident';
        IDENT_DOT = 'ident_dot';
        IDENT_PARENS = 'ident_parens';
        IDENT_PARENSDOT = 'ident_parens_dot';
}

// 
/////////////////////////////////////////////////////////////////////////////////

@parser::header {
        
        package net.certiv.core.parser.gen;
}

@lexer::header {
        
        package net.certiv.core.parser.gen;
}

ident
        : ident_parens+ EOF  -> ^( MAIN ident_parens+ )
        ;

ident_parens
        :  ( identM | identN | identO )  ( '.' ( identM | identO )  )* ';'
        ;

identM
        : '(' '.' ipd+=ID ( '.' ipd+=ID )* ')'          -> ^( IDENT_PARENSDOT 
$ipd+ )
        | '(' ip+=ID ( '.' ip+=ID )* ')'                        -> ^( 
IDENT_PARENS $ip+ )
        ;

identN
        : '.' id+=ID ( '.' id+=ID )* -> ^( IDENT_DOT $id+ )
        ;

identO
        : i+=ID ( '.' i+=ID )* -> ^( IDENT $i+ )
        ;

// ///////////////////////////////////////////////////////////////////////


ID
        : LETTER ( LETTER | '_' | DIGIT )*
        ;

fragment
LETTER
        : UPPER | LOWER
        ;

fragment
DIGIT
        : '0'..'9'
        ;

fragment
LOWER
        : 'a'..'z'
        ;

fragment
UPPER
        : 'A'..'Z'
        ;

WS
        :  ( ' ' | '\r' | '\t' | '\u000C' | '\n' ) { $channel = HIDDEN; }
        ;

  (.buf_unittest.complex_opt1).foo;
  .buf_unittest.complex_opt1.fum;
  (buf_unittest.complex_opt1).(.buf_unittest.quux);
  (.buf_unittest.complex_opt1).(buf_unittest.corge).qux;
  (complex_opt2).baz;
  (complex_opt2).(grault);
  (complex_opt2).bar.foo;
  (complex_opt2).bar.(quux);
  (complex_opt2).bar.(buf_unittest.corge).qux;
  (complex_opt2).(garply).foo;
  (complex_opt2).(garply).(.buf_unittest.quux);
  (complex_opt2).(buf_unittest.garply).(corge).qux;
  (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo;
  (complex_opt2).fred.waldo;
  (buf_unittest.complex_opt3).qux;
  (complex_opt3).complexoptiontype5.plugh;
  (complexopt6).xyzzy;
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 il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to