开发者

Get all variables of javascript in JAVA

开发者 https://www.devze.com 2022-12-26 07:05 出处:网络
I am using rhino and Scripting for the Java Platform in order to allow the user extend my application.

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 jo开发者_Go百科b but i amnt sure... Please i somebody could help me figure out the java regexp to get the variables i would really appriciate it..


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


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.


a little late but you might be interested in this: http://ramkulkarni.com/blog/understanding-ast-created-by-mozilla-rhino-parser/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号