In EcmaScript 3, Array.prototype.push
is exophoric so it can
be call
ed on any object by design —
not just Array
s.
So o = {}, [].push.call(o, 'a', 'b');
is equivalent to
o = { 0: 'a', 1: 'b', length: 2 };
.
match("@clazz.prototype.@methodName = function (@params*) { @body*; }", node, bindings, scope)will check whether node looks like a javascript method assignment, and if successful, will put entries into {@code bindings} that map "quasi-holes" like {@code "clazz"} to the corresponding descendents of node.
Quasiliterals can also be used to generate parse trees as in
substV("cajita.def(@clazz, @baseClazz, @methods, @statics)", "clazz", ..., "baseClazz", ..., "methods", ..., "statics", ...);
QuasiSyntax | Match | Substitute |
---|---|---|
@foo | Matches any node and binds it to the name foo. If there is an existing binding for foo, the match only passes if the candidate binding and the original are deeply equal. | Emits any binding for foo, or fails to substitute if no such binding exists. |
@foo___ | Matches a reference or identifier with the suffix ___, binding the name foo to a reference or identifier with the ___ suffix removed. | If foo is bound to a reference or identifier, emits a reference or identifier with the ___ suffix added. |
@foo? | Like @foo but if no match is available, succeeds without creating a binding or consuming any input. | Like @foo but if no binding is available does not fail. |
@foo* | Like foo but will match as many nodes as possible on the input grouping them into a ParseTreeNodeContainer which is bound to foo. | Emits all of the children of the binding of foo if it exists, succeeding either way. |
@foo+ | Like @foo* but there must be at least one matching input for the match to succeed. | Like @foo* but there must be a binding and it must have a non-empty child list for the substitution to succeed. |
'use foo,bar'; | If it appears where a UseSubsetDirective is allowed, matches any UseSubsetDirective that contains a super-set of the subsets named. | Emits a UseSubsetDirective with only the subsets named. |
'@foo' | Matches a string literal whose content is a valid JS identifier. Binds foo to an Identifier with that identifier. | If foo is bound to an Identifier or a Reference emits a StringLiteral whose content is the identifier name. Fails to substitute otherwise. |