Code Monkey home page Code Monkey logo

antlr4-runtime-benchmarks's Issues

> StringTemplate for target actions in grammars

I don't use the @members

Sorry, you are right. I just noticed that you already have the code in base classes.

but still, you have to import these classes and the calls to methods are different (depending on the target)

Yes, that is true, but that's exactly what "transformGrammar is all about. Yes, it is a totally disgusting hack, but it allows for the grammar to be shared for all targets.

Rather than have all these different syntax, the grammar always uses "this." in all actions, and transformGrammmar.py replaces the pattern with the appropriate syntax. To be really "target agnostic", you shouldn't even use operators like <, %, etc. I forgot, but there is one target for one grammar in grammars-v4 that had this issue.

For Cpp, the semantic action https://github.com/mike-lischke/antlr4-runtime-benchmarks/blob/a971852628d9ecca0ce79c7972e3c026017bdadc/src/mysql/targets/antlr4-cpp/MySQLLexer.g4#L474C90-L474C111 does not have a "this->", but is it required because the field is already declared in the base class. In most grammars, the "transformGrammar.py" hack is required to mutate "this." to "this->".

For JavaScript and TypeScript, "this." must be used https://github.com/mike-lischke/antlr4-runtime-benchmarks/blob/a971852628d9ecca0ce79c7972e3c026017bdadc/src/mysql/targets/antlr4/MySQLLexer.g4#L486C90-L486C116 . But, since we already require "this." for all field and method references for "target agnostic format", it's fine as is.

For Go, lexer predicates must be reference with "l." which parser predicates are "p.".

Etc., etc., etc.

A much better solution would be to provide a StringTemplate expansion for the target. A PR was added for this here: antlr/antlr4#4345 , but personally, I'd make the entire file a string template, and prefix or suffix the file with .st, and just apply ST through the whole file. Trash already does this. (You have to have a tool like trgen because Java requires base class code to be in a specific directory structure if you use a -package option for the Antlr tool.

Originally posted by @kaby76 in #1 (comment)

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.