org.autoplot.jythonsupport.SimplifyScriptSupport
AST support for Jython completions. This is not meant to be thorough, but instead should be helpful when working with scripts.
SimplifyScriptSupport( )
alligatorParse
alligatorParse( String script ) → String
eat away at the end of the script until it can be parsed
Parameters
script - a Jython script.
Returns:
the script with lines at the end removed such that the script can compile.
See Also:
JythonCompletionTask#trimLinesToMakeValid(java.lang.String)
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
getIndent
getIndent( String line ) → String
return the indent for a line, for example the " " in " continue "
Parameters
line - a String
Returns:
the indent
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
getSourceForStatement
getSourceForStatement( String[] ss, stmtType o ) → String
Using the stmtType get the line, or lines. If the last line contains a single triple-quote, we need to kludge a little and
look for the preceding triple-quote in previous lines.
Parameters
ss - a java.lang.String[]
o - a stmtType
Returns:
a String
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
removeSideEffects
removeSideEffects( String script ) → String
Remove parts of the script which are expensive so that the script can be run and completions offered. TODO: What is the
difference between this and simplifyScriptToCompletions?
Parameters
script - Jython script
Returns:
simplified version of the script.
See Also:
simplifyScriptToCompletions(java.lang.String)
https://github.com/autoplot/dev/tree/master/bugs/sf/1687
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
simplifyScriptToCompletions
simplifyScriptToCompletions( String script ) → String
extracts the parts of the program that are quickly executed, generating a code which can be run and then queried for
completions. This uses a Jython syntax tree (AST), so the code must be free of syntax errors. This will remove lines from the
end of the code until the code compiles, in case the script has a partially defined def or class.
Parameters
script - the entire python program
Returns:
the python program with lengthy calls removed.
See Also:
removeSideEffects(java.lang.String)
JythonUtil#simplifyScriptToGetParams(java.lang.String, boolean)
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
simplifyScriptToGetCompletions
simplifyScriptToGetCompletions( String[] ss, stmtType[] stmts, java.util.HashSet variableNames, int beginLine, int lastLine, int depth ) → String
Extracts the parts of the program that get parameters or take a trivial amount of time to execute. This may call itself
recursively when if blocks are encountered. See test038.
Parameters
ss - the entire script, with a null at index 0.
stmts - statements being processed.
variableNames - variable names that have been resolved.
beginLine - first line of the script being processed, or -1 to use stmts[0].beginLine
lastLine - INCLUSIVE last line of the script being processed.
depth - recursion depth, for debugging.
Returns:
the simplified script
See Also:
JythonUtil#simplifyScriptToGetParams(java.lang.String[], org.python.parser.ast.stmtType[], java.util.HashSet, int, int,
int)
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
tryResolveStringNode
tryResolveStringNode( SimpleNode n, int row, int column, java.util.Map env ) → String
given the node n, try to resolve its string value, maybe by implementing some of the addition (concatenation).
This was introduced to support URI completions within Jython codes, allowing the filename to be a variable and
thus shortening lines.
Parameters
n - node within an AST.
row - the row of the caret
column - the column of the caret
env - any variables which have been identified as string values.
Returns:
the string or null.
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
tryResolveStringNode( Module n, int row, int column, java.util.Map env ) → String
tryResolveTupleNode
tryResolveTupleNode( SimpleNode n, int row, int column, java.util.Map env ) → Object[]
quick and dirty attempt to resolve tuple for format statement.
Parameters
n - a SimpleNode
row - an int
column - an int
env - a java.util.Map
Returns:
an Object[]
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]