java-commons/muscript/src/main/java/io/gitlab/jfronny/muscript/compiler/lexer/LegacyLexer.java

68 lines
1.7 KiB
Java

package io.gitlab.jfronny.muscript.compiler.lexer;
import io.gitlab.jfronny.muscript.compiler.*;
import org.jetbrains.annotations.Nullable;
/**
* Wraps the old Lexer implementation in the new Lexer interface for compatibility
*/
public class LegacyLexer implements Lexer {
private final io.gitlab.jfronny.muscript.compiler.Lexer backend;
private Lexer.Token previous = null;
public LegacyLexer(MuScriptVersion version, String source) {
this(new io.gitlab.jfronny.muscript.compiler.Lexer(version, source));
}
public LegacyLexer(MuScriptVersion version, String source, String file) {
this(new io.gitlab.jfronny.muscript.compiler.Lexer(version, source, file));
}
public LegacyLexer(io.gitlab.jfronny.muscript.compiler.Lexer backend) {
this.backend = backend;
}
@Override
public CodeLocation location() {
return backend.location();
}
@Override
public MuScriptVersion version() {
return backend.getComponentVersion();
}
@Override
public boolean wasNewlinePassed() {
return backend.passedNewline;
}
@Override
public Token getPrevious() {
return previous;
}
@Override
public Token advance() {
backend.next();
return previous = new Token(
backend.lexeme,
backend.token,
backend.start,
backend.current,
backend.ch,
new CodeLocation(backend.start, backend.current - 1, backend.source, backend.file)
);
}
@Override
public @Nullable String getSource() {
return backend.source;
}
@Override
public @Nullable String getFile() {
return backend.file;
}
}