/** * Get the next event and proceed further. */ public Event getEvent() { peekEvent(); Event value = currentEvent; currentEvent = null; return value; }
/** * Get the next event. */ public Event peekEvent() { if (currentEvent == null) { if (state != null) { currentEvent = state.produce(); } } return currentEvent; }
@Override public boolean hasNext() { return parser.peekEvent() != null; }
public Event produce() { // Parse an implicit document. if (!scanner.checkToken(Token.ID.Directive, Token.ID.DocumentStart, Token.ID.StreamEnd)) { directives = new VersionTagsTuple(null, DEFAULT_TAGS); Token token = scanner.peekToken(); Mark startMark = token.getStartMark(); Mark endMark = startMark; Event event = new DocumentStartEvent(startMark, endMark, false, null, null); // Prepare the next state. states.push(new ParseDocumentEnd()); state = new ParseBlockNode(); return event; } else { Production p = new ParseDocumentStart(); return p.produce(); } } }
public class Consumer { public static void main(String[] args) { Parser p = new ParserImpl(); // just like a Java class! ... } }
/** * Checks if further documents are available. * * @return <code>true</code> if there is at least one more document. */ public boolean checkNode() { // Drop the STREAM-START event. if (parser.checkEvent(Event.ID.StreamStart)) { parser.getEvent(); } // If there are more documents available? return !parser.checkEvent(Event.ID.StreamEnd); }
public Event produce() { if (scanner.checkToken(Token.ID.BlockEntry)) { Token token = scanner.getToken(); if (!scanner.checkToken(Token.ID.BlockEntry, Token.ID.Key, Token.ID.Value, Token.ID.BlockEnd)) { states.push(new ParseIndentlessSequenceEntry()); return new ParseBlockNode().produce(); } else { state = new ParseIndentlessSequenceEntry(); return processEmptyScalar(token.getEndMark()); } } Token token = scanner.peekToken(); Event event = new SequenceEndEvent(token.getStartMark(), token.getEndMark()); state = states.pop(); return event; } }
@Override public Event next() { return parser.getEvent(); }
public ParserImpl(Scanner scanner) { this.scanner = scanner; currentEvent = null; directives = new VersionTagsTuple(null, new HashMap<String, String>(DEFAULT_TAGS)); states = new ArrayStack<Production>(100); marks = new ArrayStack<Mark>(10); state = new ParseStreamStart(); }
public Event produce() { Event event; if (scanner.checkToken(Token.ID.Directive, Token.ID.DocumentStart, Token.ID.DocumentEnd, Token.ID.StreamEnd)) { event = processEmptyScalar(scanner.peekToken().getStartMark()); state = states.pop(); return event; } else { Production p = new ParseBlockNode(); return p.produce(); } } }
public Event produce() { Token token = scanner.getToken(); marks.push(token.getStartMark()); return new ParseBlockSequenceEntry().produce(); } }
private Event parseBlockNodeOrIndentlessSequence() { return parseNode(true, true); }
public Event produce() { state = new ParseFlowMappingKey(false); return processEmptyScalar(scanner.peekToken().getStartMark()); } }
public Event produce() { Token token = scanner.getToken(); if (!scanner.checkToken(Token.ID.Value, Token.ID.FlowEntry, Token.ID.FlowSequenceEnd)) { states.push(new ParseFlowSequenceEntryMappingValue()); return parseFlowNode(); } else { state = new ParseFlowSequenceEntryMappingValue(); return processEmptyScalar(token.getEndMark()); } } }
public Event produce() { // Parse the stream start. StreamStartToken token = (StreamStartToken) scanner.getToken(); Event event = new StreamStartEvent(token.getStartMark(), token.getEndMark()); // Prepare the next state. state = new ParseImplicitDocumentStart(); return event; } }
private Object loadFromReader(StreamReader sreader, Class<?> type) { Composer composer = new Composer(new ParserImpl(sreader), resolver); constructor.setComposer(composer); return constructor.getSingleData(type); }
/** * Check the type of the next event. */ public boolean checkEvent(Event.ID choice) { peekEvent(); return currentEvent != null && currentEvent.is(choice); }
private Event parseFlowNode() { return parseNode(false, false); }
public YAMLParser(IOContext ctxt, BufferRecycler br, int parserFeatures, int formatFeatures, ObjectCodec codec, Reader reader) { super(ctxt, parserFeatures); _objectCodec = codec; _formatFeatures = formatFeatures; _reader = reader; _yamlParser = new ParserImpl(new StreamReader(reader)); }
/** * Parse the first YAML document in a stream and produce the corresponding * representation tree. (This is the opposite of the represent() method) * * @see <a href="http://yaml.org/spec/1.1/#id859333">Figure 3.1. Processing * Overview</a> * @param yaml * YAML document * @return parsed root Node for the specified YAML document */ public Node compose(Reader yaml) { Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver); return composer.getSingleNode(); }