mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-11 23:34:04 +09:00
basic: actually the parser was correct
This commit is contained in:
@@ -2062,15 +2062,18 @@ bF._parseExpr = function(lnum, tokens, states, recDepth, ifMode) {
|
|||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
// ## case for:
|
// ## case for:
|
||||||
|
// (* at this point, if OP is found in paren-level 0, skip function_call *)
|
||||||
// | function_call ;
|
// | function_call ;
|
||||||
try {
|
if (topmostOp === undefined) {
|
||||||
bF.parserPrintdbgline('E', "Trying Function Call...", lnum, recDepth);
|
try {
|
||||||
return bF._parseFunctionCall(lnum, tokens, states, recDepth + 1);
|
bF.parserPrintdbgline('E', "Trying Function Call...", lnum, recDepth);
|
||||||
}
|
return bF._parseFunctionCall(lnum, tokens, states, recDepth + 1);
|
||||||
// if ParserError is raised, continue to apply other rules
|
}
|
||||||
catch (e) {
|
// if ParserError is raised, continue to apply other rules
|
||||||
bF.parserPrintdbgline('E', 'It was NOT!', lnum, recDepth);
|
catch (e) {
|
||||||
if (!(e instanceof ParserError)) throw e;
|
bF.parserPrintdbgline('E', 'It was NOT!', lnum, recDepth);
|
||||||
|
if (!(e instanceof ParserError)) throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
@@ -2245,14 +2248,17 @@ bF._parseFunctionCall = function(lnum, tokens, states, recDepth) {
|
|||||||
|
|
||||||
// unmatched brackets, duh!
|
// unmatched brackets, duh!
|
||||||
if (parenDepth != 0) throw lang.syntaxfehler(lnum, lang.unmatchedBrackets);
|
if (parenDepth != 0) throw lang.syntaxfehler(lnum, lang.unmatchedBrackets);
|
||||||
let parenUsed = (parenStart == 1 && parenEnd == states.length - 1);
|
let parenUsed = (parenStart == 1);
|
||||||
|
// && parenEnd == tokens.length - 1);
|
||||||
|
// if starting paren is found, just use it
|
||||||
|
// this prevents "RND(~~)*K" to be parsed as [RND, (~~)*K]
|
||||||
|
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
// ## case for:
|
// ## case for:
|
||||||
// ident , "(" , [expr , {argsep , expr} , [argsep]] , ")"
|
// ident , "(" , [expr , {argsep , expr} , [argsep]] , ")"
|
||||||
// | ident , expr , {argsep , expr} , [argsep] ;
|
// | ident , expr , {argsep , expr} , [argsep] ;
|
||||||
bF.parserPrintdbgline(String.fromCharCode(0x192), 'Function Call', lnum, recDepth);
|
bF.parserPrintdbgline(String.fromCharCode(0x192), `Function Call (parenUsed: ${parenUsed})`, lnum, recDepth);
|
||||||
|
|
||||||
let treeHead = new BasicAST();
|
let treeHead = new BasicAST();
|
||||||
treeHead.astLnum = lnum;
|
treeHead.astLnum = lnum;
|
||||||
@@ -2265,10 +2271,10 @@ bF._parseFunctionCall = function(lnum, tokens, states, recDepth) {
|
|||||||
// 1 6 9 12
|
// 1 6 9 12
|
||||||
let argStartPos = [1 + (parenUsed)].concat(argSeps.map(k => k+1));
|
let argStartPos = [1 + (parenUsed)].concat(argSeps.map(k => k+1));
|
||||||
// [1,5) [6,8) [9,11) [12,end)
|
// [1,5) [6,8) [9,11) [12,end)
|
||||||
let argPos = argStartPos.map((s,i) => {return{start:s, end:(argSeps[i] || tokens.length - (parenUsed))}}); // use end of token position as separator position
|
let argPos = argStartPos.map((s,i) => {return{start:s, end:(argSeps[i] || (parenUsed) ? parenEnd : tokens.length )}}); // use end of token position as separator position
|
||||||
|
|
||||||
// check for trailing separator
|
// check for trailing separator
|
||||||
let hasTrailingSep = (states[states.length - 1 - (parenUsed)] == "sep");
|
let hasTrailingSep = (states[((parenUsed) ? parenEnd : states.length) - 1] == "sep");
|
||||||
// exclude last separator from recursion if input tokens has trailing separator
|
// exclude last separator from recursion if input tokens has trailing separator
|
||||||
if (hasTrailingSep) argPos.pop();
|
if (hasTrailingSep) argPos.pop();
|
||||||
|
|
||||||
@@ -2322,6 +2328,7 @@ bF._parseLit = function(lnum, tokens, states, recDepth) {
|
|||||||
return treeHead;
|
return treeHead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @return is defined in BasicAST
|
// @return is defined in BasicAST
|
||||||
let JStoBASICtype = function(object) {
|
let JStoBASICtype = function(object) {
|
||||||
if (typeof object === "boolean") return "bool";
|
if (typeof object === "boolean") return "bool";
|
||||||
|
|||||||
Reference in New Issue
Block a user