ANTLR JavaScript 目标

发布于 2024-08-26 20:19:58 字数 597 浏览 5 评论 0原文

我一直在使用 ANTLR 为带有 Java 目标的标记语言生成解析器 + 树语法,效果很好。现在我正在尝试获取 JavaScript 中的目标以在我的网络浏览器中使用它。

但是,我无法找到任何关于如何执行此操作的良好文档。我将 Eclipse 与 ANTLR IDE 一起使用,当我将语言指定为 JavaScript 时,出现以下错误。

此行有多个标记

  • (10):内部错误:组 JavaScript 不满足接口 ANTLRCore:这些模板上的参数不匹配 [treeParser(grammar、name、scopes、tokens、tokenNames、globalAction、rules、numRules、bitsets、labelType) ,ASTLabelType,superClass,成员,filterMode)]

  • (10):内部错误:java.util.NoSuchElementException:没有这样的属性:模板上下文中的filterMode [treeParser]

如果有人可以帮助我解决这个问题或向我指出一些我可以使用 ANTLR 阅读有关 JavaScript 目标的材料,那就太好了。

谢谢

I have been using ANTLR to generate a parser + tree grammar for a mark up language with Java target which works fine. Now I am trying to get the target in JavaScript to use it in my web browser.

However, I have not been able to locate any good documentation on how to go about doing this. I am using eclipse with ANTLR IDE, and when i specify the language as JavaScript, I get the following errors.

Multiple markers at this line

  • (10): internal error: group JavaScript does not satisfy interface ANTLRCore: mismatched arguments on these templates [treeParser(grammar, name, scopes, tokens, tokenNames, globalAction, rules, numRules, bitsets, labelType, ASTLabelType, superClass, members, filterMode)]

  • (10): internal error: java.util.NoSuchElementException: no such attribute: filterMode in template context [treeParser]

If anyone could help me out with this or point me to some material which I could read about the JavaScript target with ANTLR, it would be great.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

绝情姑娘 2024-09-02 20:19:58

ANTLR4 有一个新的 JS Lang 目标,大约 3 个月前发布到 GitHub:

antlr/antlr4-javascript

它尚未集成到正式版本中,但您可以将其放入最新的 ANTLR4 代码库中并自行重新编译 ANTLR。

There is a new JS Lang target for ANTLR4 that was posted to GitHub almost 3 months ago:

antlr/antlr4-javascript

It's not integrated into an official release yet, but you can probably just throw it into the latest ANTLR4 codebase and recompile ANTLR yourself.

晨与橙与城 2024-09-02 20:19:58

您应该使用最新版本 (3.3),在以前的版本中,javascript 目标未正确集成。仍然存在一些错误,但您可以看到一个工作示例,其中包含一些指导和链接
http://blog.barvinograd.com/ 2011/03/online-function-grapher-formula-parser-part-2/

You should use the latest version (3.3), in previous versions the javascript target was not properly integrated. There still some bugs, but you can see a working example with some guidance and links on
http://blog.barvinograd.com/2011/03/online-function-grapher-formula-parser-part-2/

哽咽笑 2024-09-02 20:19:58

看来 JavaScript 目标在 3.4 发行版中再次被破坏。 3.3 对我来说工作得很好。

It appears as though the JavaScript target is broken again in the 3.4 distribution. 3.3 is working fine for me though.

风蛊 2024-09-02 20:19:58

我一直在努力让它工作,并且在阅读完本文后才成功生成 .js 文件:

http://www.antlr3.org/pipermail/antlr-interest/2011-August/042417.html

来自帖子:

以下是如何开始使用 ANTLR 和 JavaScript后端:

  1. 下载 ANTLRWorks 1.2.2:<
    http://antlr.org/download/antlrworks-1.2.2.jar >。 JavaScript 目标
    仅当 IDE 生成词法分析器和解析器代码时才起作用(请参阅<
    http://antlr.1301665.n2.nabble .com/maven-plugin-and-javascript-target-td3647109.html>)。
    如果您尝试从命令行运行 ANTLR v3.1,您将看到错误
    消息“错误(10):内部错误:组 JavaScript 不满足
    接口 ANTLRCore”。
  2. 下载 JS 运行时发行版:
    http://antlr.org/download/antlr-javascript-runtime-3.1.zip

从此您可以使用 ANTLRWorks 1.2.2 生成词法分析器和解析器
通过从“生成”菜单中选择“生成代码”来生成代码。 ANTLRWorks 将
将生成的文件放入所在文件夹的 output 目录中
语法文件驻留。

注意,如果生成过程中出现错误,那么由于某种原因
“生成代码”操作不再有效。只需关闭语法并
从“打开最近的”菜单重新打开它。

I have been trying to get this working, and have only just managed to generate .js files succesfully after reading this:

http://www.antlr3.org/pipermail/antlr-interest/2011-August/042417.html

From the post:

Here's how to get started with ANTLR and the JavaScript back-end:

  1. Download ANTLRWorks 1.2.2: <
    http://antlr.org/download/antlrworks-1.2.2.jar>. The JavaScript target
    only works when the IDE generates the lexer and parser code (see <
    http://antlr.1301665.n2.nabble.com/maven-plugin-and-javascript-target-td3647109.html>).
    If you try to run ANTLR v3.1 from the command line, you will see the error
    message "error(10): internal error: group JavaScript does not satisfy
    interface ANTLRCore".
  2. Download the JS runtime distribution:
    http://antlr.org/download/antlr-javascript-runtime-3.1.zip

From then on you can use ANTLRWorks 1.2.2 to generate the lexer and parser
code by selecting "Generate Code" from the "Generate" menu. ANTLRWorks will
place the generated files into an output directory in the folder in which
the grammar file resides.

Note that if an error occurs in the generation process, then for some reason
the "Generate Code" action no longer works. Simply close the grammar and
re-open it from the "Open Recent" menu.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文