gpt4 book ai didi

用于 Java 的 Javascript 解析器

转载 作者:IT老高 更新时间:2023-10-28 21:03:48 26 4
gpt4 key购买 nike

谁能推荐一个不错的 Java Javascript 解析器?我相信可以使用 Rhino,但是仅仅进行解析似乎有点过头了,或者它是唯一合适的解决方案吗?任何建议将不胜感激。谢谢。

最佳答案

来自 https://github.com/google/caja/blob/master/src/com/google/caja/parser/js/Parser.java

The grammar below is a context-free representation of the grammar this parser parses. It disagrees with EcmaScript 262 Edition 3 (ES3) where implementations disagree with ES3. The rules for semicolon insertion and the possible backtracking in expressions needed to properly handle backtracking are commented thoroughly in code, since semicolon insertion requires information from both the lexer and parser and is not determinable with finite lookahead.

Noteworthy features

  1. Reports warnings on a queue where an error doesn't prevent any further errors, so that we can report multiple errors in a single compile pass instead of forcing developers to play whack-a-mole.
  2. Does not parse Firefox style catch (<Identifier> if <Expression>) since those don't work on IE and many other interpreters.
  3. Recognizes const since many interpreters do (not IE) but warns.
  4. Allows, but warns, on trailing commas in Array and Object constructors.
  5. Allows keywords as identifier names but warns since different interpreters have different keyword sets. This allows us to use an expansive keyword set.

To parse strict code, pass in a PedanticWarningMessageQueue that converts MessageLevel#WARNING and above to MessageLevel#FATAL_ERROR.


CajaTestCase.js 展示了如何设置解析器,以及 [ fromResource ] 和 [ fromString ] 在同一类中展示如何获得正确类型的输入。

关于用于 Java 的 Javascript 解析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6511556/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com