Package org.snakeyaml.engine.v2.parser
Class ParserImpl
- java.lang.Object
-
- org.snakeyaml.engine.v2.parser.ParserImpl
-
public class ParserImpl extends java.lang.Object implements 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 Classes Modifier and Type Class Description private classParserImpl.ParseBlockMappingFirstKeyprivate classParserImpl.ParseBlockMappingKeyprivate classParserImpl.ParseBlockMappingValueprivate classParserImpl.ParseBlockMappingValueCommentprivate classParserImpl.ParseBlockMappingValueCommentListprivate classParserImpl.ParseBlockNodeblock_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 classParserImpl.ParseBlockSequenceEntryKeyprivate classParserImpl.ParseBlockSequenceEntryValueprivate classParserImpl.ParseBlockSequenceFirstEntryprivate classParserImpl.ParseDocumentContentprivate classParserImpl.ParseDocumentEndprivate classParserImpl.ParseDocumentStartprivate classParserImpl.ParseFlowEndCommentprivate classParserImpl.ParseFlowMappingEmptyValueprivate classParserImpl.ParseFlowMappingFirstKeyflow_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 classParserImpl.ParseFlowMappingKeyprivate classParserImpl.ParseFlowMappingValueprivate classParserImpl.ParseFlowSequenceEntryprivate classParserImpl.ParseFlowSequenceEntryMappingEndprivate classParserImpl.ParseFlowSequenceEntryMappingKeyprivate classParserImpl.ParseFlowSequenceEntryMappingValueprivate classParserImpl.ParseFlowSequenceFirstEntryflow_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 classParserImpl.ParseImplicitDocumentStartprivate classParserImpl.ParseIndentlessSequenceEntryKeyprivate classParserImpl.ParseIndentlessSequenceEntryValueprivate classParserImpl.ParseStreamStart
-
Field Summary
Fields Modifier and Type Field Description private java.util.Optional<Event>currentEventprivate static java.util.Map<java.lang.String,java.lang.String>DEFAULT_TAGSprivate java.util.Map<java.lang.String,java.lang.String>directiveTagsprivate ArrayStack<java.util.Optional<Mark>>marksStackprotected Scannerscannertokeniserprivate LoadSettingssettingsprivate java.util.Optional<Production>stateprivate ArrayStack<Production>states
-
Constructor Summary
Constructors Constructor Description ParserImpl(LoadSettings settings, Scanner scanner)CreateParserImpl(LoadSettings settings, StreamReader reader)CreateParserImpl(Scanner scanner, LoadSettings settings)Deprecated.use the other constructor with LoadSettings firstParserImpl(StreamReader reader, LoadSettings settings)Deprecated.use the other constructor with LoadSettings first
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckEvent(Event.ID id)Check the ID of the next event.booleanhasNext()Produce the event if not yet present.private java.util.Optional<Mark>markPop()private voidmarkPush(java.util.Optional<Mark> mark)Eventnext()Consume the event (get the next event and removed it).private EventparseBlockNodeOrIndentlessSequence()private EventparseFlowNode()private EventparseNode(boolean block, boolean indentlessSequence)EventpeekEvent()Get the next event (and keep it).private VersionTagsTupleprocessDirectives()private EventprocessEmptyScalar(java.util.Optional<Mark> mark)block_mapping ::= BLOCK-MAPPING_START ((KEY block_node_or_indentless_sequence?)? (VALUE block_node_or_indentless_sequence?)?)* BLOCK-ENDprivate voidproduce()private CommentEventproduceCommentEvent(CommentToken token)
-
-
-
Field Detail
-
DEFAULT_TAGS
private static final java.util.Map<java.lang.String,java.lang.String> DEFAULT_TAGS
-
scanner
protected final Scanner scanner
tokeniser
-
settings
private final LoadSettings settings
-
states
private final ArrayStack<Production> states
-
marksStack
private final ArrayStack<java.util.Optional<Mark>> marksStack
-
currentEvent
private java.util.Optional<Event> currentEvent
-
state
private java.util.Optional<Production> state
-
directiveTags
private java.util.Map<java.lang.String,java.lang.String> directiveTags
-
-
Constructor Detail
-
ParserImpl
@Deprecated public ParserImpl(StreamReader reader, LoadSettings settings)
Deprecated.use the other constructor with LoadSettings first- Parameters:
reader- - the inputsettings- - the configuration options
-
ParserImpl
public ParserImpl(LoadSettings settings, StreamReader reader)
Create- Parameters:
settings- - configuration optionsreader- - the input
-
ParserImpl
@Deprecated public ParserImpl(Scanner scanner, LoadSettings settings)
Deprecated.use the other constructor with LoadSettings first- Parameters:
scanner- - inputsettings- - configuration options
-
ParserImpl
public ParserImpl(LoadSettings settings, Scanner scanner)
Create- Parameters:
settings- - configuration optionsscanner- - input
-
-
Method Detail
-
checkEvent
public boolean checkEvent(Event.ID id)
Check the ID of the next event.- Specified by:
checkEventin interfaceParser- Parameters:
id- Event ID to match- Returns:
trueif the next event has the given ID. Returnsfalseif no more events are available.
-
peekEvent
public Event peekEvent()
Get the next event (and keep it). Produce the event if not yet present.- Specified by:
peekEventin interfaceParser- Returns:
- The event that will be returned on the next call to
Parser.next()
-
next
public Event next()
Consume the event (get the next event and removed it).
-
hasNext
public boolean hasNext()
Produce the event if not yet present.- Specified by:
hasNextin interfacejava.util.Iterator<Event>- Returns:
- true if there is another event
-
produce
private void produce()
-
produceCommentEvent
private CommentEvent produceCommentEvent(CommentToken token)
-
processDirectives
private VersionTagsTuple processDirectives()
-
parseFlowNode
private Event parseFlowNode()
-
parseBlockNodeOrIndentlessSequence
private Event parseBlockNodeOrIndentlessSequence()
-
parseNode
private Event parseNode(boolean block, boolean indentlessSequence)
-
processEmptyScalar
private Event processEmptyScalar(java.util.Optional<Mark> mark)
block_mapping ::= BLOCK-MAPPING_START ((KEY block_node_or_indentless_sequence?)? (VALUE block_node_or_indentless_sequence?)?)* BLOCK-END
-
markPop
private java.util.Optional<Mark> markPop()
-
markPush
private void markPush(java.util.Optional<Mark> mark)
-
-