diff options
author | alon@honor <none@none> | 2010-09-04 20:22:35 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-09-04 20:22:35 -0700 |
commit | f44ff320263db6a465a09798168b4220e7333f83 (patch) | |
tree | a4d5ea4823a6c9b763b12107fbc765583c1845ad /src/parser.js | |
parent | 1715e6c9b2819fa2ca9b8a0031ae2c93781af20f (diff) |
better support for exceptions and pointers to multiparameter functions
Diffstat (limited to 'src/parser.js')
-rw-r--r-- | src/parser.js | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/parser.js b/src/parser.js index 0b6b3dad..6eb368b5 100644 --- a/src/parser.js +++ b/src/parser.js @@ -45,7 +45,7 @@ function pointingLevels(type) { function toNiceIdent(ident) { if (parseFloat(ident) == ident) return ident; - return ident.replace(/[" \.@%]/g, '_'); + return ident.replace(/[" \.@%:<>,\*]/g, '_'); } function isNumberType(type) { @@ -86,7 +86,8 @@ function isFunctionDef(token) { if (nonPointing == '(...)') return true; if (!token.item) return false; var fail = false; - token.item[0].tokens.forEach(function(subtoken) { + splitTokenList(token.item[0].tokens).forEach(function(segment) { + var subtoken = segment[0]; fail = fail || !isType(subtoken.text); }); return !fail; @@ -121,6 +122,7 @@ function compareTokens(a, b) { return ret; } +// Splits a list of tokens separated by commas. For example, a list of arguments in a function call function splitTokenList(tokens) { if (tokens.length == 0) return []; if (tokens.slice(-1)[0].text != ',') tokens.push({text:','}); @@ -2240,9 +2242,13 @@ function JSify(data) { return ret + ';'; }); makeFuncLineZyme('invoke', function(item) { - var ret = 'try { '; - ret += makeFunctionCall(item.ident, item.params); - ret += '; __label__ = ' + getLabelId(item.toLabel) + '; } catch(e) { __label__ = ' + getLabelId(item.unwindLabel) + '; }; break;'; + // Wrapping in a function lets us easily return values if we are + // in an assignment + var ret = '(function() { try { return ' + + makeFunctionCall(item.ident, item.params) + '; ' + + '__THREW__ = false } catch(e) { ' + + '__THREW__ = true; ' + + '} })(); if (!__THREW__) { ' + makeBranch(item.toLabel) + ' } else { ' + makeBranch(item.unwindLabel) + ' }'; return ret; }); makeFuncLineZyme('load', function(item) { |