/** * We always add STREAM-START as the first token and STREAM-END as the last * token. */ private void fetchStreamStart() { // Read the token. Mark mark = reader.getMark(); // Add STREAM-START. Token token = new StreamStartToken(mark, mark); this.tokens.add(token); }
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; } }
public Event produce() { state = new ParseFlowSequenceEntry(false); Token token = scanner.peekToken(); return new MappingEndEvent(token.getStartMark(), token.getEndMark()); } }
public Event produce() { state = new ParseFlowMappingKey(false); return processEmptyScalar(scanner.peekToken().getStartMark()); } }
/** * Fetch a flow-style collection end, which is either a sequence or a * mapping. The type is determined by the given boolean. * * A flow-style collection is in a format similar to JSON. Sequences are * started by '[' and ended by ']'; mappings are started by '{' and ended by * '}'. * * @see <a href="http://www.yaml.org/spec/1.1/#id863975"></a> */ private void fetchFlowCollectionEnd(boolean isMappingEnd) { // Reset possible simple key on the current level. removePossibleSimpleKey(); // Decrease the flow level. this.flowLevel--; // No simple keys after ']' or '}'. this.allowSimpleKey = false; // Add FLOW-SEQUENCE-END or FLOW-MAPPING-END. Mark startMark = reader.getMark(); reader.forward(); Mark endMark = reader.getMark(); Token token; if (isMappingEnd) { token = new FlowMappingEndToken(startMark, endMark); } else { token = new FlowSequenceEndToken(startMark, endMark); } this.tokens.add(token); }
/** * Fetch a document indicator, either "---" for "document-start", or else * "..." for "document-end. The type is chosen by the given boolean. */ private void fetchDocumentIndicator(boolean isDocumentStart) { // Set the current intendation to -1. unwindIndent(-1); // Reset simple keys. Note that there could not be a block collection // after '---'. removePossibleSimpleKey(); this.allowSimpleKey = false; // Add DOCUMENT-START or DOCUMENT-END. Mark startMark = reader.getMark(); reader.forward(3); Mark endMark = reader.getMark(); Token token; if (isDocumentStart) { token = new DocumentStartToken(startMark, endMark); } else { token = new DocumentEndToken(startMark, endMark); } this.tokens.add(token); }
Token token; if (isMappingStart) { token = new FlowMappingStartToken(startMark, endMark); } else { token = new FlowSequenceStartToken(startMark, endMark);
/** * Fetch a key in a block-style mapping. * * @see <a href="http://www.yaml.org/spec/1.1/#id863975"></a> */ private void fetchKey() { // Block context needs additional checks. if (this.flowLevel == 0) { // Are we allowed to start a key (not necessary a simple)? if (!this.allowSimpleKey) { throw new ScannerException(null, null, "mapping keys are not allowed here", reader.getMark()); } // We may need to add BLOCK-MAPPING-START. if (addIndent(this.reader.getColumn())) { Mark mark = reader.getMark(); this.tokens.add(new BlockMappingStartToken(mark, mark)); } } // Simple keys are allowed after '?' in the block context. this.allowSimpleKey = this.flowLevel == 0; // Reset possible simple key on the current level. removePossibleSimpleKey(); // Add KEY. Mark startMark = reader.getMark(); reader.forward(); Mark endMark = reader.getMark(); Token token = new KeyToken(startMark, endMark); this.tokens.add(token); }
/** * Check whether the next token is one of the given types. */ public boolean checkToken(Token.ID... choices) { while (needMoreTokens()) { fetchMoreTokens(); } if (!this.tokens.isEmpty()) { if (choices.length == 0) { return true; } // since profiler puts this method on top (it is used a lot), we // should not use 'foreach' here because of the performance reasons Token.ID first = this.tokens.get(0).getTokenId(); for (int i = 0; i < choices.length; i++) { if (first == choices[i]) { return true; } } } return false; }
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()); } } }
/** * Fetch an entry in the flow style. Flow-style entries occur either * immediately after the start of a collection, or else after a comma. * * @see <a href="http://www.yaml.org/spec/1.1/#id863975"></a> */ private void fetchFlowEntry() { // Simple keys are allowed after ','. this.allowSimpleKey = true; // Reset possible simple key on the current level. removePossibleSimpleKey(); // Add FLOW-ENTRY. Mark startMark = reader.getMark(); reader.forward(); Mark endMark = reader.getMark(); Token token = new FlowEntryToken(startMark, endMark); this.tokens.add(token); }
public Event produce() { // Parse the document end. Token token = scanner.peekToken(); Mark startMark = token.getStartMark(); Mark endMark = startMark; boolean explicit = false; if (scanner.checkToken(Token.ID.DocumentEnd)) { token = scanner.getToken(); endMark = token.getEndMark(); explicit = true; } Event event = new DocumentEndEvent(startMark, endMark, explicit); // Prepare the next state. state = new ParseDocumentStart(); return event; } }
public Event produce() { Token token = scanner.getToken(); marks.push(token.getStartMark()); return new ParseBlockSequenceEntry().produce(); } }
public Event produce() { if (scanner.checkToken(Token.ID.Value)) { Token token = scanner.getToken(); if (!scanner.checkToken(Token.ID.FlowEntry, Token.ID.FlowSequenceEnd)) { states.push(new ParseFlowSequenceEntryMappingEnd()); return parseFlowNode(); } else { state = new ParseFlowSequenceEntryMappingEnd(); return processEmptyScalar(token.getEndMark()); } } else { state = new ParseFlowSequenceEntryMappingEnd(); Token token = scanner.peekToken(); return processEmptyScalar(token.getStartMark()); } } }
public Event produce() { Token token = scanner.getToken(); marks.push(token.getStartMark()); return new ParseBlockMappingKey().produce(); } }
public Event produce() { if (scanner.checkToken(Token.ID.Value)) { Token token = scanner.getToken(); if (!scanner.checkToken(Token.ID.Key, Token.ID.Value, Token.ID.BlockEnd)) { states.push(new ParseBlockMappingKey()); return parseBlockNodeOrIndentlessSequence(); } else { state = new ParseBlockMappingKey(); return processEmptyScalar(token.getEndMark()); } } state = new ParseBlockMappingKey(); Token token = scanner.peekToken(); return processEmptyScalar(token.getStartMark()); } }
public Event produce() { Token token = scanner.getToken(); marks.push(token.getStartMark()); return new ParseFlowSequenceEntry(true).produce(); } }
public Event produce() { if (scanner.checkToken(Token.ID.Value)) { Token token = scanner.getToken(); if (!scanner.checkToken(Token.ID.FlowEntry, Token.ID.FlowMappingEnd)) { states.push(new ParseFlowMappingKey(false)); return parseFlowNode(); } else { state = new ParseFlowMappingKey(false); return processEmptyScalar(token.getEndMark()); } } else { state = new ParseFlowMappingKey(false); Token token = scanner.peekToken(); return processEmptyScalar(token.getStartMark()); } } }
public Event produce() { Token token = scanner.getToken(); marks.push(token.getStartMark()); return new ParseFlowMappingKey(true).produce(); } }
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(); } } }