Skip to content
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
20 changes: 10 additions & 10 deletions src/main/java/org/perlonjava/frontend/parser/OperatorParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -694,13 +694,22 @@ static OperatorNode parseStat(Parser parser, LexerToken token, int currentIndex)
paren = true;
}

if (nextToken.text.equals("_")) {
// Handle `stat _`
TokenUtils.consume(parser);
if (paren) {
TokenUtils.consume(parser, OPERATOR, ")");
}
return new OperatorNode(token.text,
new IdentifierNode("_", parser.tokenIndex), parser.tokenIndex);
}

// stat/lstat: bareword filehandle (typically ALLCAPS) should be treated as a typeglob.
// Consume it here, before generic expression parsing can turn it into a subroutine call.
if (nextToken.type == IDENTIFIER) {
String name = nextToken.text;
if (name.matches("^[A-Z_][A-Z0-9_]*$")) {
TokenUtils.consume(parser);
// autovivify filehandle and convert to globref
GlobalVariable.getGlobalIO(FileHandle.normalizeBarewordHandle(parser, name));
Node fh = FileHandle.parseBarewordHandle(parser, name);
Node operand = fh != null ? fh : new IdentifierNode(name, parser.tokenIndex);
Expand All @@ -710,15 +719,6 @@ static OperatorNode parseStat(Parser parser, LexerToken token, int currentIndex)
return new OperatorNode(token.text, operand, currentIndex);
}
}
if (nextToken.text.equals("_")) {
// Handle `stat _`
TokenUtils.consume(parser);
if (paren) {
TokenUtils.consume(parser, OPERATOR, ")");
}
return new OperatorNode(token.text,
new IdentifierNode("_", parser.tokenIndex), parser.tokenIndex);
}

// Parse optional single argument (or default to $_)
// If we've already consumed '(', we must parse a full expression up to ')'.
Expand Down
Loading