001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008:
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package antlr;
021:
022: import antlr.collections.impl.BitSet;
023:
024: /**
025: *
026: * @author gorrus
027: */
028: public abstract class CharScannerNoEx extends CharScanner {
029: public CharScannerNoEx() {
030: super ();
031: }
032:
033: public CharScannerNoEx(InputBuffer cb) { // SAS: use generic buffer
034: super (cb);
035: }
036:
037: public CharScannerNoEx(LexerSharedInputState sharedState) {
038: super (sharedState);
039: }
040:
041: public void match(char c) {
042: if (LA(1) == c) {
043: consume();
044: //matchError = false;
045: } else {
046: if (inputState.guessing == 0) {
047: matchException = new MismatchedCharException(LA(1), c,
048: false, this );
049: }
050: matchError = true;
051: }
052: }
053:
054: public void match(BitSet b) {
055: if (b.member(LA(1))) {
056: consume();
057: //matchError = false;
058: } else {
059: if (inputState.guessing == 0) {
060: matchException = new MismatchedCharException(LA(1), b,
061: false, this );
062: }
063: matchError = true;
064: }
065: }
066:
067: public void match(String s) {
068: int len = s.length();
069: for (int i = 0; i < len; i++) {
070: if (LA(1) != s.charAt(i)) {
071: if (inputState.guessing == 0) {
072: matchException = new MismatchedCharException(LA(1),
073: s.charAt(i), false, this );
074: }
075: matchError = true;
076: return;
077: }
078: consume();
079: }
080: //matchError = false;
081: }
082:
083: public void matchNot(char c) {
084: if (LA(1) != c) {
085: consume();
086: //matchError = false;
087: } else {
088: if (inputState.guessing == 0) {
089: matchException = new MismatchedCharException(LA(1), c,
090: true, this );
091: }
092: matchError = true;
093: }
094: }
095:
096: public void matchRange(char c1, char c2) {
097: char LA1 = LA(1);
098: if (LA1 < c1 || LA1 > c2) {
099: if (inputState.guessing == 0) {
100: matchException = new MismatchedCharException(LA(1), c1,
101: c2, false, this );
102: }
103: matchError = true;
104: } else {
105: consume();
106: //matchError = false;
107: }
108: }
109:
110: public void setCaseSensitive(boolean t) {
111: if (t != true) {
112: throw new UnsupportedOperationException(
113: "In this version only case sensitive grammars supported");
114: }
115: super .setCaseSensitive(t);
116: }
117:
118: public void consume() {
119: if (inputState.guessing == 0) {
120: char c = LA(1);
121: append(c);
122: if (c == '\t') {
123: tab();
124: } else {
125: inputState.column++;
126: }
127: }
128: inputState.input.consume();
129: }
130:
131: public char LA(int i) {
132: return inputState.input.LA(i);
133: }
134: }
|