Home | History | Annotate | Download | only in Framework
      1 // [The "BSD licence"]
      2 // Copyright (c) 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 #import <Cocoa/Cocoa.h>
     28 #import "ANTLRToken.h"
     29 #import "ANTLRBitSet.h"
     30 #import "ANTLRRuleStack.h"
     31 #import "AMutableArray.h"
     32 
     33 @interface ANTLRRecognizerSharedState : NSObject {
     34 	__strong AMutableArray *following;  // a stack of FOLLOW bitsets used for context sensitive prediction and recovery
     35     NSInteger _fsp;                     // Follow stack pointer
     36 	BOOL errorRecovery;                 // are we recovering?
     37 	NSInteger lastErrorIndex;
     38 	BOOL failed;                        // indicate that some match failed
     39     NSInteger syntaxErrors;
     40 	NSInteger backtracking;             // the level of backtracking
     41 	__strong ANTLRRuleStack *ruleMemo;	// store previous results of matching rules so we don't have to do it again. Hook in incremental stuff here, too.
     42 
     43 	__strong id<ANTLRToken> token;
     44 	NSInteger  tokenStartCharIndex;
     45 	NSUInteger tokenStartLine;
     46 	NSUInteger tokenStartCharPositionInLine;
     47 	NSUInteger channel;
     48 	NSUInteger type;
     49 	NSString   *text;
     50 }
     51 
     52 @property (retain, getter=getFollowing, setter=setFollowing:) AMutableArray *following;
     53 @property (assign) NSInteger _fsp;
     54 @property (assign) BOOL errorRecovery;
     55 @property (assign) NSInteger lastErrorIndex;
     56 @property (assign, getter=getFailed, setter=setFailed:) BOOL failed;
     57 @property (assign) NSInteger syntaxErrors;
     58 @property (assign, getter=getBacktracking, setter=setBacktracking:) NSInteger backtracking;
     59 @property (retain, getter=getRuleMemo, setter=setRuleMemo:) ANTLRRuleStack *ruleMemo;
     60 @property (copy, getter=getToken, setter=setToken:) id<ANTLRToken> token;
     61 @property (getter=type,setter=setType:) NSUInteger type;
     62 @property (getter=channel,setter=setChannel:) NSUInteger channel;
     63 @property (getter=getTokenStartLine,setter=setTokenStartLine:) NSUInteger tokenStartLine;
     64 @property (getter=charPositionInLine,setter=setCharPositionInLine:) NSUInteger tokenStartCharPositionInLine;
     65 @property (getter=getTokenStartCharIndex,setter=setTokenStartCharIndex:) NSInteger tokenStartCharIndex;
     66 @property (retain, getter=text, setter=setText:) NSString *text;
     67 
     68 + (ANTLRRecognizerSharedState *) newANTLRRecognizerSharedState;
     69 + (ANTLRRecognizerSharedState *) newANTLRRecognizerSharedStateWithRuleLen:(NSInteger)aLen;
     70 + (ANTLRRecognizerSharedState *) newANTLRRecognizerSharedState:(ANTLRRecognizerSharedState *)aState;
     71 
     72 - (id) init;
     73 - (id) initWithRuleLen:(NSInteger)aLen;
     74 - (id) initWithState:(ANTLRRecognizerSharedState *)state;
     75 
     76 - (id<ANTLRToken>) getToken;
     77 - (void) setToken:(id<ANTLRToken>) theToken;
     78 
     79 - (NSUInteger)type;
     80 - (void) setType:(NSUInteger) theTokenType;
     81 
     82 - (NSUInteger)channel;
     83 - (void) setChannel:(NSUInteger) theChannel;
     84 
     85 - (NSUInteger) getTokenStartLine;
     86 - (void) setTokenStartLine:(NSUInteger) theTokenStartLine;
     87 
     88 - (NSUInteger) charPositionInLine;
     89 - (void) setCharPositionInLine:(NSUInteger) theCharPosition;
     90 
     91 - (NSInteger) getTokenStartCharIndex;
     92 - (void) setTokenStartCharIndex:(NSInteger) theTokenStartCharIndex;
     93 
     94 - (NSString *)text;
     95 - (void) setText:(NSString *) theText;
     96 
     97 
     98 - (AMutableArray *) getFollowing;
     99 - (void)setFollowing:(AMutableArray *)aFollow;
    100 - (ANTLRRuleStack *) getRuleMemo;
    101 - (void)setRuleMemo:(ANTLRRuleStack *)aRuleMemo;
    102 - (BOOL) isErrorRecovery;
    103 - (void) setIsErrorRecovery: (BOOL) flag;
    104 
    105 - (BOOL) getFailed;
    106 - (void) setFailed: (BOOL) flag;
    107 
    108 - (NSInteger)  getBacktracking;
    109 - (void) setBacktracking:(NSInteger) value;
    110 - (void) increaseBacktracking;
    111 - (void) decreaseBacktracking;
    112 - (BOOL) isBacktracking;
    113 
    114 - (NSInteger) lastErrorIndex;
    115 - (void) setLastErrorIndex:(NSInteger) value;
    116 
    117 @end
    118