Class ScriptParser

java.lang.Object
com.darkcollective.relix.lang.ScriptParser

public final class ScriptParser extends Object
Recursive-descent parser for .relix scripting language source files.

Usage

   Script script = ScriptParser.parse(sourceText);
   Script script = ScriptParser.parse(sourceText, "path/to/file.relix");
 

Script structure

   [namespace IDENTIFIER ;]
   [env [from STRING] [using STRING] ;]
   (import | source | connection | relate | IDENTIFIER := ... | def | query) *
 

Embedded sub-languages

Relational-algebra expression blocks (\{ … \}) in assignment and query statements are extracted as raw text and delegated eagerly to RelAlgebraParser.parse(String, String, int, int). Function-body expressions in def statements are similarly delegated to RelAlgebraParser.parseOperand(String, String, int, int).

Raw block extraction invariant

When a delimiter token (LangTokenType.LBRACE or LangTokenType.LBRACKET) is the current lookahead, the lexer's character position is already past that delimiter character. Raw block extraction must therefore be performed without calling advance() first — doing so would skip the first content character. The LangLexer.consumeRawBraceBlock() and LangLexer.consumeRawBracketBlock() helpers enforce this contract.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Script
    Parses a relix scripting language source from the given input stream (UTF-8 encoded).
    static Script
    parse(InputStream input, String filePath)
    Parses a relix scripting language source from the given input stream (UTF-8 encoded), embedding filePath in every statement's source location.
    static Script
    parse(String source)
    Parses a relix scripting language source from the given string.
    static Script
    parse(String source, String filePath)
    Parses a relix scripting language source from the given string, embedding filePath in every statement's source location.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • parse

      public static Script parse(String source)
      Parses a relix scripting language source from the given string.
      Parameters:
      source - the full script source text
      Returns:
      the parsed Script AST
      Throws:
      LangParseException - if the source contains syntax errors
      NullPointerException - if source is null
    • parse

      public static Script parse(String source, String filePath)
      Parses a relix scripting language source from the given string, embedding filePath in every statement's source location.
      Parameters:
      source - the full script source text
      filePath - the file path to embed in source locations
      Returns:
      the parsed Script AST
      Throws:
      LangParseException - if the source contains syntax errors
      NullPointerException - if source or filePath is null
    • parse

      public static Script parse(InputStream input) throws IOException
      Parses a relix scripting language source from the given input stream (UTF-8 encoded).
      Parameters:
      input - the source stream
      Returns:
      the parsed Script AST
      Throws:
      IOException - if reading from the stream fails
      LangParseException - if the source contains syntax errors
      NullPointerException - if input is null
    • parse

      public static Script parse(InputStream input, String filePath) throws IOException
      Parses a relix scripting language source from the given input stream (UTF-8 encoded), embedding filePath in every statement's source location.
      Parameters:
      input - the source stream
      filePath - the file path to embed in source locations
      Returns:
      the parsed Script AST
      Throws:
      IOException - if reading from the stream fails
      LangParseException - if the source contains syntax errors
      NullPointerException - if input or filePath is null