获取JAVA中javascript的所有变量

发布于 2024-08-28 05:05:50 字数 268 浏览 11 评论 0原文

我使用 rhino 和 Java 平台脚本来允许用户扩展我的应用程序。

然而,用户可以编写一些情况,例如 (ASTO.value>440) || (ASTO.bellowNormal) 等等... 问题是在使用 ScriptEngine 从我的 JAVA 应用程序运行脚本之前 我想获取所有变量的名称!因为我应该知道脚本运行需要哪些变量...... 我知道正则表达式可以完成这项工作,但我不确定...... 请有人能帮我找出 java 正则表达式来获取变量,我真的很感激它。

I am using rhino and Scripting for the Java Platform in order to allow the user extend my application.

However the user can write some cases eg (ASTO.value>440) || (ASTO.bellowNormal) etc...
The problem is that before running the script from my JAVA application using ScriptEngine
i want to get the names of all the variables! Because i should know which variables are required for the script to run...
I know that a regular expression would do the job but i amnt sure...
Please i somebody could help me figure out the java regexp to get the variables i would really appriciate it..

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

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

发布评论

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

评论(3

开始看清了 2024-09-04 05:05:50

我找到了解决方案
cx.getDebuggableView(结果).getParamAndVarCount()
但它不会返回未声明的变量:(

I found a solution
cx.getDebuggableView(result).getParamAndVarCount()
But it doesnt return undeclared variables:(

雨轻弹 2024-09-04 05:05:50

我们正在做一些非常相似的事情,尽管它是用 Scala 编写的,我只能给你一些提示...

  1. 测试非常重要
  2. 这是我们更复杂的测试之一: listArg[Math.floor(4 / listArg[ ZeroArg]['f3'])]
  3. 描述设计的变量...

    // 后面可能使用了环境变量的字符
    private val NewScopeChars = List('[', '(', '/', '*', '+', '-', ',')
    // 表示变量名结束的字符
    私有 val SepChars = '.' :: ' ' :: ';' :: ']' :: ')' :: NewScopeChars
    private val ExcludeStrings = List("new", "Math")
    private val LiteralPrefixes = "'" :: "\"" :: (0 到 9).map(_.toString).toList
    

我有

We're doing something very similar although it is written in Scala and I can only give you some hints...

  1. Tests are really important
  2. This is one of our more complex tests: listArg[Math.floor(4 / listArg[zeroArg]['f3'])]
  3. Variables that describe the design...

    // chars after which there may be an environment variable used
    private val NewScopeChars = List('[', '(', '/', '*', '+', '-', ',')
    // chars that signal the end of a variable name
    private val SepChars = '.' :: ' ' :: ';' :: ']' :: ')' :: NewScopeChars
    private val ExcludeStrings = List("new", "Math")
    private val LiteralPrefixes = "'" :: "\"" :: (0 to 9).map(_.toString).toList
    

I'm having a problem with performance so any help would be appreciated.

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