Class RNCParser
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 Summary
Modifier and TypeMethodDescriptionstatic RNCParserReturns the singleton parser instance.parse(CharSequence text, String uri) Parses RNC source text into anRNCDocumentAST.
-
Method Details
-
getInstance
Returns the singleton parser instance.- Returns:
- the parser instance.
-
parse
Parses RNC source text into anRNCDocumentAST.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),currdescends into the new node. When the matching closing brace is found,currascends 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
RNCDocumentwith all AST nodes and errors.
-