1 /** 2 * Copyright (c) 2008, SnakeYAML 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 package org.yaml.snakeyaml.tokens; 15 16 import org.yaml.snakeyaml.error.Mark; 17 import org.yaml.snakeyaml.error.YAMLException; 18 19 public abstract class Token { 20 21 public enum ID { 22 Alias("<alias>"), Anchor("<anchor>"), BlockEnd("<block end>"), BlockEntry( 23 "-"), BlockMappingStart("<block mapping start>"), BlockSequenceStart( 24 "<block sequence start>"), Directive("<directive>"), DocumentEnd( 25 "<document end>"), DocumentStart("<document start>"), FlowEntry( 26 ","), FlowMappingEnd("}"), FlowMappingStart("{"), FlowSequenceEnd( 27 "]"), FlowSequenceStart("["), Key("?"), Scalar("<scalar>"), StreamEnd( 28 "<stream end>"), StreamStart("<stream start>"), Tag("<tag>"), Value( 29 ":"), Whitespace("<whitespace>"), Comment("#"), Error("<error>"); 30 31 private final String description; 32 ID(String s)33 ID(String s) { 34 description = s; 35 } 36 37 @Override toString()38 public String toString() { 39 return description; 40 } 41 } 42 43 private final Mark startMark; 44 private final Mark endMark; 45 Token(Mark startMark, Mark endMark)46 public Token(Mark startMark, Mark endMark) { 47 if (startMark == null || endMark == null) { 48 throw new YAMLException("Token requires marks."); 49 } 50 this.startMark = startMark; 51 this.endMark = endMark; 52 } 53 getStartMark()54 public Mark getStartMark() { 55 return startMark; 56 } 57 getEndMark()58 public Mark getEndMark() { 59 return endMark; 60 } 61 62 /** 63 * For error reporting. 64 * 65 * @see "class variable 'id' in PyYAML" 66 * @return ID of this token 67 */ getTokenId()68 public abstract Token.ID getTokenId(); 69 } 70