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