Class AbstractParser

java.lang.Object
ortus.boxlang.compiler.parser.AbstractParser
Direct Known Subclasses:
BoxScriptParser, BoxTemplateParser, CFScriptParser, CFTemplateParser, DocParser

public abstract class AbstractParser extends Object
Parser abstract class
  • Field Details

    • startLine

      protected int startLine
    • startColumn

      protected int startColumn
    • file

      protected File file
    • sourceCode

      protected String sourceCode
    • sourceToParse

      protected Source sourceToParse
    • issues

      protected final List<Issue> issues
    • comments

      protected final List<BoxComment> comments
    • subParser

      protected boolean subParser
      Flag 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 errorListener
      Overrides 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

      protected org.apache.commons.io.input.BOMInputStream getInputStream(File file) throws IOException
      Convert the input file in a UTF-8 Input stream with BOM
      Parameters:
      file - input file
      Returns:
      a BOMInputStream
      Throws:
      IOException
    • parse

      public abstract ParsingResult parse(File file) throws IOException
      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

      public abstract ParsingResult parse(String code, Boolean classOrInterface) throws IOException
      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 instance
      parser - 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 code
      classOrInterface - 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

      protected Position getPosition(org.antlr.v4.runtime.ParserRuleContext node)
      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

      protected Position getPosition(org.antlr.v4.runtime.Token token)
      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

      protected Position getPosition(org.antlr.v4.runtime.tree.ParseTree parseTree)
      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

      protected Position createPosition(int startLine, int startColumn, int stopLine, int stopColumn)
    • 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

      protected String getSourceText(org.antlr.v4.runtime.ParserRuleContext node)
      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 node
      stopNode - 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 token
      endToken - The end token
      Returns:
      a string containing the source code
    • getSourceText

      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 end
      Parameters:
      startIndex - The start index
      nodeStop - The stop node
      Returns:
      a string containing the source code
    • extractMultiLineCommentText

      public String extractMultiLineCommentText(String rawText, Boolean doc)
    • setSubParser

      public AbstractParser setSubParser(boolean subParser)
    • isSubParser

      public boolean isSubParser()
    • getComments

      public List<BoxComment> getComments()