1
16 package org.yaml.snakeyaml.tokens;
17
18 import org.yaml.snakeyaml.error.Mark;
19 import org.yaml.snakeyaml.error.YAMLException;
20
21 public abstract class Token {
22 public enum ID {
23 Alias("<alias>"),
24 Anchor("<anchor>"),
25 BlockEnd("<block end>"),
26 BlockEntry("-"),
27 BlockMappingStart("<block mapping start>"),
28 BlockSequenceStart("<block sequence start>"),
29 Directive("<directive>"),
30 DocumentEnd("<document end>"),
31 DocumentStart("<document start>"),
32 FlowEntry(","),
33 FlowMappingEnd("}"),
34 FlowMappingStart("{"),
35 FlowSequenceEnd("]"),
36 FlowSequenceStart("["),
37 Key("?"),
38 Scalar("<scalar>"),
39 StreamEnd("<stream end>"),
40 StreamStart("<stream start>"),
41 Tag("<tag>"),
42 Value(":"),
43 Whitespace("<whitespace>"),
44 Comment("#"),
45 Error("<error>");
46
47 private final String description;
48
49 ID(String s) {
50 description = s;
51 }
52
53 @Override
54 public String toString() {
55 return description;
56 }
57 }
58
59 private final Mark startMark;
60 private final Mark endMark;
61
62 public Token(Mark startMark, Mark endMark) {
63 if (startMark == null || endMark == null) {
64 throw new YAMLException("Token requires marks.");
65 }
66 this.startMark = startMark;
67 this.endMark = endMark;
68 }
69
70 public Mark getStartMark() {
71 return startMark;
72 }
73
74 public Mark getEndMark() {
75 return endMark;
76 }
77
78
84 public abstract Token.ID getTokenId();
85 }
86