Package ortus.boxlang.compiler.parser
Class AbstractParser
java.lang.Object
ortus.boxlang.compiler.parser.AbstractParser
- Direct Known Subclasses:
BoxScriptParser,BoxTemplateParser,CFScriptParser,CFTemplateParser,DocParser
Parser abstract class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<BoxComment> protected final org.antlr.v4.runtime.BaseErrorListenerOverrides the ANTL4 default error listener collecting the errorsprotected Fileprotected Stringprotected Sourceprotected intprotected intprotected booleanFlag to indicate if the parser is parsing the outermost source or just being used to parse a portion of the code. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor, initialize the error listAbstractParser(int startLine, int startColumn) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddErrorListeners(org.antlr.v4.runtime.Lexer lexer, org.antlr.v4.runtime.Parser parser) Add the parser error listener to the ANTLR parserprotected PositioncreateOffsetPosition(int startLine, int startColumn, int stopLine, int stopColumn) protected PositioncreatePosition(int startLine, int startColumn, int stopLine, int stopColumn) extractMultiLineCommentText(String rawText, Boolean doc) protected org.apache.commons.io.input.BOMInputStreamgetInputStream(File file) Convert the input file in a UTF-8 Input stream with BOMprotected PositiongetPosition(org.antlr.v4.runtime.ParserRuleContext node) Extracts the position from the ANTLR nodeprotected PositiongetPosition(org.antlr.v4.runtime.ParserRuleContext startNode, org.antlr.v4.runtime.ParserRuleContext endNode) Extracts the position from the ANTLR node, using a custom starting point.protected PositiongetPosition(org.antlr.v4.runtime.Token token) Extracts the position from the ANTLR tokenprotected PositiongetPosition(org.antlr.v4.runtime.Token startToken, org.antlr.v4.runtime.Token endToken) Extracts the position from the ANTLR tokenprotected PositiongetPosition(org.antlr.v4.runtime.tree.ParseTree parseTree) Extracts the position from the ANTLR parse tree.protected PositiongetPositionStartingAt(org.antlr.v4.runtime.ParserRuleContext node, org.antlr.v4.runtime.ParserRuleContext startNode) Extracts the position from the ANTLR node, using a custom starting point.protected PositiongetPositionStartingAt(org.antlr.v4.runtime.ParserRuleContext node, org.antlr.v4.runtime.Token startToken) Extracts the position from the ANTLR node, using a custom starting point.protected StringgetSourceText(int startIndex, org.antlr.v4.runtime.ParserRuleContext nodeStop) Extracts from the ANTLR node where one node is the start, and another node is the endprotected StringgetSourceText(org.antlr.v4.runtime.ParserRuleContext node) Extracts from the ANTLR nodeprotected StringgetSourceText(org.antlr.v4.runtime.ParserRuleContext node, int startIndex, int stopIndex) Extracts from the ANTLR nodeprotected StringgetSourceText(org.antlr.v4.runtime.ParserRuleContext startNode, org.antlr.v4.runtime.ParserRuleContext stopNode) Extracts text from a range of nodesprotected StringgetSourceText(org.antlr.v4.runtime.Token startToken, org.antlr.v4.runtime.Token endToken) Extracts from the ANTLR nodebooleanabstract ParsingResultParse a fileabstract ParsingResultParse a cf script string expressionprotected abstract BoxNodeparserFirstStage(InputStream stream, Boolean classOrInterface) Fist stage parsersetSubParser(boolean subParser)
-
Field Details
-
startLine
protected int startLine -
startColumn
protected int startColumn -
file
-
sourceCode
-
sourceToParse
-
issues
-
comments
-
subParser
protected boolean subParserFlag to indicate if the parser is parsing the outermost source or just being used to parse a portion of the code. When true, this skips comment assocation and final AST visitors, waiting for the entire AST to be assembled first. -
errorListener
protected final org.antlr.v4.runtime.BaseErrorListener errorListenerOverrides the ANTL4 default error listener collecting the errors
-
-
Constructor Details
-
AbstractParser
public AbstractParser()Constructor, initialize the error list -
AbstractParser
public AbstractParser(int startLine, int startColumn)
-
-
Method Details
-
getInputStream
Convert the input file in a UTF-8 Input stream with BOM- Parameters:
file- input file- Returns:
- a BOMInputStream
- Throws:
IOException
-
parse
Parse a file- 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- See Also:
-
parse
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- See Also:
-
addErrorListeners
protected void addErrorListeners(org.antlr.v4.runtime.Lexer lexer, org.antlr.v4.runtime.Parser parser) Add the parser error listener to the ANTLR parser- Parameters:
lexer- ANTLR lexer instanceparser- ANTLR parser instance
-
parserFirstStage
protected abstract BoxNode parserFirstStage(InputStream stream, Boolean classOrInterface) throws IOException Fist stage parser- 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
-
getPosition
Extracts the position from the ANTLR node- Parameters:
node- any ANTLR role- Returns:
- a Position representing the region on the source code
- See Also:
-
getPositionStartingAt
protected Position getPositionStartingAt(org.antlr.v4.runtime.ParserRuleContext node, org.antlr.v4.runtime.ParserRuleContext startNode) Extracts the position from the ANTLR node, using a custom starting point.- Parameters:
node- any ANTLR role- Returns:
- a Position representing the region on the source code
- See Also:
-
getPosition
protected Position getPosition(org.antlr.v4.runtime.ParserRuleContext startNode, org.antlr.v4.runtime.ParserRuleContext endNode) Extracts the position from the ANTLR node, using a custom starting point.- Parameters:
node- any ANTLR role- Returns:
- a Position representing the region on the source code
- See Also:
-
getPositionStartingAt
protected Position getPositionStartingAt(org.antlr.v4.runtime.ParserRuleContext node, org.antlr.v4.runtime.Token startToken) Extracts the position from the ANTLR node, using a custom starting point.- Parameters:
node- any ANTLR role- Returns:
- a Position representing the region on the source code
- See Also:
-
getPosition
Extracts the position from the ANTLR token- Parameters:
token- any ANTLR token- Returns:
- a Position representing the region on the source code
- See Also:
-
getPosition
Extracts the position from the ANTLR parse tree. ParseTree is a super interface, which can either be a TerminalNode or a ParserRuleContext- Parameters:
parseTree- any ANTLR parse tree- Returns:
- a Position representing the region on the source code
- See Also:
-
getPosition
protected Position getPosition(org.antlr.v4.runtime.Token startToken, org.antlr.v4.runtime.Token endToken) Extracts the position from the ANTLR token- Parameters:
token- any ANTLR token- Returns:
- a Position representing the region on the source code
- See Also:
-
createPosition
-
createOffsetPosition
protected Position createOffsetPosition(int startLine, int startColumn, int stopLine, int stopColumn) -
getSourceText
protected String getSourceText(org.antlr.v4.runtime.ParserRuleContext node, int startIndex, int stopIndex) Extracts from the ANTLR node- Parameters:
node- any ANTLR role- Returns:
- a string containing the source code
-
getSourceText
Extracts from the ANTLR node- Parameters:
node- any ANTLR role- Returns:
- a string containing the source code
-
getSourceText
protected String getSourceText(org.antlr.v4.runtime.ParserRuleContext startNode, org.antlr.v4.runtime.ParserRuleContext stopNode) Extracts text from a range of nodes- Parameters:
startNode- The start nodestopNode- The stop node- Returns:
- a string containing the source code
-
getSourceText
protected String getSourceText(org.antlr.v4.runtime.Token startToken, org.antlr.v4.runtime.Token endToken) Extracts from the ANTLR node- Parameters:
startToken- The start tokenendToken- The end token- Returns:
- a string containing the source code
-
getSourceText
Extracts from the ANTLR node where one node is the start, and another node is the end- Parameters:
startIndex- The start indexnodeStop- The stop node- Returns:
- a string containing the source code
-
extractMultiLineCommentText
-
setSubParser
-
isSubParser
public boolean isSubParser() -
getComments
-