1// [The "BSD licence"] 2// Copyright (c) 2006-2007 Kay Roepke 2010 Alan Condit 3// All rights reserved. 4// 5// Redistribution and use in source and binary forms, with or without 6// modification, are permitted provided that the following conditions 7// are met: 8// 1. Redistributions of source code must retain the above copyright 9// notice, this list of conditions and the following disclaimer. 10// 2. Redistributions in binary form must reproduce the above copyright 11// notice, this list of conditions and the following disclaimer in the 12// documentation and/or other materials provided with the distribution. 13// 3. The name of the author may not be used to endorse or promote products 14// derived from this software without specific prior written permission. 15// 16// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 27 28#import <Cocoa/Cocoa.h> 29#import "ANTLRTokenSource.h" 30#import "ANTLRBaseRecognizer.h" 31#import "ANTLRRecognizerSharedState.h" 32#import "ANTLRCharStream.h" 33#import "ANTLRToken.h" 34#import "ANTLRCommonToken.h" 35#import "ANTLRRecognitionException.h" 36#import "ANTLRMismatchedTokenException.h" 37#import "ANTLRMismatchedRangeException.h" 38 39@interface ANTLRLexer : ANTLRBaseRecognizer <ANTLRTokenSource> { 40 id<ANTLRCharStream> input; ///< The character stream we pull tokens out of. 41 NSUInteger ruleNestingLevel; 42} 43 44@property (retain, getter=getInput, setter=setInput:) id<ANTLRCharStream> input; 45@property (getter=getRuleNestingLevel, setter=setRuleNestingLevel) NSUInteger ruleNestingLevel; 46 47#pragma mark Initializer 48- (id) initWithCharStream:(id<ANTLRCharStream>) anInput; 49- (id) initWithCharStream:(id<ANTLRCharStream>)anInput State:(ANTLRRecognizerSharedState *)state; 50 51- (id) copyWithZone:(NSZone *)zone; 52 53- (void) reset; 54 55// - (ANTLRRecognizerSharedState *) state; 56 57#pragma mark Tokens 58- (id<ANTLRToken>)getToken; 59- (void) setToken: (id<ANTLRToken>) aToken; 60- (id<ANTLRToken>) nextToken; 61- (void) mTokens; // abstract, defined in generated sources 62- (void) skip; 63- (id<ANTLRCharStream>) getInput; 64- (void) setInput:(id<ANTLRCharStream>)aCharStream; 65 66- (void) emit; 67- (void) emit:(id<ANTLRToken>)aToken; 68 69#pragma mark Matching 70- (void) matchString:(NSString *)aString; 71- (void) matchAny; 72- (void) matchChar:(unichar) aChar; 73- (void) matchRangeFromChar:(unichar)fromChar to:(unichar)toChar; 74 75#pragma mark Informational 76- (NSUInteger) getLine; 77- (NSUInteger) getCharPositionInLine; 78- (NSInteger) getIndex; 79- (NSString *) getText; 80- (void) setText:(NSString *) theText; 81 82// error handling 83- (void) reportError:(ANTLRRecognitionException *)e; 84- (NSString *)getErrorMessage:(ANTLRRecognitionException *)e TokenNames:(NSMutableArray *)tokenNames; 85- (NSString *)getCharErrorDisplay:(NSInteger)c; 86- (void) recover:(ANTLRRecognitionException *)e; 87- (void)traceIn:(NSString *)ruleName Index:(NSInteger)ruleIndex; 88- (void)traceOut:(NSString *)ruleName Index:(NSInteger)ruleIndex; 89 90@end 91