mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
Мелкие исправления для повышения скорости
This commit is contained in:
parent
4df44cadea
commit
03b56ce019
@ -203,7 +203,7 @@ public final class Lexer {
|
||||
clearBuffer();
|
||||
while (true) {
|
||||
final String text = buffer.toString();
|
||||
if (!OPERATORS.containsKey(text + current) && !text.isEmpty()) {
|
||||
if (!text.isEmpty() && !OPERATORS.containsKey(text + current)) {
|
||||
addToken(OPERATORS.get(text));
|
||||
return;
|
||||
}
|
||||
@ -237,9 +237,9 @@ public final class Lexer {
|
||||
clearBuffer();
|
||||
char current = peek(0);
|
||||
while (true) {
|
||||
if (current == '`') break;
|
||||
if (current == '\0') throw error("Reached end of file while parsing extended word.");
|
||||
if (current == '\n' || current == '\r') throw error("Reached end of line while parsing extended word.");
|
||||
if (current == '`') break;
|
||||
buffer.append(current);
|
||||
current = next();
|
||||
}
|
||||
@ -252,7 +252,6 @@ public final class Lexer {
|
||||
clearBuffer();
|
||||
char current = peek(0);
|
||||
while (true) {
|
||||
if (current == '\0') throw error("Reached end of file while parsing text string.");
|
||||
if (current == '\\') {
|
||||
current = next();
|
||||
switch (current) {
|
||||
@ -288,6 +287,7 @@ public final class Lexer {
|
||||
continue;
|
||||
}
|
||||
if (current == '"') break;
|
||||
if (current == '\0') throw error("Reached end of file while parsing text string.");
|
||||
buffer.append(current);
|
||||
current = next();
|
||||
}
|
||||
@ -306,8 +306,8 @@ public final class Lexer {
|
||||
private void tokenizeMultilineComment() {
|
||||
char current = peek(0);
|
||||
while (true) {
|
||||
if (current == '\0') throw error("Reached end of file while parsing multiline comment");
|
||||
if (current == '*' && peek(1) == '/') break;
|
||||
if (current == '\0') throw error("Reached end of file while parsing multiline comment");
|
||||
current = next();
|
||||
}
|
||||
next(); // *
|
||||
|
@ -6,6 +6,7 @@ import com.annimon.ownlang.lib.StringValue;
|
||||
import com.annimon.ownlang.lib.UserDefinedFunction;
|
||||
import com.annimon.ownlang.parser.ast.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -27,9 +28,9 @@ public final class Parser {
|
||||
|
||||
private static final Token EOF = new Token(TokenType.EOF, "", -1, -1);
|
||||
|
||||
private static final Map<TokenType, BinaryExpression.Operator> assignOperator;
|
||||
private static final EnumMap<TokenType, BinaryExpression.Operator> assignOperator;
|
||||
static {
|
||||
assignOperator = new HashMap<>(BinaryExpression.Operator.values().length + 1);
|
||||
assignOperator = new EnumMap(TokenType.class);
|
||||
assignOperator.put(TokenType.EQ, null);
|
||||
assignOperator.put(TokenType.PLUSEQ, BinaryExpression.Operator.ADD);
|
||||
assignOperator.put(TokenType.MINUSEQ, BinaryExpression.Operator.SUBTRACT);
|
||||
|
Loading…
Reference in New Issue
Block a user