问题描述
任何人都可以推荐适合Java的Javascript解析器吗?我相信Rhino可以使用,但是对于解析来说它似乎有些过分,或者它是唯一合适的解决方案?任何建议将不胜感激。谢谢。
Anyone can recommend a decent Javascript parser for Java? I believe Rhino can be used, however it seems an overkill for just doing parsing, or is it the only decent solution? Any suggestion would be greatly appreciated. Thanks.
推荐答案
来自
值得注意的功能
- 报告队列上的警告,其中错误不会阻止任何进一步的错误,这样我们就可以在单个编译过程中报告多个错误,而不是强迫开发人员玩whack-a-mole。
- 不解析Firefox样式
catch(< Identifier> if< Expression>)
,因为那些不适用于IE和许多其他解释器。 - 识别
const
,因为许多口译员都做(不是IE)但警告。 - 允许,但警告,在
数组
和对象
构造函数中的尾随逗号。 - 允许将关键字作为标识符由于不同的解释器具有不同的关键字集,因此可以发出警告。这允许我们使用扩展的关键字集。
- 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.
- Does not parse Firefox style
catch (<Identifier> if <Expression>)
since those don't work on IE and many other interpreters. - Recognizes
const
since many interpreters do (not IE) but warns. - Allows, but warns, on trailing commas in
Array
andObject
constructors. - Allows keywords as identifier names but warns since different interpreters have different keyword sets. This allows us to use an expansive keyword set.
要解析严格的代码,请传入 PedanticWarningMessageQueue
将 MessageLevel#WARNING
及以上转换为 MessageLevel#FATAL_ERROR
。
To parse strict code, pass in a PedanticWarningMessageQueue
that converts MessageLevel#WARNING
and above to MessageLevel#FATAL_ERROR
.
显示如何设置一个解析器,同一个类中的[ fromResource
]和[ fromString
]显示了如何获得正确的输入好的。
CajaTestCase.js
shows how to set up a parser, and [fromResource
] and [fromString
] in the same class show how to get an input of the right kind.
这篇关于Java的Javascript解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!