[antlr-interest] [CSharp3] rule visibility in composite grammars

Sam Harwell sharwell at pixelminegames.com
Thu Apr 7 06:56:31 PDT 2011


The visibility of delegated rules now matches the way they're declared in
the imported grammar. Since some of them return nested classes declared in
the delegate grammar, I had to make the delegate grammar 'public' and all
its rules 'internal'.

I fixed the reserved names issue right after releasing 3.3.1, so it'll be
included when I release 3.3.2. Note that rule parameters and return values
need to include an explicit '@' in their declarations in the grammar, as
follows. Labels and rule names do not need the '@'.

namespace[int @in] returns [int @out] : as=A B;

Sam

-----Original Message-----
From: Ranco Marcus [mailto:ranco.marcus at epirion.nl] 
Sent: Thursday, April 07, 2011 6:49 AM
To: Sam Harwell; antlr-interest at antlr.org
Subject: RE: [antlr-interest] [CSharp3] rule visibility in composite
grammars

Sounds great, Sam! 

What will be the visibility of the methods in the 'Delegated rules' region
now that the class of the imported grammar is internal? Private or internal?

Another small suggestion is to prefix variable names (at least those that
are reserved in C#) with an at-sign. The generated class for the grammar
below has a compile error since 'as' is not a valid variable name while
'@as' is. 

name : as=firstName lastName;

Are you planning to release new binaries any time soon? 

Thanks again,

Ranco Marcus

> -----Original Message-----
> From: Sam Harwell [mailto:sharwell at pixelminegames.com]
> Sent: woensdag 6 april 2011 17:20
> To: Ranco Marcus; antlr-interest at antlr.org
> Subject: RE: [antlr-interest] [CSharp3] rule visibility in composite 
> grammars
> 
> Hi Ranco,
> 
> I made the following changes so far:
> 
> * An imported grammar is always generated as an internal class instead 
> of a public class.
> * Rules within the imported grammar are always declared public since 
> they are only called by the root grammar.
> 
> How does that sound?
> 
> Sam
> 
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org 
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Ranco Marcus
> Sent: Wednesday, March 23, 2011 6:40 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] [CSharp3] rule visibility in composite 
> grammars
> 
> Hi all/Sam,
> 
> While using the CSharp3 target on a composite grammar, I came across a 
> few issues regarding rule visibility.
> 
> If no modifier (private, protected, public, ...) is specified for a 
> rule, the Java target generates public methods (since it is not 
> implemented IIRC) and the
> CSharp3 target generates private methods.
> 
> I like the idea to explicitly specify which rules are callable (by 
> making them public). However, for composite grammars the generated 
> parser contains delegate rules for every rule of the imported grammar, 
> even for rules in the imported grammar that aren't public (causing 
> compile errors). This can solved this adding a public modifier to 
> every rule of the imported grammar, but I was wondering if there's a more
convenient way of doing this.
> 
> Furthermore, the methods for the delegate rules in the composite 
> grammars are all public, regardless of the visibility of the rule in the
imported grammar.
> IMHO, it would be better to make them private and use the composite 
> grammar to explicitly specify the rules that are externally visible. 
> What are your thoughts on this?
> 
> Btw, the CSharp3 templates are also included in the original Java 
> tool. Does that mean that we don't need the .NET version of the tool
anymore?
> 
> 
> Best regards,
> 
> Ranco Marcus
> Epirion Knowledge Solutions B.V.
> 
> 
> 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 mailing list