Skip to content

Commit b7c0baf

Browse files
committed
special literals
1 parent 5917616 commit b7c0baf

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

FEATURE_MATRIX.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
- [ ] **`require` operator**: The `require` operator is not yet implemented.
117117
- [ ] **`use` and `no` statements**: Module imports and version changes via `use` and `no` are missing.
118118
- [ ] **`__SUB__`**: The `__SUB__` special variable is not yet supported.
119-
- [ ] **Special literals**: `__FILE__`, `__LINE__` not yet supported.
119+
- [x] **Special literals**: `__FILE__`, `__LINE__`
120120
- [ ] **`BEGIN` block**: `BEGIN` blocks are missing.
121121
- [ ] **Labels**: Labels and their usage are not supported.
122122
- [ ] **Search for labels in call stack**: Label searching in the call stack is missing.

src/main/java/org/perlonjava/codegen/EmitterVisitor.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,6 @@ public void visit(OperatorNode node) throws Exception {
517517
listNode.accept(this);
518518
}
519519
return;
520-
case "__PACKAGE__":
521-
new StringNode(ctx.symbolTable.getCurrentPackage(), node.tokenIndex).accept(this);
522-
return;
523520
case "$":
524521
case "@":
525522
case "%":

src/main/java/org/perlonjava/parser/Parser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,12 @@ private Node parsePrimary() {
581581
return new StringNode(token.text, tokenIndex);
582582
}
583583
switch (token.text) {
584+
case "__LINE__":
585+
return new NumberNode(Integer.toString(ctx.errorUtil.getLineNumber(tokenIndex)), tokenIndex);
586+
case "__FILE__":
587+
return new StringNode(ctx.compilerOptions.fileName, tokenIndex);
584588
case "__PACKAGE__":
585-
// this takes no parameters
586-
return new OperatorNode(token.text, null, tokenIndex);
589+
return new StringNode(ctx.symbolTable.getCurrentPackage(), tokenIndex);
587590
case "not":
588591
// Handle 'not' keyword as a unary operator with an operand
589592
operand = parseExpression(getPrecedence(token.text) + 1);

0 commit comments

Comments
 (0)