Class IXMLAnalyzer

java.lang.Object
org.libxmq.imp.ixml.IXMLAnalyzer

public final class IXMLAnalyzer extends Object
Character-level LL(*) analysis and parser-description DOM. Every decision gets a lookahead DFA, see IXMLLookahead.
  • Field Details

  • Method Details

    • analyze

      public static XmlDocument analyze(String source, String input)
      Analyze a grammar and test its predictive parser against the whole input.
      Parameters:
      source - iXML grammar
      input - sample input (not used to infer grammar properties), or null for no test
      Returns:
      an analysis DOM containing diagnostics or a parser and test result
    • compileParser

      public static IXMLAnalyzer compileParser(String source)
      Compile a grammar for parsing many inputs with the LL(*) parser, see parseInput.
      Parameters:
      source - iXML grammar
      Returns:
      the compiled parser
      Throws:
      IllegalArgumentException - if the grammar is not LL(*)
    • parseInput

      public XmlDocument parseInput(String input)
      Parse an input with a parser from compileParser.
      Parameters:
      input - the input to parse
      Returns:
      the parse tree
      Throws:
      IllegalArgumentException - if the input is rejected
    • parseInputOrFailure

      public XmlDocument parseInputOrFailure(String input, boolean silent)
      Parse an input with a parser from compileParser. When the input is rejected, the result is a failure document, like in the C version: ixml(ixml:state=failed){info=... line=... column=... pos=...} A dynamic error, eg D02, has only the info.
      Parameters:
      input - the input to parse
      silent - if true a rejected input gives an empty document
      Returns:
      the parse tree or the failure document
    • failureDocument

      public static XmlDocument failureDocument(String input, int failed_at, String error, List<EarleyParser.Expected> expected)
      The failure document of a rejected input, like in the C version: ixml(ixml:state=failed){info=... line=... column=... pos=...} A dynamic error, eg D02, has only the info.
      Parameters:
      input - the input
      failed_at - the code point position of the failure
      error - the error message
      expected - what the parser could read at the position, see EarleyParser.expected
      Returns:
      the failure document
    • failureDocument

      public static XmlDocument failureDocument(byte[] buf, int begin, int stop, int failed_at, String error, List<EarleyParser.Expected> expected)
      The failure document of a rejected input, like failureDocument for a String, but the input is UTF-8 bytes, only the code points up to the failure and around it are decoded. An error starting with Earley.INVALID_UTF8 gives the failure document of the C version for an input that is not valid UTF-8, the error is then at the invalid bytes.
      Parameters:
      buf - the input as UTF-8
      begin - the first byte of the input
      stop - the end of the input, exclusive
      failed_at - the code point position of the failure
      error - the error message
      expected - what the parser could read at the position, see EarleyParser.expected
      Returns:
      the failure document
    • isFailure

      public static boolean isFailure(XmlDocument d)
      Returns true if the document is a failure document from parseInputOrFailure.
      Parameters:
      d - the document
      Returns:
      true if the root has ixml:state=failed
    • parse

      public static XmlDocument parse(String source, String input)
      Parse the input with the LL(*) parser of the grammar and return the ixml parse tree.
      Parameters:
      source - iXML grammar
      input - the input to parse
      Returns:
      the parse tree
      Throws:
      IllegalArgumentException - if the grammar is not LL(*) or the input is rejected