Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add operator for getting the path to the current file (M0) #127

Merged
merged 1 commit into from
Jan 1, 2025
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
14 changes: 10 additions & 4 deletions src/aya/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import aya.parser.tokens.BlockToken;
import aya.parser.tokens.CDictToken;
import aya.parser.tokens.CharToken;
import aya.parser.tokens.CurrentFileToken;
import aya.parser.tokens.DictToken;
import aya.parser.tokens.KeyVarToken;
import aya.parser.tokens.LambdaToken;
Expand Down Expand Up @@ -215,10 +216,15 @@ else if (in.peek() <= Ops.MAX_OP){

// Math Operators
else if (current == 'M') {
try {
tokens.add(new OperatorToken("" + in.next(), OperatorToken.MATH_OP, in.currentRef()));
} catch (EndOfInputError e) {
throw new SyntaxError("Expected op name after 'M'", in.currentRef());
if (in.peek() == '0') {
in.next(); // Skip 0
tokens.add(new CurrentFileToken(in.currentRef()));
} else {
try {
tokens.add(new OperatorToken("" + in.next(), OperatorToken.MATH_OP, in.currentRef()));
} catch (EndOfInputError e) {
throw new SyntaxError("Expected op name after 'M'", in.currentRef());
}
}
}

Expand Down
23 changes: 23 additions & 0 deletions src/aya/parser/tokens/CurrentFileToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package aya.parser.tokens;

import aya.exceptions.parser.ParserException;
import aya.instruction.Instruction;
import aya.instruction.StringLiteralInstruction;
import aya.parser.SourceStringRef;

public class CurrentFileToken extends StdToken {

public CurrentFileToken(SourceStringRef source) {
super(source.getSource().getFilename(), Token.STRING, source);
}

@Override
public Instruction getInstruction() throws ParserException {
return new StringLiteralInstruction(source, this.source.getSource().getFilename());
}

@Override
public String typeString() {
return "constant_current_file";
}
}
Loading