Skip to content

Commit 72a4320

Browse files
committed
update PythonLexerBase
1 parent e5935b9 commit 72a4320

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

port_CSharp/PythonLexerBase.cs

+17-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ THE SOFTWARE.
3333
public abstract class PythonLexerBase : Lexer
3434
{
3535
// A stack that keeps track of the indentation lengths
36-
private readonly Stack<int> _indentLengthStack = new Stack<int>();
36+
private Stack<int> _indentLengthStack = new Stack<int>();
3737
// A list where tokens are waiting to be loaded into the token stream
38-
private readonly LinkedList<IToken> _pendingTokens = new LinkedList<IToken>();
38+
private LinkedList<IToken> _pendingTokens = new LinkedList<IToken>();
3939
// last pending token types
4040
private int _previousPendingTokenType = 0;
4141
private int _lastPendingTokenTypeFromDefaultChannel = 0;
@@ -61,6 +61,21 @@ protected PythonLexerBase(ICharStream input, TextWriter output, TextWriter error
6161
{
6262
}
6363

64+
public override void Reset()
65+
{
66+
_indentLengthStack = new Stack<int>();
67+
_pendingTokens = new LinkedList<IToken>();
68+
_previousPendingTokenType = 0;
69+
_lastPendingTokenTypeFromDefaultChannel = 0;
70+
_opened = 0;
71+
_wasSpaceIndentation = false;
72+
_wasTabIndentation = false;
73+
_wasIndentationMixedWithSpacesAndTabs = false;
74+
_curToken = null!;
75+
_ffgToken = null!;
76+
base.Reset();
77+
}
78+
6479
public override IToken NextToken() // reading the input stream until a return EOF
6580
{
6681
CheckNextToken();

port_JavaScript/PythonLexerBase.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ export default class PythonLexerBase extends antlr4.Lexer {
5151
this._wasIndentationMixedWithSpacesAndTabs = false;
5252
this._INVALID_LENGTH = -1;
5353

54-
this._curToken; // current (under processing) token
55-
this._ffgToken; // following (look ahead) token
54+
this._curToken = null; // current (under processing) token
55+
this._ffgToken = null; // following (look ahead) token
5656

5757
this._ERR_TXT = " ERROR: ";
5858
}
@@ -309,4 +309,20 @@ export default class PythonLexerBase extends antlr4.Lexer {
309309
// the ERROR_TOKEN will raise an error in the parser
310310
this.createAndAddPendingToken(PythonLexer.ERROR_TOKEN, Token.DEFAULT_CHANNEL, this._ERR_TXT + errMsg, this._ffgToken);
311311
}
312+
313+
reset() {
314+
this._indentLengthStack = [];
315+
this._pendingTokens = [];
316+
this._previousPendingTokenType = 0;
317+
this._lastPendingTokenTypeFromDefaultChannel = 0;
318+
this._opened = 0;
319+
this._wasSpaceIndentation = false;
320+
this._wasTabIndentation = false;
321+
this._wasIndentationMixedWithSpacesAndTabs = false;
322+
this._INVALID_LENGTH = -1;
323+
this._curToken = null;
324+
this._ffgToken = null;
325+
this._ERR_TXT = " ERROR: ";
326+
super.reset();
327+
}
312328
}

port_Python3/PythonLexerBase.py

+15
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ def __init__(self, input: InputStream, output: TextIO = sys.stdout):
5555

5656
self._ERR_TXT: str = " ERROR: "
5757

58+
def reset(self):
59+
self._indent_length_stack = deque()
60+
self._pending_tokens = []
61+
self._previous_pending_token_type = 0
62+
self._last_pending_token_type_from_default_channel = 0
63+
self._opened = 0
64+
self._was_space_indentation = False
65+
self._was_tab_indentation = False
66+
self._was_indentation_mixed_with_spaces_and_tabs = False
67+
self._INVALID_LENGTH = -1
68+
self._cur_token = None
69+
self._ffg_token = None
70+
self._ERR_TXT = " ERROR: "
71+
super().reset()
72+
5873
def nextToken(self) -> CommonToken: # reading the input stream until a return EOF
5974
self.check_next_token()
6075
return self._pending_tokens.pop(0) # add the queued token to the token stream

0 commit comments

Comments
 (0)