grammars-v4 icon indicating copy to clipboard operation
grammars-v4 copied to clipboard

Can't use StringTemplate grammar with CSharp Target

Open DerIltis opened this issue 3 years ago • 1 comments

Dear all,

I am currently using ANTLRs C# StringTemplate library to generate some R and Python code.

Now I want to create a developer manual of this creation process and the string templates, and I thought it would be a natural idea to use the ANTLR grammar for StringTemplates (STParser and STLexer under https://github.com/antlr/grammars-v4/tree/master/stringtemplate) to generate a C# parser that will in turn allow me to translate the relations between my string template definitions into a graphviz dot file.

However, I observed that although the grammar for the StringTemplates can be used to generate a C# parser, this C# parser does not compile. I think my problem is related to this open issue reported on Github https://github.com/antlr/grammars-v4/issues/2167, it seems as if this grammar was specifically designed for JAVA.

  • STLexer.g4 uses superClass=LexerAdaptor, which is only available in Java.
  • STLexer.g4 uses Inline Java calls that refer to this superclass as well.
  • STLexer.g4 refers to LexBasic.g4, which uses Inline Java calls to the Java Character Class, namely the toCodePoint Methods.

Points 1 & 2 could easily be fixed by translating the supplemental Java class "LexerAdaptor" to C#, this is more or less straightforward. However, I cannot fix Point 3, because I don't understand the toCodePoint Methods.

Can anyone help me out here?

DerIltis avatar Aug 29 '22 15:08 DerIltis

Check out java/java9. There's a method in the lexer base class that is a replacement for the toCodePoint() method. Make sure to use Antl4.Runtime.Standard 4.10.1 as opposed to Antlr4.Runtime v4.6.6, which is the now unsupported fork antlr4cs. We don't support that anymore.

kaby76 avatar Aug 29 '22 16:08 kaby76