Questions tagged [sweet.js]

Sweet.js is a Mozilla Library for adding Macro Compilation to JavaScript

Sweet.js brings the hygienic macros of languages like Scheme and Rust to JavaScript. Macros allow you to alter the syntax of JavaScript and craft the language you've always wanted.

To get a better sense of what macros can do, check out some example macros or play around with macros in the online editor.

68 questions
0
votes
1 answer

Does CodeKit support the sweet.js compilation?

I am just wondering if CodeKit supports the compilation of Sweet.js files ?
ceth
  • 44,198
  • 62
  • 180
  • 289
0
votes
1 answer

Is it possible to make a sweet.js macro `m` expand to the symbol `m`?

Suppose there's a function somewhere called m, which is invoked like this //foo.js m("foo") I have a sweet.js macro that defines a macro called m which is meant to take foo.js and expand m (basically to run the function at compile time) In some…
LeoHorie
  • 1,320
  • 11
  • 11
0
votes
1 answer

Why are case macros not nesting?

Given this sweet.js macro macro m { case { _ ( $a, $b ) } => { return #{$a + $b}; } case { _ ( $a ) } => { return #{$a}; } case { _ } => { return #{no}; } } export m; And this source code: m(1,…
LeoHorie
  • 1,320
  • 11
  • 11
0
votes
1 answer

access parents variable in Sweet.js

I'm creating a new object orientation system and I need to access the variables of the parent of the macro. I have the following: macro module { rule { $i:ident { $e ... } } => { var $i = { $e ... } } } macro fn…
Marcelo Camargo
  • 2,240
  • 2
  • 22
  • 51
0
votes
0 answers

Nested macros in Sweet.js

How can I do nested macros using sweet JS? macro a { rule { { $e:expr } } => { } } macro b { rule { test } => { } } In this case, b isn't an expression. Can I set that $e can also be a b macro, being possible to do a b test instead of a, b…
Marcelo Camargo
  • 2,240
  • 2
  • 22
  • 51
0
votes
1 answer

Capture a function call's arguments with sweet.js

I'm trying to write a rule for capturing the expression and arguments of a function call with sweet.js. Here's my current macro (that fails to match): macro foo { rule { ( $fn:expr ($args ...) ) } => { $fn("stuff", $args ...)…
SimpleJ
  • 13,812
  • 13
  • 53
  • 93
0
votes
1 answer

How to match colon in sweet.js?

macro m { rule { $a: $b } => { $a($b) } } m 1: 2 I think sweetjs is interpreting the colon as a marker for match class. If so, how do I escape that make make sweetjs match it as it is? This seems to work just fine though macro m { …
ming_codes
  • 2,870
  • 25
  • 24
0
votes
2 answers

sweetjs adding : ''

I am trying to write a macro with sweetjs to go from {a,b,c} to {a:'',b:'',c:''} basically I want to list the attributes of an object and create an empty prototype with that attributes. The rule I have written is macro basic { rule { { $x (,)…
user1544128
  • 583
  • 4
  • 20
1 2 3 4
5