Releases: sweet-js/sweet-core
more es6 support
Updated parser support for ES6 (class
now works).
0.7.3
local expand
The experimental function localExpand
is now available to case macros. Local expand allows you to force expansion of macros inside of another macro.
macro PI { rule {} => { 3.14159 }}
macro ex {
case { { $toks ... } } => {
var expanded = localExpand(#{$toks ...});
assert(unwrapSyntax(expanded[0]) === 3.14159)
return expanded;
}
}
ex { PI }
From PR #310.
case and rule interleaving
Case and rule macros can now be interleaved:
macro m {
rule { ( $toks ... ) } => { /* handle () as a rule */ }
case {_ { $toksn... } } => { /* handle {} as a case */ }
}
From PR #428
0.7.2
sweet.js v0.7.1
reader extensions
New Features
Reader Extensions! You can now change how sweet.js reads/lexes tokens. Documentation here
bug fixes
Sweet Dreams
New Features
New Documentation
The documentation for sweet.js has been moved from the home page to its own home here. Lots of changes including sections on features (like literal patterns, :invoke
, and the compiler API) that had not been documented yet.
Custom Operators #296
Full documentation is here. Allows you to create custom operators with their own precedence and associativity:
operator (^^) 14 right
{ $base, $exp } => #{ Math.pow($base, $exp) }
y + x ^^ 10 ^^ 100 - z
// expands to:
// y + Math.pow(x, Math.pow(10, 100)) - z;
Loading macros modules in node #295
Full documentation is here. The basic idea is you can now load macro modules in node (like using the -m
flag on the command line).
// load sweet.js as a library
var sweet = require('sweet.js');
// load all `export`ed macros in macros/str.sjs
sweet.loadMacro('./macros/str');
// test.sjs can use the macros defined in macros/str.sjs
require('./test.sjs');
Custom Pattern Classes #203
Full documentation here. Allows you to abstract pattern classes at a more declarative level than just using :invoke
directly. The syntax is very experimental at the moment so try it out but don't rely on it just yet.
// define the cond_clause pattern class
macroclass cond_clause {
pattern { $check:expr => $body:expr }
}
macro cond {
rule { $first:cond_clause $rest:cond_clause ... } => {
// sub-pattern variables in the custom class are
// referenced by concatenation
if ($first$check) {
$first$body
} $(else if ($rest$check) {
$rest$body
}) ...
}
}
cond
x < 3 => console.log("less than 3")
x == 3 => console.log("3")
x > 3 => console.log("greater than 3")
// expands to:
// if (x < 3) {
// console.log('less than 3');
// } else if (x == 3) {
// console.log('3');
// } else if (x > 3) {
// console.log('greater than 3');
// }
Changes
:invoke
is no longer recursive by default. If you want recursive behavior use :invokeRec
. :invokeOnce
no longer exists.
Bugs And Performance Fixes
Sweet Disposition
New feature!
You can now define custom pattern classes (like :expr
) with the new :invoke
/:invokeOnce
class which inserts the parametrized macro into the token stream before matching the pattern.
macro color {
rule { red } => { red }
rule { green } => { green }
rule { blue } => { blue }
}
macro colors_options {
rule { ($opt:invoke(color) ...) } => { ... }
}
// you can also use a shorthand that automatically inserts invoke:
macro colors_options {
rule { ($opt:color ...) } => { ... }
}
More details at #244.
Change:
When defining multi-token macros you must now surround the tokens with parens to prevent ambiguity:
macro (number?) {
rule { $x } => {
typeof $x === "number";
}
}
See #258 for discussion.
Bugs squashed: #231, #256, #259, #257, #258, #260, #264, #272, #274, #275
bugfixes
Bugs squashed:
#206, #209, #208, #211, #220, #219, #229, #230, #247, #234, #238, #252, #253.
Two mini features have been added. One is #237, a shorthand form of withSyntax
:
macro m {
case {_ () } => {
return withSyntax ($x = [makeValue(42, #{here})]) #{ $x }
}
}
And the other #227 sets up the resolve
path correctly letting you expand a macro into a call to resolve
.