1*16467b97STreehugger Robot // [The "BSD licence"] 2*16467b97STreehugger Robot // Copyright (c) 2007 Kay Roepke 2010 Alan Condit 3*16467b97STreehugger Robot // All rights reserved. 4*16467b97STreehugger Robot // 5*16467b97STreehugger Robot // Redistribution and use in source and binary forms, with or without 6*16467b97STreehugger Robot // modification, are permitted provided that the following conditions 7*16467b97STreehugger Robot // are met: 8*16467b97STreehugger Robot // 1. Redistributions of source code must retain the above copyright 9*16467b97STreehugger Robot // notice, this list of conditions and the following disclaimer. 10*16467b97STreehugger Robot // 2. Redistributions in binary form must reproduce the above copyright 11*16467b97STreehugger Robot // notice, this list of conditions and the following disclaimer in the 12*16467b97STreehugger Robot // documentation and/or other materials provided with the distribution. 13*16467b97STreehugger Robot // 3. The name of the author may not be used to endorse or promote products 14*16467b97STreehugger Robot // derived from this software without specific prior written permission. 15*16467b97STreehugger Robot // 16*16467b97STreehugger Robot // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17*16467b97STreehugger Robot // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18*16467b97STreehugger Robot // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19*16467b97STreehugger Robot // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20*16467b97STreehugger Robot // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21*16467b97STreehugger Robot // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22*16467b97STreehugger Robot // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23*16467b97STreehugger Robot // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24*16467b97STreehugger Robot // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25*16467b97STreehugger Robot // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26*16467b97STreehugger Robot 27*16467b97STreehugger Robot #import <Foundation/Foundation.h> 28*16467b97STreehugger Robot #import "Token.h" 29*16467b97STreehugger Robot #import "ANTLRBitSet.h" 30*16467b97STreehugger Robot #import "RuleStack.h" 31*16467b97STreehugger Robot #import "AMutableArray.h" 32*16467b97STreehugger Robot 33*16467b97STreehugger Robot @interface RecognizerSharedState : NSObject { 34*16467b97STreehugger Robot __strong AMutableArray *following; // a stack of FOLLOW bitsets used for context sensitive prediction and recovery 35*16467b97STreehugger Robot NSInteger _fsp; // Follow stack pointer 36*16467b97STreehugger Robot BOOL errorRecovery; // are we recovering? 37*16467b97STreehugger Robot NSInteger lastErrorIndex; 38*16467b97STreehugger Robot BOOL failed; // indicate that some match failed 39*16467b97STreehugger Robot NSInteger syntaxErrors; 40*16467b97STreehugger Robot NSInteger backtracking; // the level of backtracking 41*16467b97STreehugger Robot __strong RuleStack *ruleMemo; // store previous results of matching rules so we don't have to do it again. Hook in incremental stuff here, too. 42*16467b97STreehugger Robot 43*16467b97STreehugger Robot __strong id<Token> token; 44*16467b97STreehugger Robot NSInteger tokenStartCharIndex; 45*16467b97STreehugger Robot NSUInteger tokenStartLine; 46*16467b97STreehugger Robot NSUInteger tokenStartCharPositionInLine; 47*16467b97STreehugger Robot NSUInteger channel; 48*16467b97STreehugger Robot NSUInteger type; 49*16467b97STreehugger Robot NSString *text; 50*16467b97STreehugger Robot } 51*16467b97STreehugger Robot 52*16467b97STreehugger Robot @property (retain, getter=getFollowing, setter=setFollowing:) AMutableArray *following; 53*16467b97STreehugger Robot @property (assign) NSInteger _fsp; 54*16467b97STreehugger Robot @property (assign) BOOL errorRecovery; 55*16467b97STreehugger Robot @property (assign) NSInteger lastErrorIndex; 56*16467b97STreehugger Robot @property (assign, getter=getFailed, setter=setFailed:) BOOL failed; 57*16467b97STreehugger Robot @property (assign) NSInteger syntaxErrors; 58*16467b97STreehugger Robot @property (assign, getter=getBacktracking, setter=setBacktracking:) NSInteger backtracking; 59*16467b97STreehugger Robot @property (retain, getter=getRuleMemo, setter=setRuleMemo:) RuleStack *ruleMemo; 60*16467b97STreehugger Robot @property (copy, getter=getToken, setter=setToken:) id<Token> token; 61*16467b97STreehugger Robot @property (getter=type,setter=setType:) NSUInteger type; 62*16467b97STreehugger Robot @property (getter=channel,setter=setChannel:) NSUInteger channel; 63*16467b97STreehugger Robot @property (getter=getTokenStartLine,setter=setTokenStartLine:) NSUInteger tokenStartLine; 64*16467b97STreehugger Robot @property (getter=charPositionInLine,setter=setCharPositionInLine:) NSUInteger tokenStartCharPositionInLine; 65*16467b97STreehugger Robot @property (getter=getTokenStartCharIndex,setter=setTokenStartCharIndex:) NSInteger tokenStartCharIndex; 66*16467b97STreehugger Robot @property (retain, getter=text, setter=setText:) NSString *text; 67*16467b97STreehugger Robot 68*16467b97STreehugger Robot + (RecognizerSharedState *) newRecognizerSharedState; 69*16467b97STreehugger Robot + (RecognizerSharedState *) newRecognizerSharedStateWithRuleLen:(NSInteger)aLen; 70*16467b97STreehugger Robot + (RecognizerSharedState *) newRecognizerSharedState:(RecognizerSharedState *)aState; 71*16467b97STreehugger Robot 72*16467b97STreehugger Robot - (id) init; 73*16467b97STreehugger Robot - (id) initWithRuleLen:(NSInteger)aLen; 74*16467b97STreehugger Robot - (id) initWithState:(RecognizerSharedState *)state; 75*16467b97STreehugger Robot 76*16467b97STreehugger Robot - (id<Token>) getToken; 77*16467b97STreehugger Robot - (void) setToken:(id<Token>) theToken; 78*16467b97STreehugger Robot 79*16467b97STreehugger Robot - (NSUInteger)type; 80*16467b97STreehugger Robot - (void) setType:(NSUInteger) theTokenType; 81*16467b97STreehugger Robot 82*16467b97STreehugger Robot - (NSUInteger)channel; 83*16467b97STreehugger Robot - (void) setChannel:(NSUInteger) theChannel; 84*16467b97STreehugger Robot 85*16467b97STreehugger Robot - (NSUInteger) getTokenStartLine; 86*16467b97STreehugger Robot - (void) setTokenStartLine:(NSUInteger) theTokenStartLine; 87*16467b97STreehugger Robot 88*16467b97STreehugger Robot - (NSUInteger) charPositionInLine; 89*16467b97STreehugger Robot - (void) setCharPositionInLine:(NSUInteger) theCharPosition; 90*16467b97STreehugger Robot 91*16467b97STreehugger Robot - (NSInteger) getTokenStartCharIndex; 92*16467b97STreehugger Robot - (void) setTokenStartCharIndex:(NSInteger) theTokenStartCharIndex; 93*16467b97STreehugger Robot 94*16467b97STreehugger Robot - (NSString *)text; 95*16467b97STreehugger Robot - (void) setText:(NSString *) theText; 96*16467b97STreehugger Robot 97*16467b97STreehugger Robot 98*16467b97STreehugger Robot - (AMutableArray *) getFollowing; 99*16467b97STreehugger Robot - (void)setFollowing:(AMutableArray *)aFollow; 100*16467b97STreehugger Robot - (RuleStack *) getRuleMemo; 101*16467b97STreehugger Robot - (void)setRuleMemo:(RuleStack *)aRuleMemo; 102*16467b97STreehugger Robot - (BOOL) isErrorRecovery; 103*16467b97STreehugger Robot - (void) setIsErrorRecovery: (BOOL) flag; 104*16467b97STreehugger Robot 105*16467b97STreehugger Robot - (BOOL) getFailed; 106*16467b97STreehugger Robot - (void) setFailed: (BOOL) flag; 107*16467b97STreehugger Robot 108*16467b97STreehugger Robot - (NSInteger) getBacktracking; 109*16467b97STreehugger Robot - (void) setBacktracking:(NSInteger) value; 110*16467b97STreehugger Robot - (void) increaseBacktracking; 111*16467b97STreehugger Robot - (void) decreaseBacktracking; 112*16467b97STreehugger Robot - (BOOL) isBacktracking; 113*16467b97STreehugger Robot 114*16467b97STreehugger Robot - (NSInteger) lastErrorIndex; 115*16467b97STreehugger Robot - (void) setLastErrorIndex:(NSInteger) value; 116*16467b97STreehugger Robot 117*16467b97STreehugger Robot @end 118