diff --git a/src/aya/parser/Parser.java b/src/aya/parser/Parser.java index bef6e17b..ebd1aeaa 100644 --- a/src/aya/parser/Parser.java +++ b/src/aya/parser/Parser.java @@ -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; @@ -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()); + } } } diff --git a/src/aya/parser/tokens/CurrentFileToken.java b/src/aya/parser/tokens/CurrentFileToken.java new file mode 100644 index 00000000..e729941b --- /dev/null +++ b/src/aya/parser/tokens/CurrentFileToken.java @@ -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"; + } +}