Skip to content

Releases: sweet-js/sweet-core

more es6 support

09 Feb 20:59
Compare
Choose a tag to compare

Updated parser support for ES6 (class now works).

0.7.3

05 Jan 23:23
Compare
Choose a tag to compare
  • editor cleanup #439
  • localExpand #310
  • case and rule interleaving #428
  • stack overflow bugfix #309

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

26 Oct 22:21
Compare
Choose a tag to compare

Bugfixes:

sweet.js v0.7.1

19 Aug 19:58
Compare
Choose a tag to compare

reader extensions

01 Jul 17:07
Compare
Choose a tag to compare

New Features

Reader Extensions! You can now change how sweet.js reads/lexes tokens. Documentation here

bug fixes

23 Jun 18:54
Compare
Choose a tag to compare

Mostly just bug fixes with a couple of minor changes.

Changes

  • added --version flag to sjs #320
  • you can now name pattern groups. See the docs #325
  • the experimental macroclass syntax has been cleaned up a little. #350

Bugs

Dev

You can now fuzz sweet.js with grunt fuzz.

Sweet Dreams

04 May 23:47
Compare
Choose a tag to compare

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

  • #232/#303 pref for resolve
  • #291 restrict positions of macro
  • #301/#283 reader edge cases
  • #308 yield/new are now operators
  • #306 multi token export now works

Sweet Disposition

10 Mar 03:40
Compare
Choose a tag to compare

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

14 Feb 00:04
Compare
Choose a tag to compare

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.

bugfixes

17 Jan 01:35
Compare
Choose a tag to compare

Bunch of minor bug fixes. Also a new command line flag --readable-names which cleans up the renamings in output code.