cirru-script

2019-09-13 admin

cirru-script是什么

什么是cirru-script,Generated JavaScript from Cirru Grammar

cirru-script使用教程帮助文档

CirruScript: a JavaScript generator in Cirru Grammar

Live Docs: http://script.cirru.org/

Join the chat at https://gitter.im/Cirru/cirru-script

Play with CirruScript by typing in here: http://repo.cirru.org/script/

The AST transformer of CirruScript is Scirpus https://github.com/Cirru/scirpus .

Usage

Here is a demo of calling compiler:

npm i --save cirru-script

script = require 'cirru-script'
code = "console.log :demo"
script.compile code

I use gulp-cirru-script to compile the code.

Command-line tool

By installing CirruScript at global, you’ll get command cirru-script(and crs for short):

npm i -g cirru-script

crs
# enter REPL
cirru-script>

crs a.cirru
# evaluates a file

File compiling and SourceMaps support might come in the future.

Syntax

-- "test assignment"

= a 1
= b :string
= c true
= d undefined
= e /^hello\sworld$

-- "test values"

console.log 1
console.log a b c

array 1 2 3
console.log $ object (:a 1) (:b :)
  :c $ array 1

-- "combine"

console.log $ array 1 2 3

= e $ array 1 2
= f $ object
  :a 1
  :c :nothing

... gulp
  src :src/**/*.cirru (object (:base :src))
  pipe $ script (object (:dest :../lib))
  pipe $ rename (object (:extname :.js))
  pipe $ gulp.dest :./lib

> 2 1

+ 1 2 3

and (> 2 1) true

not a
not (+ a 1)

new String :x :y

. a :b

? a

in a b

= list $ array 1 2 3 4 5
= obj $ object (:a 1) (:b 2)

= a 1

if (> a 1)
  do
    console.log true
    console.log true
    console.log true
  do
    console.log false

= b $ cond (> a 1) :>1 :<=1

console.log b

= f1 $ \ (a b)
  = a $ + a 2
  console.log a b

= f2 $ \ (a)
  = a 1
  , a

= f3 $ \ ((xs))
  = head $ . xs 0
  = body $ xs.slice 1
  return body.length

switch a
  1 :1
  2
    console.log 1
    console.log 2
  else a

switch 3
  3 :3
  else :else

switch true
  (> a 1) :1
  (> 2 3) :2
  else
    console.log 2
    console.log 2

set a 4
switch true
  (> a 2) :large
  else :small

throw $ new Error ":just an error"

try
  do
    print x
  error
    console.error error

try
  do
    print y
  err

License

MIT

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-75057.html

文章标题:cirru-script

回到顶部