Package org.yaml.snakeyaml.parser
Class ParserImpl
java.lang.Object
org.yaml.snakeyaml.parser.ParserImpl
- All Implemented Interfaces:
Parser
# The following YAML grammar is LL(1) and is parsed by a recursive descent
parser.
stream ::= STREAM-START implicit_document? explicit_document* STREAM-END
implicit_document ::= block_node DOCUMENT-END*
explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
block_node_or_indentless_sequence ::=
ALIAS
| properties (block_content | indentless_block_sequence)?
| block_content
| indentless_block_sequence
block_node ::= ALIAS
| properties block_content?
| block_content
flow_node ::= ALIAS
| properties flow_content?
| flow_content
properties ::= TAG ANCHOR? | ANCHOR TAG?
block_content ::= block_collection | flow_collection | SCALAR
flow_content ::= flow_collection | SCALAR
block_collection ::= block_sequence | block_mapping
flow_collection ::= flow_sequence | flow_mapping
block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END
indentless_sequence ::= (BLOCK-ENTRY block_node?)+
block_mapping ::= BLOCK-MAPPING_START
((KEY block_node_or_indentless_sequence?)?
(VALUE block_node_or_indentless_sequence?)?)*
BLOCK-END
flow_sequence ::= FLOW-SEQUENCE-START
(flow_sequence_entry FLOW-ENTRY)*
flow_sequence_entry?
FLOW-SEQUENCE-END
flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
flow_mapping ::= FLOW-MAPPING-START
(flow_mapping_entry FLOW-ENTRY)*
flow_mapping_entry?
FLOW-MAPPING-END
flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
FIRST sets:
stream: { STREAM-START }
explicit_document: { DIRECTIVE DOCUMENT-START }
implicit_document: FIRST(block_node)
block_node: { ALIAS TAG ANCHOR SCALAR BLOCK-SEQUENCE-START BLOCK-MAPPING-START FLOW-SEQUENCE-START FLOW-MAPPING-START }
flow_node: { ALIAS ANCHOR TAG SCALAR FLOW-SEQUENCE-START FLOW-MAPPING-START }
block_content: { BLOCK-SEQUENCE-START BLOCK-MAPPING-START FLOW-SEQUENCE-START FLOW-MAPPING-START SCALAR }
flow_content: { FLOW-SEQUENCE-START FLOW-MAPPING-START SCALAR }
block_collection: { BLOCK-SEQUENCE-START BLOCK-MAPPING-START }
flow_collection: { FLOW-SEQUENCE-START FLOW-MAPPING-START }
block_sequence: { BLOCK-SEQUENCE-START }
block_mapping: { BLOCK-MAPPING-START }
block_node_or_indentless_sequence: { ALIAS ANCHOR TAG SCALAR BLOCK-SEQUENCE-START BLOCK-MAPPING-START FLOW-SEQUENCE-START FLOW-MAPPING-START BLOCK-ENTRY }
indentless_sequence: { ENTRY }
flow_collection: { FLOW-SEQUENCE-START FLOW-MAPPING-START }
flow_sequence: { FLOW-SEQUENCE-START }
flow_mapping: { FLOW-MAPPING-START }
flow_sequence_entry: { ALIAS ANCHOR TAG SCALAR FLOW-SEQUENCE-START FLOW-MAPPING-START KEY }
flow_mapping_entry: { ALIAS ANCHOR TAG SCALAR FLOW-SEQUENCE-START FLOW-MAPPING-START KEY }
Since writing a recursive-descendant parser is a straightforward task, we do not give many
comments here.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classprivate classprivate classprivate classprivate classprivate classblock_node_or_indentless_sequence ::= ALIAS | properties (block_content | indentless_block_sequence)? | block_content | indentless_block_sequence block_node ::= ALIAS | properties block_content? | block_content flow_node ::= ALIAS | properties flow_content? | flow_content properties ::= TAG ANCHOR? | ANCHOR TAG? block_content ::= block_collection | flow_collection | SCALAR flow_content ::= flow_collection | SCALAR block_collection ::= block_sequence | block_mapping flow_collection ::= flow_sequence | flow_mappingprivate classprivate classprivate classprivate classprivate classprivate classprivate classprivate classprivate classflow_mapping ::= FLOW-MAPPING-START (flow_mapping_entry FLOW-ENTRY)* flow_mapping_entry? FLOW-MAPPING-END flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?private classprivate classprivate classprivate classprivate classprivate classprivate classflow_sequence ::= FLOW-SEQUENCE-START (flow_sequence_entry FLOW-ENTRY)* flow_sequence_entry? FLOW-SEQUENCE-END flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? Note that while production rules for both flow_sequence_entry and flow_mapping_entry are equal, their interpretations are different.private classprivate classprivate classprivate classstream ::= STREAM-START implicit_document? explicit_document* STREAM-END implicit_document ::= block_node DOCUMENT-END* explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Eventprivate VersionTagsTupleprivate final ArrayStack<Mark> protected final Scannerprivate Productionprivate final ArrayStack<Production> -
Constructor Summary
ConstructorsConstructorDescriptionParserImpl(StreamReader reader) Deprecated.use optionsParserImpl(StreamReader reader, boolean parseComments) Deprecated.use options insteadParserImpl(StreamReader reader, LoaderOptions options) ParserImpl(Scanner scanner) -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckEvent(Event.ID choice) Check the type of the next event.getEvent()Get the next event and proceed further.private Eventprivate Eventprivate EventparseNode(boolean block, boolean indentlessSequence) Get the next event.private VersionTagsTuplehttps://yaml.org/spec/1.1/#id898785 says "If the document specifies no directives, it is parsed using the same settings as the previous document.private EventprocessEmptyScalar(Mark mark) block_mapping ::= BLOCK-MAPPING_START ((KEY block_node_or_indentless_sequence?)? (VALUE block_node_or_indentless_sequence?)?)* BLOCK-ENDprivate CommentEventproduceCommentEvent(CommentToken token)
-
Field Details
-
DEFAULT_TAGS
-
scanner
-
currentEvent
-
states
-
marks
-
state
-
directives
-
-
Constructor Details
-
ParserImpl
Deprecated.use optionsCreate- Parameters:
reader- - input
-
ParserImpl
Deprecated.use options insteadCreate- Parameters:
reader- - inputparseComments- - true to keep the comments
-
ParserImpl
-
ParserImpl
-
-
Method Details
-
checkEvent
Check the type of the next event.- Specified by:
checkEventin interfaceParser- Parameters:
choice- Event ID.- Returns:
trueif the next event can be assigned to a variable of the given type. Returnsfalseif no more events are available.
-
peekEvent
Get the next event.- Specified by:
peekEventin interfaceParser- Returns:
- The event that will be returned on the next call to
Parser.getEvent()
-
getEvent
Get the next event and proceed further. -
produceCommentEvent
-
processDirectives
https://yaml.org/spec/1.1/#id898785 says "If the document specifies no directives, it is parsed using the same settings as the previous document. If the document does specify any directives, all directives of previous documents, if any, are ignored." TODO the last statement is not respected (as in PyYAML, to work the same)- Returns:
- directives to be applied for the current document
-
parseFlowNode
-
parseBlockNodeOrIndentlessSequence
-
parseNode
-
processEmptyScalar
block_mapping ::= BLOCK-MAPPING_START ((KEY block_node_or_indentless_sequence?)? (VALUE block_node_or_indentless_sequence?)?)* BLOCK-END
-