Why are antlr3 c# parser methods private?
Asked Answered
B

1

14

I'm building a parser in antlr which compiles to a working java target. When I retarget for c#2 it produces a parser in which all of the parse methods are private but marked with a [GrammarRule("rulename")] attribute.

What is the approved means to actually invoke the parser?

I am using ANTLR 3.3 Nov 30, 2010 12:45:30

Thanks, Andy

Bloater answered 20/6, 2011 at 12:59 Comment(0)
U
20

Make at least one parser rule "public" like this:

grammar T;

options {
  language=CSharp2;
}

public parse
  :  privateRule+ EOF
  ;

privateRule
  :  Token+
  ;

// ...

You can then call parse() on the generated parser.

protected and private (the default if nothing is specified) are also supported.

Unbounded answered 20/6, 2011 at 13:6 Comment(2)
Thanks, I couldn't find any documentation to this effect.Bloater
@Andy, you're welcome. Yeah, it works a bit differently than the Java target where you can use these keywords, but are not implemented. ANTLR's Java target by default produces the public modifier. So it should still work with the Java target if you put a public before some parser rule.Unbounded

© 2022 - 2024 — McMap. All rights reserved.