Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added examples to clarify the syntax for specifying the C# namespace in the different grammar types

...

You can specify that your generated recognizer should be declared within a specific namespace as shown below. By default all recognizers are generated as top-level types with no enclosing namespace.

Code Block
@lexergrammar MyGrammar;

options
{
    language=CSharp;
}

@parser::namespace { 	My.Custom.NameSpace.For.Lexers.Parser.In.Combined.Grammar } // Or just @namespace { ... }

@parser@lexer::namespace { My.Custom.NameSpace.For.Lexer.In.Combined.Grammar }

// rest of grammar follows
....
Code Block

lexer grammar MyGrammar;

options
{
    language=CSharp;
}

@namespace { My.Custom.NameSpace.For.Lexer }

// rest of grammar follows
....
Code Block

parser grammar MyGrammar;

options
{
	
    language=CSharp;
}

@namespace { My.Custom.NameSpace.For.ParsersExclTreeParsers.Parser }

// rest of grammar follows
....
Code Block

tree grammar MyGrammar;

options
{
    language=CSharp;
}
 
@namespace { 	My.Custom.NameSpace.For.ParsersInclTreeParsersTreeParser }

// rest of grammar follows
....

Syntactic differences from the Java target

...