Package ortus.boxlang.compiler.parser
Class CFParser
java.lang.Object
ortus.boxlang.compiler.parser.AbstractParser
ortus.boxlang.compiler.parser.CFParser
Parser for CF scripts
-
Field Summary
FieldsFields inherited from class ortus.boxlang.compiler.parser.AbstractParser
comments, file, issues, sourceCode, sourceToParse, startColumn, startLine, subParser -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckArrayAccess(ortus.boxlang.parser.antlr.CFGrammar.ExprArrayAccessContext ctx, BoxExpression object, BoxExpression access) Check array access to ensure that nonsensical access methods are rejected at AST build timevoidcheckDotAccess(BoxExpression left, BoxExpression right, boolean isStatic) Checks DOT access methods to ensure that nonsensical access methods are rejected at AST build time and not left to the runtime, when it is not so useful!static voidClear the DFA cache.escapeStringLiteral(String quoteChar, String string) Escape double up quotes and pounds in a string literalstatic intGet the number of states stored in all the DFA cache.org.antlr.v4.runtime.TokenbooleanParse a cf script fileParse a cf script stringParse a cf script stringparseCFExpression(String code, Position position) This is only in use now for loop and while, which allow conditions to be specified as a string.parseExpression(String code) Parse a cf script string expressionprotected BoxNodeparserFirstStage(InputStream stream, boolean classOrInterface, boolean isScript) Fist stage parserparseStatement(String code) Parse a cf script string statementvoidreportError(String message, Position position) voidreportExpressionError(BoxExpression expression) voidreportStatementError(BoxStatement statement) voidsetInOutputBlock(boolean inOutputBlock) setSubParser(boolean subParser) toStatementOrError(Supplier<BoxStatement> statementGenerator, org.antlr.v4.runtime.ParserRuleContext node) Methods inherited from class ortus.boxlang.compiler.parser.AbstractParser
addErrorListeners, createOffsetPosition, createPosition, extractMultiLineCommentText, getComments, getInputStream, getPosition, getPosition, getPosition, getPosition, getPosition, getPositionStartingAt, getPositionStartingAt, getSourceText, getSourceText, getSourceText, getSourceText, getSourceText, isScope, isSubParser, profileParser
-
Field Details
-
componentService
-
-
Constructor Details
-
CFParser
public CFParser()Constructor -
CFParser
public CFParser(int startLine, int startColumn) -
CFParser
public CFParser(int startLine, int startColumn, boolean inOutputBlock)
-
-
Method Details
-
getInOutputBlock
public boolean getInOutputBlock() -
setInOutputBlock
public void setInOutputBlock(boolean inOutputBlock) -
parse
Parse a cf script file- Specified by:
parsein classAbstractParser- Parameters:
file- source file to parse- Returns:
- a ParsingResult containing the AST with a BoxScript as root and the list of errors (if any)
- Throws:
IOException- if the input stream is in error- See Also:
-
parse
Parse a cf script string- Parameters:
code- source code to parse- Returns:
- a ParsingResult containing the AST with a BoxScript as root and the list of errors (if any)
- Throws:
IOException- if the input stream is in error- See Also:
-
parse
- Throws:
IOException
-
parse
public ParsingResult parse(String code, boolean classOrInterface, boolean isScript) throws IOException Parse a cf script string- Specified by:
parsein classAbstractParser- Parameters:
code- source code to parse- Returns:
- a ParsingResult containing the AST with a BoxScript as root and the list of errors (if any)
- Throws:
IOException- if the input stream is in error- See Also:
-
parseExpression
Parse a cf script string expression- Parameters:
code- source of the expression to parse- Returns:
- a ParsingResult containing the AST with a BoxExpr as root and the list of errors (if any)
- Throws:
IOException- if the input stream is in error- See Also:
-
parseStatement
Parse a cf script string statement- Parameters:
code- source of the expression to parse- Returns:
- a ParsingResult containing the AST with a BoxStatement as root and the list of errors (if any)
- Throws:
IOException- if the input stream is in error- See Also:
-
parserFirstStage
protected BoxNode parserFirstStage(InputStream stream, boolean classOrInterface, boolean isScript) throws IOException Fist stage parser- Specified by:
parserFirstStagein classAbstractParser- Parameters:
stream- input stream (file or string) of the source codeclassOrInterface- true if the code is a class or interface as opposed to just a list of statements- Returns:
- the ANTLR ParserRule representing the parse tree of the code
- Throws:
IOException- io error
-
toAst
public List<BoxStatement> toAst(File file, ortus.boxlang.parser.antlr.CFGrammar.Template_statementsContext node) -
toStatementOrError
public BoxStatement toStatementOrError(Supplier<BoxStatement> statementGenerator, org.antlr.v4.runtime.ParserRuleContext node) -
escapeStringLiteral
Escape double up quotes and pounds in a string literal- Overrides:
escapeStringLiteralin classAbstractParser- Parameters:
quoteChar- the quote character used to surround the stringstring- the string to escape- Returns:
- the escaped string
-
parseCFExpression
This is only in use now for loop and while, which allow conditions to be specified as a string. I could parse them as expressions, but that would be a lot more annoying work in the Lexer to detect that exact scenario and I don't think it's worth it.- Parameters:
code- the code to parseposition- the position of the code- Returns:
- the parsed expression
-
getFirstToken
public org.antlr.v4.runtime.Token getFirstToken() -
setSubParser
- Overrides:
setSubParserin classAbstractParser
-
checkDotAccess
Checks DOT access methods to ensure that nonsensical access methods are rejected at AST build time and not left to the runtime, when it is not so useful!This is necessarily quite an involved check as there are many combinations of left and right
- Parameters:
left- the left side of the dot access left.rightright- the right side of the dot access left.right
-
checkArrayAccess
public void checkArrayAccess(ortus.boxlang.parser.antlr.CFGrammar.ExprArrayAccessContext ctx, BoxExpression object, BoxExpression access) Check array access to ensure that nonsensical access methods are rejected at AST build time- Parameters:
ctx- the Parsers ExprArrayAccessContext for source reference etcobject- the object node that is being accessed as if it were an arrayaccess- the access node that is being used to access the object
-
reportExpressionError
-
reportStatementError
-
reportError
-
getCacheSize
public static int getCacheSize()Get the number of states stored in all the DFA cache.- Returns:
- the number of states stored in all the DFA cache
-
clearParseCache
public static void clearParseCache()Clear the DFA cache.
-