Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not expose LexerInputCharStream as an API. #5257

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
*/
public final class TomlLexer extends AbstractAntlrLexerBridge<org.tomlj.internal.TomlLexer, TomlTokenId> {

public TomlLexer(LexerRestartInfo<TomlTokenId> info, org.tomlj.internal.TomlLexer lexer) {
super(info, lexer);
public TomlLexer(LexerRestartInfo<TomlTokenId> info) {
super(info, org.tomlj.internal.TomlLexer::new);
}

@Override
Expand Down Expand Up @@ -122,6 +122,7 @@ private static class LexerState extends AbstractAntlrLexerBridge.LexerState<org.
this.arrayDepthStack = new IntegerStack(lexer.arrayDepthStack);
}

@Override
public void restore(org.tomlj.internal.TomlLexer lexer) {
super.restore(lexer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.netbeans.spi.lexer.LanguageHierarchy;
import org.netbeans.spi.lexer.Lexer;
import org.netbeans.spi.lexer.LexerRestartInfo;
import org.netbeans.spi.lexer.antlr4.LexerInputCharStream;

/**
*
Expand Down Expand Up @@ -67,7 +66,7 @@ protected Collection<TomlTokenId> createTokenIds() {

@Override
protected Lexer<TomlTokenId> createLexer(LexerRestartInfo<TomlTokenId> info) {
return new TomlLexer(info, new org.tomlj.internal.TomlLexer(new LexerInputCharStream(info.input())));
return new TomlLexer(info);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.netbeans.spi.lexer.antlr4;

import java.util.function.Function;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.misc.IntegerList;
import org.netbeans.api.lexer.Token;
import org.antlr.v4.runtime.Lexer;
Expand All @@ -38,24 +40,24 @@ public abstract class AbstractAntlrLexerBridge<L extends Lexer, T extends TokenI

private final TokenFactory<T> tokenFactory;
protected final L lexer;
protected final LexerInputCharStream input;
private final LexerInputCharStream input;

/**
* Constructor for the lexer bridge, usually used as:
* <pre>{@code
* public SomeLexer(LexerRestartInfo<SomeTokenId> info) {
* super(info, new SomeANTLRLexer(new LexerInputCharStream(info.input())));
* super(info, SomeANTLRLexer::new);
* }
* }
* </pre>
* @param info The lexer restart info
* @param lexer The ANTLR generated Lexer
* @param lexerCreator A function to create an ANTLR from a {@code CharSteram}.
*/
@SuppressWarnings("unchecked")
public AbstractAntlrLexerBridge(LexerRestartInfo<T> info, L lexer) {
public AbstractAntlrLexerBridge(LexerRestartInfo<T> info, Function<CharStream, L> lexerCreator) {
this.tokenFactory = info.tokenFactory();
this.lexer = lexer;
this.input = (LexerInputCharStream) lexer.getInputStream();
this.input = new LexerInputCharStream(info.input());
this.lexer = lexerCreator.apply(input);
if (info.state() != null) {
((LexerState<L>) info.state()).restore(lexer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @author Laszlo Kishalmi
*/
public class LexerInputCharStream implements CharStream {
final class LexerInputCharStream implements CharStream {
private final LexerInput input;

private int tokenMark = Integer.MAX_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.netbeans.modules.languages.antlr.AntlrTokenId;
import static org.netbeans.modules.languages.antlr.AntlrTokenId.*;
import org.netbeans.spi.lexer.antlr4.AbstractAntlrLexerBridge;
import org.netbeans.spi.lexer.antlr4.LexerInputCharStream;

/**
*
Expand All @@ -36,7 +35,7 @@ public final class Antlr3Lexer extends AbstractAntlrLexerBridge<ANTLRv3Lexer, An


public Antlr3Lexer(LexerRestartInfo<AntlrTokenId> info) {
super(info, new ANTLRv3Lexer(new LexerInputCharStream(info.input())));
super(info, ANTLRv3Lexer::new);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.netbeans.modules.languages.antlr.AntlrTokenId;
import static org.netbeans.modules.languages.antlr.AntlrTokenId.*;
import org.netbeans.spi.lexer.antlr4.AbstractAntlrLexerBridge;
import org.netbeans.spi.lexer.antlr4.LexerInputCharStream;

/**
*
Expand All @@ -36,7 +35,7 @@ public final class Antlr4Lexer extends AbstractAntlrLexerBridge<ANTLRv4Lexer, An


public Antlr4Lexer(LexerRestartInfo<AntlrTokenId> info) {
super(info, new ANTLRv4Lexer(new LexerInputCharStream(info.input())));
super(info, ANTLRv4Lexer::new);
}

@Override
Expand Down