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.BaseErrorListener
Overrides the ANTL4 default error listener collecting the errorsprotected File
protected String
protected Source
protected int
protected int
protected boolean
Flag 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 void
addErrorListeners
(org.antlr.v4.runtime.Lexer lexer, org.antlr.v4.runtime.Parser parser) Add the parser error listener to the ANTLR parserprotected Position
createOffsetPosition
(int startLine, int startColumn, int stopLine, int stopColumn) protected Position
createPosition
(int startLine, int startColumn, int stopLine, int stopColumn) extractMultiLineCommentText
(String rawText, Boolean doc) protected org.apache.commons.io.input.BOMInputStream
getInputStream
(File file) Convert the input file in a UTF-8 Input stream with BOMprotected Position
getPosition
(org.antlr.v4.runtime.ParserRuleContext node) Extracts the position from the ANTLR nodeprotected 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.protected Position
getPosition
(org.antlr.v4.runtime.Token token) Extracts the position from the ANTLR tokenprotected Position
getPosition
(org.antlr.v4.runtime.Token startToken, org.antlr.v4.runtime.Token endToken) Extracts the position from the ANTLR tokenprotected Position
getPosition
(org.antlr.v4.runtime.tree.ParseTree parseTree) Extracts the position from the ANTLR parse tree.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.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.protected String
getSourceText
(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 String
getSourceText
(org.antlr.v4.runtime.ParserRuleContext node) Extracts from the ANTLR nodeprotected String
getSourceText
(org.antlr.v4.runtime.ParserRuleContext node, int startIndex, int stopIndex) Extracts from the ANTLR nodeprotected String
getSourceText
(org.antlr.v4.runtime.ParserRuleContext startNode, org.antlr.v4.runtime.ParserRuleContext stopNode) Extracts text from a range of nodesprotected String
getSourceText
(org.antlr.v4.runtime.Token startToken, org.antlr.v4.runtime.Token endToken) Extracts from the ANTLR nodeboolean
abstract ParsingResult
Parse a fileabstract ParsingResult
Parse a cf script string expressionprotected abstract BoxNode
parserFirstStage
(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
-