0

I have a very simple sweet.js file I'm trying to compile:

macro @ {
    rule {
        $exp
    }=>{
        + $exp +
    }
}

...using this command:

sjs -o out.js my_file.js

But nothing is getting output; the out.js file is created, but it doesn't contain anything. At first I thought it may be any issue with the sweet.js file itself, but when I test it using the sweet.js online editor, it works as expected.

Am I not using the 'sjs' command properly? Is there something else I'm overlooking?

Tomalak
  • 332,285
  • 67
  • 532
  • 628
Bryan Green
  • 441
  • 3
  • 18
  • 1
    because you are only compiling a macro? try using that macro. – Fabricator Jan 09 '16 at 18:58
  • The sweet.js compiler is supposed to expand all macros into Javascript code. – Bryan Green Jan 09 '16 at 19:11
  • macros only exist in sweetjs. they are syntactic sugar for creating javascript code. you have to use it like `@ (123)` – Fabricator Jan 09 '16 at 19:20
  • Then what is the purpose of the sjs compiler? All the tutorials I've seen so far have you writing macros (similar to mine above), and then running them through the compiler to output JS code. – Bryan Green Jan 09 '16 at 19:56

1 Answers1

1

I was able to compile after adding some lines of code outside of the macro definition:

macro @ {
rule {
    $exp
}=>{
    + $exp +
   }
}

var msg = "Hello";
console.log("message is: " @msg ".");

I misunderstood the documentation I've been reading, and thought just the macro code itself could be compiled into a JavaScript file, but the compiler spits out a JavaScript file based on the defined macro and the code that utilizes the defined macro.

Bryan Green
  • 441
  • 3
  • 18