java.lang.Object
org.eclipse.lemminx.extensions.relaxng.grammar.rnc.parser.RNCParser

public class RNCParser extends Object
Parser for RNC (RELAX NG Compact Syntax) files that produces an RNCDocument AST.

The parser uses the RNCScanner to tokenize the input and builds a tree of RNCNode subclasses representing the document structure: namespace declarations, datatypes declarations, start patterns, defines, elements, attributes, includes, and divs.

Use case: called by RNCTextDocumentService on every document open/change to produce the parsed model that all language features operate on.

Example: parsing the text start = element root { text } produces:

 RNCDocument
   ├─ RNCStart (assignType=ASSIGN)
   └─ RNCElement (name="root")
 

This parser also detects structural errors (unclosed blocks, missing names, missing braces, missing assign operators, missing URIs) and records them as RNCDocument.RNCError entries for diagnostics.

  • Method Details

    • getInstance

      public static RNCParser getInstance()
      Returns the singleton parser instance.
      Returns:
      the parser instance.
    • parse

      public RNCDocument parse(CharSequence text, String uri)
      Parses RNC source text into an RNCDocument AST.

      The parser scans tokens and builds a tree by tracking the current parent node (curr). When a block-opening construct is encountered (element, attribute, include, div with an opening brace), curr descends into the new node. When the matching closing brace is found, curr ascends back to the parent.

      Braces that do not belong to a node (mixed { }, list { }, grammar { }, datatype parameters, malformed names) are tracked on a stack of anonymous blocks, so that each closing brace is matched with its own opening brace.

      Example usage:

       RNCDocument doc = RNCParser.getInstance().parse("start = element root { text }", "test.rnc");
       List<RNCDefine> defines = doc.getDefines(); // empty - no defines, just inline
       RNCStart start = doc.getStartDecl(); // RNCStart node
       
      Parameters:
      text - the RNC source text to parse.
      uri - the document URI (stored in the resulting document).
      Returns:
      the parsed RNCDocument with all AST nodes and errors.