0

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..

3
  • Sounds like you want to implement the Alien Autopsy antipattern: forums.sun.com/thread.jspa?messageID=10337966#10337966 Commented Apr 12, 2010 at 16:09
  • Why do you think that regex is the only solution? Are other solutions allowed? Commented Apr 12, 2010 at 16:14
  • ofcourse..all solutions are accepted Commented Apr 12, 2010 at 16:36

3 Answers 3

0

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.