Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Oct 22, 2024
1 parent 8cc2319 commit 9b0a1ff
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/main/java/org/perlonjava/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public Node parseCoreOperator(LexerToken token) {
case "sprintf":
// Handle 'join' keyword as a Binary operator with a RuntimeList operand
operand = ListParser.parseZeroOrMoreList(this, 1, false, true, false, false);
separator = ((ListNode) operand).elements.remove(0);
separator = ((ListNode) operand).elements.removeFirst();
return new BinaryOperatorNode(token.text, separator, operand, currentIndex);
case "sort":
case "map":
Expand Down Expand Up @@ -630,14 +630,14 @@ public Node parsePrimary() {

switch (token.type) {
case IDENTIFIER:
LexerToken nextToken = TokenUtils.peek(this);
if (nextToken.text.equals("=>")) {
String nextTokenText = TokenUtils.peek(this).text;
if (nextTokenText.equals("=>")) {
// Autoquote
return new StringNode(token.text, tokenIndex);
}

// Try to parse a builtin operation; backtrack if it fails
if (token.text.equals("CORE") && nextToken.text.equals("::")) {
if (token.text.equals("CORE") && nextTokenText.equals("::")) {
TokenUtils.consume(this); // "::"
token = TokenUtils.consume(this); // operator
}
Expand Down Expand Up @@ -703,7 +703,7 @@ public Node parsePrimary() {
return new OperatorNode(token.text, operand, tokenIndex);
case "-":
// Handle unary operators like `- -d`
nextToken = tokens.get(tokenIndex);
LexerToken nextToken = tokens.get(tokenIndex);
if (nextToken.type == LexerTokenType.IDENTIFIER && nextToken.text.length() == 1) {
// Handle `-d`
String operator = "-" + nextToken.text;
Expand Down Expand Up @@ -819,8 +819,7 @@ public Node parseVariable(String sigil) {
}

// Create a Variable node
Node opNode = new OperatorNode(sigil, new IdentifierNode(varName, tokenIndex), tokenIndex);
return opNode;
return new OperatorNode(sigil, new IdentifierNode(varName, tokenIndex), tokenIndex);
} else if (TokenUtils.peek(this).text.equals("{")) {
// Handle curly brackets to parse a nested expression `${v}`
TokenUtils.consume(this); // Consume the '{'
Expand Down

0 comments on commit 9b0a1ff

Please sign in to comment.