@@ -33,35 +33,37 @@ THE SOFTWARE.
33
33
public abstract class PythonLexerBase : Lexer
34
34
{
35
35
// A stack that keeps track of the indentation lengths
36
- private Stack < int > _indentLengthStack = new Stack < int > ( ) ;
36
+ private Stack < int > _indentLengthStack ;
37
37
// A list where tokens are waiting to be loaded into the token stream
38
- private LinkedList < IToken > _pendingTokens = new LinkedList < IToken > ( ) ;
38
+ private LinkedList < IToken > _pendingTokens ;
39
39
// last pending token types
40
- private int _previousPendingTokenType = 0 ;
41
- private int _lastPendingTokenTypeFromDefaultChannel = 0 ;
40
+ private int _previousPendingTokenType ;
41
+ private int _lastPendingTokenTypeFromDefaultChannel ;
42
42
43
43
// The amount of opened parentheses, square brackets, or curly braces
44
- private int _opened = 0 ;
44
+ private int _opened ;
45
45
46
- private bool _wasSpaceIndentation = false ;
47
- private bool _wasTabIndentation = false ;
48
- private bool _wasIndentationMixedWithSpacesAndTabs = false ;
46
+ private bool _wasSpaceIndentation ;
47
+ private bool _wasTabIndentation ;
48
+ private bool _wasIndentationMixedWithSpacesAndTabs ;
49
49
private const int INVALID_LENGTH = - 1 ;
50
50
51
- private CommonToken _curToken = null ! ; // current (under processing) token
52
- private IToken _ffgToken = null ! ; // following (look ahead) token
51
+ private CommonToken _curToken ; // current (under processing) token
52
+ private IToken _ffgToken ; // following (look ahead) token
53
53
54
54
private const string _ERR_TXT = " ERROR: " ;
55
55
56
56
protected PythonLexerBase ( ICharStream input ) : base ( input )
57
57
{
58
+ Init ( ) ;
58
59
}
59
60
60
61
protected PythonLexerBase ( ICharStream input , TextWriter output , TextWriter errorOutput ) : base ( input , output , errorOutput )
61
62
{
63
+ Init ( ) ;
62
64
}
63
65
64
- public override void Reset ( )
66
+ private void Init ( )
65
67
{
66
68
_indentLengthStack = new Stack < int > ( ) ;
67
69
_pendingTokens = new LinkedList < IToken > ( ) ;
@@ -73,7 +75,6 @@ public override void Reset()
73
75
_wasIndentationMixedWithSpacesAndTabs = false ;
74
76
_curToken = null ! ;
75
77
_ffgToken = null ! ;
76
- base . Reset ( ) ;
77
78
}
78
79
79
80
public override IToken NextToken ( ) // reading the input stream until a return EOF
@@ -385,4 +386,10 @@ private void ReportError(string errMsg)
385
386
// the ERROR_TOKEN will raise an error in the parser
386
387
CreateAndAddPendingToken ( PythonLexer . ERROR_TOKEN , TokenConstants . DefaultChannel , _ERR_TXT + errMsg , _ffgToken ) ;
387
388
}
389
+
390
+ public override void Reset ( )
391
+ {
392
+ Init ( ) ;
393
+ base . Reset ( ) ;
394
+ }
388
395
}
0 commit comments