mirror of https://github.com/adamdruppe/arsd.git
fix more bugs omg
This commit is contained in:
parent
5a25404ede
commit
f924d9b42a
31
script.d
31
script.d
|
|
@ -2714,6 +2714,10 @@ Expression parsePart(MyTokenStreamHere)(ref MyTokenStreamHere tokens) {
|
||||||
auto parenthetical = new ParentheticalExpression(parseExpression(tokens));
|
auto parenthetical = new ParentheticalExpression(parseExpression(tokens));
|
||||||
tokens.requireNextToken(ScriptToken.Type.symbol, ")");
|
tokens.requireNextToken(ScriptToken.Type.symbol, ")");
|
||||||
|
|
||||||
|
if(tokens.peekNextToken(ScriptToken.Type.symbol, "(")) {
|
||||||
|
// we have a function call, e.g. (test)()
|
||||||
|
return parseFunctionCall(tokens, parenthetical);
|
||||||
|
} else
|
||||||
return parenthetical;
|
return parenthetical;
|
||||||
case "[":
|
case "[":
|
||||||
// array literal
|
// array literal
|
||||||
|
|
@ -2883,6 +2887,9 @@ Expression parseFunctionCall(MyTokenStreamHere)(ref MyTokenStreamHere tokens, Ex
|
||||||
assert(!tokens.empty);
|
assert(!tokens.empty);
|
||||||
auto peek = tokens.front;
|
auto peek = tokens.front;
|
||||||
auto exp = new CallExpression(ScriptLocation(peek.scriptFilename, peek.lineNumber), e);
|
auto exp = new CallExpression(ScriptLocation(peek.scriptFilename, peek.lineNumber), e);
|
||||||
|
|
||||||
|
assert(peek.str == "(");
|
||||||
|
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
if(tokens.empty)
|
if(tokens.empty)
|
||||||
throw new ScriptCompileException("unexpected end of file when parsing call expression", peek.scriptFilename, peek.lineNumber);
|
throw new ScriptCompileException("unexpected end of file when parsing call expression", peek.scriptFilename, peek.lineNumber);
|
||||||
|
|
@ -3030,17 +3037,18 @@ Expression parseExpression(MyTokenStreamHere)(ref MyTokenStreamHere tokens, bool
|
||||||
|
|
||||||
auto e = new OpAssignExpression("~", new VariableExpression(i), literal);
|
auto e = new OpAssignExpression("~", new VariableExpression(i), literal);
|
||||||
ret = e;
|
ret = e;
|
||||||
} else if(tokens.peekNextToken(ScriptToken.Type.symbol, "(")) {
|
}/+ else if(tokens.peekNextToken(ScriptToken.Type.symbol, "(")) {
|
||||||
auto start = tokens.front;
|
auto start = tokens.front;
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
auto parenthetical = new ParentheticalExpression(parseExpression(tokens));
|
auto parenthetical = new ParentheticalExpression(parseExpression(tokens));
|
||||||
|
|
||||||
tokens.requireNextToken(ScriptToken.Type.symbol, ")");
|
tokens.requireNextToken(ScriptToken.Type.symbol, ")");
|
||||||
if(tokens.peekNextToken(ScriptToken.Type.symbol, "(")) {
|
if(tokens.peekNextToken(ScriptToken.Type.symbol, "(")) {
|
||||||
// we have a function call, e.g. (test)()
|
// we have a function call, e.g. (test)()
|
||||||
ret = parseFunctionCall(tokens, parenthetical);
|
ret = parseFunctionCall(tokens, parenthetical);
|
||||||
} else
|
} else
|
||||||
ret = parenthetical;
|
ret = parenthetical;
|
||||||
} else if(tokens.peekNextToken(ScriptToken.Type.keyword, "new")) {
|
}+/ else if(tokens.peekNextToken(ScriptToken.Type.keyword, "new")) {
|
||||||
auto start = tokens.front;
|
auto start = tokens.front;
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
|
|
||||||
|
|
@ -3193,7 +3201,9 @@ Expression parseExpression(MyTokenStreamHere)(ref MyTokenStreamHere tokens, bool
|
||||||
} else if(tokens.peekNextToken(ScriptToken.Type.keyword, "if")) {
|
} else if(tokens.peekNextToken(ScriptToken.Type.keyword, "if")) {
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
auto e = new IfExpression();
|
auto e = new IfExpression();
|
||||||
|
tokens.requireNextToken(ScriptToken.Type.symbol, "(");
|
||||||
e.condition = parseExpression(tokens);
|
e.condition = parseExpression(tokens);
|
||||||
|
tokens.requireNextToken(ScriptToken.Type.symbol, ")");
|
||||||
e.ifTrue = parseExpression(tokens);
|
e.ifTrue = parseExpression(tokens);
|
||||||
if(tokens.peekNextToken(ScriptToken.Type.symbol, ";")) {
|
if(tokens.peekNextToken(ScriptToken.Type.symbol, ";")) {
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
|
|
@ -3301,8 +3311,13 @@ Expression parseExpression(MyTokenStreamHere)(ref MyTokenStreamHere tokens, bool
|
||||||
} else if(tokens.peekNextToken(ScriptToken.Type.keyword, "while")) {
|
} else if(tokens.peekNextToken(ScriptToken.Type.keyword, "while")) {
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
auto e = new ForExpression();
|
auto e = new ForExpression();
|
||||||
|
|
||||||
|
tokens.requireNextToken(ScriptToken.Type.symbol, "(");
|
||||||
e.condition = parseExpression(tokens);
|
e.condition = parseExpression(tokens);
|
||||||
|
tokens.requireNextToken(ScriptToken.Type.symbol, ")");
|
||||||
|
|
||||||
e.loopBody = parseExpression(tokens);
|
e.loopBody = parseExpression(tokens);
|
||||||
|
|
||||||
ret = e;
|
ret = e;
|
||||||
expectedEnd = "";
|
expectedEnd = "";
|
||||||
} else if(tokens.peekNextToken(ScriptToken.Type.keyword, "break") || tokens.peekNextToken(ScriptToken.Type.keyword, "continue")) {
|
} else if(tokens.peekNextToken(ScriptToken.Type.keyword, "break") || tokens.peekNextToken(ScriptToken.Type.keyword, "continue")) {
|
||||||
|
|
@ -3613,8 +3628,6 @@ Expression parseStatement(MyTokenStreamHere)(ref MyTokenStreamHere tokens, strin
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME someday this should work, my parser is so bad
|
|
||||||
// until then put parens around your == stuff.
|
|
||||||
unittest {
|
unittest {
|
||||||
interpret(q{
|
interpret(q{
|
||||||
var a = 5;
|
var a = 5;
|
||||||
|
|
@ -3622,7 +3635,6 @@ unittest {
|
||||||
assert(a == 5 || b);
|
assert(a == 5 || b);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
version(none)
|
|
||||||
unittest {
|
unittest {
|
||||||
interpret(q{
|
interpret(q{
|
||||||
var a = 5;
|
var a = 5;
|
||||||
|
|
@ -3638,6 +3650,15 @@ unittest {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unittest {
|
||||||
|
interpret(q{
|
||||||
|
var a = 5;
|
||||||
|
while(a > 0) { a-=1; }
|
||||||
|
|
||||||
|
if(a) { a } else { a }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct CompoundStatementRange(MyTokenStreamHere) {
|
struct CompoundStatementRange(MyTokenStreamHere) {
|
||||||
// FIXME: if MyTokenStreamHere is not a class, this fails!
|
// FIXME: if MyTokenStreamHere is not a class, this fails!
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue