1 31 32 package org.antlr.works.ate.syntax.misc; 33 34 public class ATEToken implements Comparable { 35 36 public int type; 37 38 public int startLineNumber; public int endLineNumber; public int startLineIndex; public int endLineIndex; protected String text; 44 48 public int start; 49 public int end; 50 51 protected String attribute; 53 public int index; public boolean modified; public ATEScope scope; 56 57 public ATEToken(int type, int start, int end, 58 int startLineNumber, int endLineNumber, 59 int startLineIndex, int endLineIndex, 60 String text) 61 { 62 this.type = type; 63 64 this.start = start; 65 this.end = end; 66 67 this.startLineNumber = startLineNumber; 68 this.endLineNumber = endLineNumber; 69 this.startLineIndex = startLineIndex; 70 this.endLineIndex = endLineIndex; 71 72 this.text = text; 73 this.attribute = text.substring(start, end); 74 } 75 76 public String getText() { 77 return text; 78 } 79 80 public String getAttribute() { 81 return attribute; 82 } 83 84 public int getStartLineIndex() { 85 return startLineIndex; 86 } 87 88 public int getStartIndex() { 89 return start; 90 } 91 92 public int getEndIndex() { 93 return end; 94 } 95 96 public boolean containsIndex(int index) { 97 return index >= getStartIndex() && index <= getEndIndex(); 98 } 99 100 public boolean equals(Object otherObject) { 101 if(otherObject == null) { 102 return false; 103 } 104 105 if(otherObject instanceof ATEToken) { 106 ATEToken otherToken = (ATEToken)otherObject; 107 return type == otherToken.type && 108 start == otherToken.start && 109 end == otherToken.end; 110 } else { 111 return false; 112 } 113 } 114 115 public int compareTo(Object o) { 116 if(o instanceof ATEToken) { 117 ATEToken otherToken = (ATEToken)o; 118 return this.getAttribute().compareTo(otherToken.getAttribute()); 119 } else { 120 return 1; 121 } 122 } 123 124 public String toString() { 125 return getAttribute()+" <type="+type+", start="+start+", end="+end+">"; 126 } 127 128 public static boolean isLexerName(String name) { 129 if(name == null || name.length() < 1) 130 return false; 131 else 132 return name.charAt(0) == name.toUpperCase().charAt(0); 133 } 134 } 135 | Popular Tags |