Skip to content

Commit

Permalink
support a(b) as synonym for (a b)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbr committed Apr 30, 2016
1 parent 1e0d87e commit 7852415
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 123 deletions.
106 changes: 60 additions & 46 deletions lib/browser.js
Expand Up @@ -816,15 +816,16 @@ this.sibilant = (function() {
"whitespace": "\\s+",
"ignored": "."
};
parser.tokenPrecedence = [ "comment", "string", "number", "dots", "tick", "hat", "at", "special", "literal", "argPlaceholder", "otherChar", "openExpression", "closeExpression", "newline", "whitespace", "ignored" ];
parser.tokens.head = ("(-?[*.$a-zA-Z_\\|><=!\\+\\/\\*-]" + "[/*.a-zA-Z0-9-_\\|><=!\\+\\/\\*-]*" + "(\\?|!)?\\()");
parser.tokenPrecedence = [ "comment", "string", "number", "dots", "tick", "hat", "at", "special", "head", "literal", "argPlaceholder", "otherChar", "openExpression", "closeExpression", "newline", "whitespace", "ignored" ];
parser.orderedRegexes = parser.tokenPrecedence.map((function(x) {
/* src/parser.sibilant:39:23 */
/* src/parser.sibilant:43:23 */

return mergeInto((new RegExp(("^" + parser.tokens[x]), undefined)), { name: x });
}));
var orderedRegexes = parser.orderedRegexes;
parser.parse = (function parser$parse$(string, context) {
/* parser.parse src/parser.sibilant:44:0 */
/* parser.parse src/parser.sibilant:48:0 */

context = (typeof context !== "undefined") ? context : {
position: 0,
Expand All @@ -841,7 +842,7 @@ this.sibilant = (function() {
while (match) {
while$7 = (function() {
detect(orderedRegexes, (function(r) {
/* src/parser.sibilant:55:20 */
/* src/parser.sibilant:59:20 */

regexName = r.name;
return match = r.exec(remainingInput);
Expand Down Expand Up @@ -888,8 +889,7 @@ this.sibilant = (function() {
return context.stack;
});
var parse = parser.parse;
var restructurers = { },
acceptablePairs = {
var acceptablePairs = {
"(": ")",
"[": "]",
"{": "}"
Expand All @@ -900,7 +900,7 @@ this.sibilant = (function() {
"{": "brace"
};
var restructure = (function restructure$(input) {
/* restructure src/restructurer.sibilant:7:0 */
/* restructure src/restructurer.sibilant:6:0 */

var output = {
type: "root",
Expand All @@ -913,15 +913,10 @@ this.sibilant = (function() {
parseStack: [ output ],
output: output,
input: input,
ignoredTokens: [],
ignoredNodes: [],
specials: 0
};
inject(context, input, (function(context, token, index) {
/* src/restructurer.sibilant:20:13 */

var restructurer = (restructurers[token.type] || restructurers.default);
return restructurer(token, context, index);
}));
inject(context, input, restructurers);
(function() {
if (!(1 === context.parseStack.length)) {
var unclosedNode = context.parseStack[0];
Expand All @@ -930,21 +925,40 @@ this.sibilant = (function() {
}).call(this);
return output;
});
var restructurers = (function restructurers$(context, node) {
/* restructurers src/restructurer.sibilant:29:0 */

var restructurer = (restructurers[node.type] || restructurers.default);
return restructurer(node, context);
});
sibilant.restructure = restructure;
restructurers.openExpression = (function restructurers$openExpression$(token, context) {
/* restructurers.open-expression src/restructurer.sibilant:35:0 */
restructurers.head = (function restructurers$head$(node, context) {
/* restructurers.head src/restructurer.sibilant:35:0 */

var head = mergeWith(node, {
token: node.token.slice(0, -1),
type: "literal"
}),
expression = mergeWith(node, {
token: "(",
type: "openExpression"
});
return restructurers(restructurers(context, expression), head);
});
restructurers.openExpression = (function restructurers$openExpression$(node, context) {
/* restructurers.open-expression src/restructurer.sibilant:44:42 */

var first = context.parseStack[0];
token.contents = [];
token.type = bracketTypes[token.token];
acceptIgnoredTokens(token, context);
acceptSpecials(token, context);
first.contents.push(token);
context.parseStack.unshift(token);
node.contents = [];
node.type = bracketTypes[node.token];
acceptIgnoredNodes(node, context);
acceptSpecials(node, context);
first.contents.push(node);
context.parseStack.unshift(node);
return context;
});
restructurers.closeExpression = (function restructurers$closeExpression$(node, context, index) {
/* restructurers.close-expression src/restructurer.sibilant:47:0 */
restructurers.closeExpression = (function restructurers$closeExpression$(node, context) {
/* restructurers.close-expression src/restructurer.sibilant:56:0 */

var first = context.parseStack[0];
(function() {
Expand All @@ -959,8 +973,8 @@ this.sibilant = (function() {
}).call(this);
first.end = node.end;
first.closed = true;
first.closingIgnored = context.ignoredTokens;
context.ignoredTokens = [];
first.closingIgnored = context.ignoredNodes;
context.ignoredNodes = [];
context.parseStack.shift();
closeSpecials(first, context);
(function() {
Expand All @@ -971,32 +985,32 @@ this.sibilant = (function() {
return context;
});
var openSpecial = (function openSpecial$(node, context) {
/* open-special src/restructurer.sibilant:72:0 */
/* open-special src/restructurer.sibilant:81:0 */

((context.specials)++);
acceptIgnoredTokens(node, context);
acceptIgnoredNodes(node, context);
var first = context.parseStack[0];
node.contents = [];
first.contents.push(node);
context.parseStack.unshift(node);
return context;
});
var acceptSpecials = (function acceptSpecials$(node, context) {
/* accept-specials src/restructurer.sibilant:85:0 */
/* accept-specials src/restructurer.sibilant:94:0 */

node.specials = context.specials;
context.specials = 0;
return context;
});
var acceptIgnoredTokens = (function acceptIgnoredTokens$(node, context) {
/* accept-ignored-tokens src/restructurer.sibilant:90:0 */
var acceptIgnoredNodes = (function acceptIgnoredNodes$(node, context) {
/* accept-ignored-nodes src/restructurer.sibilant:99:0 */

node.precedingIgnored = context.ignoredTokens;
context.ignoredTokens = [];
node.precedingIgnored = context.ignoredNodes;
context.ignoredNodes = [];
return context;
});
var closeSpecials = (function closeSpecials$(node, context) {
/* close-specials src/restructurer.sibilant:95:0 */
/* close-specials src/restructurer.sibilant:104:0 */

(function() {
if (node.specials > 0) {
Expand All @@ -1007,29 +1021,29 @@ this.sibilant = (function() {
}).call(this);
return context;
});
var accumulateIgnoredToken = (function accumulateIgnoredToken$(token, context, index) {
/* accumulate-ignored-token src/restructurer.sibilant:103:0 */
var accumulateIgnoredNode = (function accumulateIgnoredNode$(node, context) {
/* accumulate-ignored-node src/restructurer.sibilant:112:0 */

context.ignoredTokens.push(token);
context.ignoredNodes.push(node);
return context;
});
[ "hat", "dots", "tick", "at" ].forEach((function(special) {
/* src/restructurer.sibilant:107:0 */
/* src/restructurer.sibilant:116:0 */

return restructurers[special] = openSpecial;
}));
[ "whitespace", "newline", "ignored", "comment" ].forEach((function(ignored) {
/* src/restructurer.sibilant:110:0 */
/* src/restructurer.sibilant:119:0 */

return restructurers[ignored] = accumulateIgnoredToken;
return restructurers[ignored] = accumulateIgnoredNode;
}));
restructurers.default = (function restructurers$default$(token, context, index) {
/* restructurers.default src/restructurer.sibilant:113:0 */
restructurers.default = (function restructurers$default$(node, context) {
/* restructurers.default src/restructurer.sibilant:122:0 */

acceptSpecials(token, context);
acceptIgnoredTokens(token, context);
context.parseStack[0].contents.push(token);
return closeSpecials(token, context);
acceptSpecials(node, context);
acceptIgnoredNodes(node, context);
context.parseStack[0].contents.push(node);
return closeSpecials(node, context);
});
var coreNamespace = { },
macroNamespaces = { core: coreNamespace };
Expand Down

0 comments on commit 7852415

Please sign in to comment.