Class CFParser

java.lang.Object
ortus.boxlang.compiler.parser.AbstractParser
ortus.boxlang.compiler.parser.CFParser

public class CFParser extends AbstractParser
Parser for CF scripts
  • Field Details

  • 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

      public ParsingResult parse(File file, boolean isScript) throws IOException
      Parse a cf script file
      Specified by:
      parse in class AbstractParser
      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

      public ParsingResult parse(String code, boolean isScript) throws IOException
      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

      public ParsingResult parse(String code) throws IOException
      Throws:
      IOException
    • parse

      public ParsingResult parse(String code, boolean classOrInterface, boolean isScript) throws IOException
      Parse a cf script string
      Specified by:
      parse in class AbstractParser
      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

      public ParsingResult parseExpression(String code) 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 - if the input stream is in error
      See Also:
    • parseStatement

      public ParsingResult parseStatement(String code) throws IOException
      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:
      parserFirstStage in class AbstractParser
      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
    • 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

      public String escapeStringLiteral(String quoteChar, String string)
      Escape double up quotes and pounds in a string literal
      Overrides:
      escapeStringLiteral in class AbstractParser
      Parameters:
      quoteChar - the quote character used to surround the string
      string - the string to escape
      Returns:
      the escaped string
    • parseCFExpression

      public BoxExpression parseCFExpression(String code, Position position)
      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 parse
      position - the position of the code
      Returns:
      the parsed expression
    • getFirstToken

      public org.antlr.v4.runtime.Token getFirstToken()
    • setSubParser

      public CFParser setSubParser(boolean subParser)
      Overrides:
      setSubParser in class AbstractParser
    • checkDotAccess

      public void checkDotAccess(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!

      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.right
      right - 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 etc
      object - the object node that is being accessed as if it were an array
      access - the access node that is being used to access the object
    • reportExpressionError

      public void reportExpressionError(BoxExpression expression)
    • reportStatementError

      public void reportStatementError(BoxStatement statement)
    • reportError

      public void reportError(String message, Position position)
    • 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.