KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > syntax > element > ElementGrammarName


1 package org.antlr.works.syntax.element;
2
3 import org.antlr.works.ate.syntax.misc.ATEToken;
4
5 import java.util.ArrayList JavaDoc;
6 import java.util.List JavaDoc;
7 /*
8
9 [The "BSD licence"]
10 Copyright (c) 2005 Jean Bovet
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions
15 are met:
16
17 1. Redistributions of source code must retain the above copyright
18 notice, this list of conditions and the following disclaimer.
19 2. Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
22 3. The name of the author may not be used to endorse or promote products
23 derived from this software without specific prior written permission.
24
25 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
36 */

37
38 public class ElementGrammarName {
39
40     public static final List JavaDoc<String JavaDoc> types;
41
42     public static final int COMBINED = 0;
43     public static final int PARSER = 1;
44     public static final int LEXER = 2;
45     public static final int TREEPARSER = 3;
46
47     public ATEToken name;
48     public ATEToken start;
49     public ATEToken end;
50     public ATEToken type;
51
52     static {
53         types = new ArrayList JavaDoc<String JavaDoc>();
54         types.add("combined");
55         types.add("parser");
56         types.add("lexer");
57         types.add("tree");
58     }
59
60     public ElementGrammarName(ATEToken name, ATEToken start, ATEToken end, ATEToken type) {
61         this.name = name;
62         this.start = type==null?start:type;
63         this.end = end;
64         this.type = type;
65     }
66
67     public int getType() {
68         int t = COMBINED;
69         if(type != null) {
70             t = types.indexOf(type.getAttribute());
71         }
72
73         if(t == -1) {
74             return COMBINED;
75         } else {
76             return t;
77         }
78     }
79
80     public String JavaDoc getName() {
81         return name.getAttribute();
82     }
83
84     public static boolean isKnownType(String JavaDoc type) {
85         return types.contains(type);
86     }
87
88 }
89
Popular Tags