This is an automated email from the ASF dual-hosted git repository.

lkishalmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 12f20e87a7 Save/restore the ANTLR RustLexer specific internals. (#5624)
12f20e87a7 is described below

commit 12f20e87a763cfa033ab614d7069c006e1c84174
Author: Laszlo Kishalmi <[email protected]>
AuthorDate: Wed Mar 8 11:54:49 2023 -0800

    Save/restore the ANTLR RustLexer specific internals. (#5624)
    
    * Save/restore the ANTLR RustLexer specific internals.
    
    * Use just the token type in RustLexerBase
---
 .../modules/rust/grammar/RustLanguageLexer.java    | 27 ++++++++++++++++++++--
 .../modules/rust/grammar/antlr4/RustLexerBase.java | 10 ++++----
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git 
a/rust/rust.grammar/src/org/netbeans/modules/rust/grammar/RustLanguageLexer.java
 
b/rust/rust.grammar/src/org/netbeans/modules/rust/grammar/RustLanguageLexer.java
index 8d1892e6f2..80f365b70d 100644
--- 
a/rust/rust.grammar/src/org/netbeans/modules/rust/grammar/RustLanguageLexer.java
+++ 
b/rust/rust.grammar/src/org/netbeans/modules/rust/grammar/RustLanguageLexer.java
@@ -21,7 +21,6 @@ package org.netbeans.modules.rust.grammar;
 import java.util.BitSet;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import org.antlr.v4.runtime.ANTLRErrorListener;
 import org.antlr.v4.runtime.BaseErrorListener;
 import org.antlr.v4.runtime.CharStream;
 import org.antlr.v4.runtime.Parser;
@@ -75,7 +74,7 @@ public class RustLanguageLexer extends 
AbstractAntlrLexerBridge<RustLexer, RustT
 
     }
 
-    private static final RustLexer createLexer(CharStream input) {
+    private static RustLexer createLexer(CharStream input) {
         RustLexer lexer = new RustLexer(input);
         lexer.removeErrorListeners();
         lexer.addErrorListener(new RustLanguageLexerErrorListener());
@@ -91,4 +90,28 @@ public class RustLanguageLexer extends 
AbstractAntlrLexerBridge<RustLexer, RustT
         return token(RustTokenID.from(antlrToken));
     }
 
+    @Override
+    public Object state() {
+        return new LexerState(lexer);
+    }
+
+    private static final class LexerState extends 
AbstractAntlrLexerBridge.LexerState<RustLexer> {
+        final Integer lt1;
+        final Integer lt2;
+
+        LexerState(RustLexer lexer) {
+            super(lexer);
+
+            this.lt1 = lexer.lt1;
+            this.lt2 = lexer.lt2;
+        }
+
+        @Override
+        public void restore(RustLexer lexer) {
+            super.restore(lexer);
+
+            lexer.lt1 = lt1;
+            lexer.lt2 = lt2;
+        }
+    }
 }
diff --git 
a/rust/rust.grammar/src/org/netbeans/modules/rust/grammar/antlr4/RustLexerBase.java
 
b/rust/rust.grammar/src/org/netbeans/modules/rust/grammar/antlr4/RustLexerBase.java
index 39c5919663..cefd4b7a5d 100644
--- 
a/rust/rust.grammar/src/org/netbeans/modules/rust/grammar/antlr4/RustLexerBase.java
+++ 
b/rust/rust.grammar/src/org/netbeans/modules/rust/grammar/antlr4/RustLexerBase.java
@@ -54,8 +54,8 @@ public abstract class RustLexerBase extends Lexer {
         super(input);
     }
 
-    Token lt1;
-    Token lt2;
+    public Integer lt1;
+    public Integer lt2;
 
     @Override
     public Token nextToken() {
@@ -85,7 +85,7 @@ public abstract class RustLexerBase extends Lexer {
         if (next.getChannel() == Token.DEFAULT_CHANNEL) {
             // Keep track of the last token on the default channel.
             this.lt2 = this.lt1;
-            this.lt1 = next;
+            this.lt1 = next.getType();
         }
 
         return next;
@@ -130,10 +130,10 @@ public abstract class RustLexerBase extends Lexer {
         if (this.lt1 == null || this.lt2 == null) {
             return true;
         }
-        if (this.lt1.getType() != RustLexer.DOT) {
+        if (this.lt1 != RustLexer.DOT) {
             return true;
         }
-        switch (this.lt2.getType()) {
+        switch (this.lt2) {
             case RustLexer.CHAR_LITERAL:
             case RustLexer.STRING_LITERAL:
             case RustLexer.RAW_STRING_LITERAL:


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to