Git Product home page Git Product logo

Comments (5)

ericvergnaud avatar ericvergnaud commented on June 7, 2024

Mmm... the target template should be generating them, see TypeScript.stg, line 875:
public static readonly channelNames: string[] = [ "DEFAULT_TOKEN_CHANNEL", "HIDDEN"<if (lexer.channelNames)>, <lexer.channelNames:{c| "<c>"}; separator=", ", wrap, anchor><endif> ];

from antlr4.

kaby76 avatar kaby76 commented on June 7, 2024

Sure, those are the names of the channels declared as an array of strings. But, if you look at the generated lexer for CSharp or probably Java, you also get constant declarations. So, when I want to reference the channel in base class code, like this in CSharp (https://github.com/antlr/grammars-v4/blob/c7883a594bf622200c561db181848d277fcd49a7/php/CSharp/PhpLexerBase.cs#L79), I can't in TypeScript (https://github.com/kaby76/grammars-v4/blob/865ccef278193e46e6cb285ea4df2a22480b7268/php/Antlr4ng/PhpLexerBase.ts#L48)--I have to hardwire the number. This is brittle code, and unnecessary.

from antlr4.

ericvergnaud avatar ericvergnaud commented on June 7, 2024

Can you provide an example of the generated code ?

from antlr4.

kaby76 avatar kaby76 commented on June 7, 2024

php_lexer.go.txt
PhpLexer.cs.txt
PhpLexer.dart.txt
PhpLexer.g4.txt
PhpLexer.h.txt
PhpLexer.java.txt
PhpLexer.js.txt
PhpLexer.py.txt
PhpLexer.ts.txt
PhpLexer.php.txt
PhpLexer.swift.txt

(Files generated via antlr4 -Dlanguage=whatever PhpLexer.g4.)

The targets that have a constant defined for SkipChannel: Cpp, CSharp, Dart, Go, Java, JavaScript, PHP, Python3, Swift.

The targets missing a constant definition for SkipChannel: TypeScript.

$ grep SkipChannel *.txt | grep 4
php_lexer.go.txt:       PhpLexerSkipChannel = 4
PhpLexer.cs.txt:                PhpComments=2, ErrorLexem=3, SkipChannel=4;
PhpLexer.dart.txt:    PhpComments = 2, ErrorLexem = 3, SkipChannel = 4;
PhpLexer.g4.txt:    SkipChannel
PhpLexer.g4.txt:PHPStart       : PhpStartFragment     -> channel(SkipChannel), pushMode(PHP);
PhpLexer.g4.txt:PHPStartInside     : PhpStartFragment     -> channel(SkipChannel), pushMode(PHP);
PhpLexer.g4.txt:PHPStartInsideQuoteString     : PhpStartFragment     -> channel(SkipChannel), pushMode(PHP);
PhpLexer.g4.txt:PHPStartDoubleQuoteString     : PhpStartFragment     -> channel(SkipChannel), pushMode(PHP);
PhpLexer.g4.txt:PHPStartInsideScript     : PhpStartFragment     -> channel(SkipChannel), pushMode(PHP);
PhpLexer.g4.txt:Whitespace        : [ \t\r\n]+    -> channel(SkipChannel);
PhpLexer.g4.txt:SingleLineComment : '//'          -> channel(SkipChannel), pushMode(SingleLineCommentMode);
PhpLexer.g4.txt:ShellStyleComment : '#'           -> channel(SkipChannel), pushMode(SingleLineCommentMode);
PhpLexer.g4.txt:    '{' { this.IsCurlyDollar(1) }? { this.SetInsideString(); } -> channel(SkipChannel), pushMode(PHP)
PhpLexer.g4.txt:CommentEnd              : [\r\n] -> channel(SkipChannel), popMode; // exit from comment.
PhpLexer.h.txt:    PhpComments = 2, ErrorLexem = 3, SkipChannel = 4
PhpLexer.java.txt:              PhpComments=2, ErrorLexem=3, SkipChannel=4;
PhpLexer.js.txt:PhpLexer.SkipChannel = 4;
PhpLexer.php.txt:               public const PhpComments = 2, ErrorLexem = 3, SkipChannel = 4;
PhpLexer.py.txt:    SkipChannel = 4
PhpLexer.swift.txt:     static let PhpComments=2, ErrorLexem=3, SkipChannel=4

from antlr4.

ericvergnaud avatar ericvergnaud commented on June 7, 2024

from antlr4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.