1 /**
2  * Copyright (c) 2008, http://www.snakeyaml.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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     /**
79      * For error reporting.
80      * 
81      * @see "class variable 'id' in PyYAML"
82      * @return ID of this token
83      */

84     public abstract Token.ID getTokenId();
85 }
86