kofuscript

0.1.6 • Public • Published

KofuScript in Development

Getting Started

Install and run!

$ npm install -g kofuscript
$ kofu -c foo.kofu # compile
$ kofu foo.kofu # execute
$ kofu # repl
$ start-kofuscript #start a new kofuscript project

Extensions you should know about KofuScript

  • .kofu and .tcoffee are compiled by kofuscript compiler.
  • Compiler uses jashkenas/coffeescript in require('./foo.coffee') by default.
  • if you want to compile .coffee with kofuscript, add --self option.

Why work on an old project.

This project is amazing, period. Everything here is exactly what I needed to be added to KOFUJS project in order for it to run the way I want it to run, without having to move over to the clunky TypeScript syntax that I would rather avoid.

Fixes made

  1. Fixed Bug Causing REPL Not to Function
  2. Updated CoffeeScript to stable version 2.5+ with JSX support
  3. Added .kofu file type

Updates Coming

  1. Documentation on Usage with KOFUJS
  2. Updates to Create KofuJS App
  3. Make This Kofuscript fork the default syntax for KOFUJS

Current Tasks

  1. Discover Additional Bugs
  2. Make Production Ready

    # Concatenate string
    present '-------Concatenate string--------'
    present 'Concatenate -->',  'con' + 'cat' + 'en' + 'ate'
 
    # typeof operator
    present '-------TYPEOF operator--------'
    present 'Typeof Operator -->', typeof 'arthur'
 
    # isnt
    present '-------ISNT instead of !== --------'
    present 'ISNT -->' , 'Love' isnt 'Hate'
 
    # and , && , also
    present '------- also --------'
    present 'ALSO -->', 5 > 3 also 6 > 5
 
    # or, ||
    present '------- or --------'
    present 'OR -->', true or false
 
    # not
    present '-------NOT--------'
    present not true
 
    # is  and Booleans
    present '------- is  and Booleans --------'
    present 'Truthy Booleans true, on, yes'
    present 'Falsey Booleans false, off, no'
    present true is on
    present true is yes
    present false is off
    present false is no
 
 
    # Types
 
    obj =  {
        "KofuScript": "JavaScript"
        "is": "==="
        "isnt": "!=="
        "not": "!"
        "also": "&&"
        "or": "||"
        "true yes on": "true"
        "false no off": "false"
        "@ this":  "this"
        "of": "in"
        "in": "no JS Equivalent"
    }
 
    keys :: String[] = Object.keys obj
 
    forEvery key in keys then present "[#{key}] in KofuScript is equivalent to [#{obj[key]}] in JavaScript" unless key is 'KofuScript'
 
    # Strings
 
    myString :: String = 'arthur'
 
    present myString.split('').reverse().join('')
    present typeof myString
 
    # Numbers
 
    myNumber :: Number = 5
 
    present 'myNumber is', myNumber
    present myNumber * 2
    present myNumber ** 2
    present myNumber % 3
    present myNumber / 2
 
 
    # Booleans
    myBoolean :: Boolean = yes
    present 'myBoolean is', myBoolean
 
    # Objects
    myObj =
        name: 'arthur'
        age: 32
        lights: on
        hair: true
 
    present myObj
    # Arrays
    numArr :: Int[] = [1,2,3]
    stringArr :: String[] = ['a', 'b', 'c']
    otherArr :: Any[] = [1, 'a']
    present otherArr
 
    # Loops & Control Flow
 
    forEvery number in [0..12] by 2 then present number
 
    forEvery number in [0..10]
        do (number) ->
            present number * 3
 
    # eat is a function that accepts a string and returns nothing
    eat :: String -> () = (food :: String ) ->
        present "yum #{food.toUpperCase()} !!!"
 
    eat food forEvery food in ['toast', 'cheese', 'wine']
 
    eat food forEvery food in  ['toast', 'cheese', 'wine'] when food isnt 'cheese'
    # Blueprints
 
    blueprint Human
        name :: String
        age :: Int
        constructor: (age :: Int, name :: String) ->
            @name = name
            @age = age
 
    blueprint SuperHero inheritsFrom Human
        name :: String
        age :: Int
        powers :: String[]
 
        constructor: (name :: String, age :: Int, powers...) ->
            super name, age
            @powers = powers
 
    bigArt = new SuperHero 'Big Art', 33, 'flight', 'super strength'
 
    present bigArt
 
    # Functions
 
    # Structs
 
    # Generics
 

(Built KofuScript On Top Of) TypedCoffeeScript

Build Status

CoffeeScript with Types.

This repository is heavily under development and unstable. See below milestone.

Concepts

  • Structual Subtyping
  • Superset of CoffeeScript
  • Easy to replace coffee (pass unannotated coffee)
  • Pessimistic type interfaces

What is pessimistic type interface?

To pass dynamic type system, TypedCoffeeScript expects symbol to implicit node by default. If compiler compares implicit node type and implicit node type and fails, it recover to implicit Any automatically.

Project Status

Current biggest issues is implementation of typescript d.ts importer.

TypeScript AST parser is ready. mizchi/dts-parser

Current Tasks(v0.12)

  • module system
  • robust namespace resolver
  • splats argument such as ( args...: T[] ) ->
  • this scope in bound function

Wip

  • TypeScript *.d.ts importer
  • typealias such as typealias Bar = Foo<T>[]

Milestone

v0.13

  • Be stable(RC for 1.0)
  • Add more tests.
  • Coverage of types to symbol
  • Infer super arguments in class
  • (Fix CoffeeScriptRedux bugs if I can)

Known bugs

  • Compiler can't resolve module namespace when namespace has more than three dots, such as A.B.C.d
  • Take over all coffee-script-redux problems
    • super with member access super().member
    • object literal parsing in class field

How to contribute

You can use this compiler without type annotation. All test by CoffeeScriptRedux passed.

If you encounter bugs, such as type interface... parser..., please report as github issues or pull request to me. I also welcome new syntax proposal.

I DON'T reccomend to use in production yet.

CHANGE LOG

v0.11

  • Generics
  • TypeArgument
  • Fix examples
  • Recognise extensions in require
  • Runnable by tcoffee foo.typed.coffee that has require
  • Class static member type interface
  • Struct with implements

v0.10

  • Rewrite internal AST and type interfaces
  • Add new command line interface
  • Refactor
  • Nullable
  • MemberAccess in struct definition
  • Infer fuction return type with return in Block
  • Destructive Assignment
  • self hosting

~v0.9

  • Implement basic concepts

Examples

Assigment with type

:: Int = 3

Pre defined symbol

:: Number
= 3.14

Nullable

:: Number?
= 3.14
= null

Typed Array

list :: Int[= [1..10]
listWithNull :: Int?[= [1null3]

In v0.10, imperfect to struct.

Struct

struct Point
  @name :: String
  x :: Number
  y :: Number
:: Point = {x: 3y: 3}
name :: String = Point.name
 
struct Point3d implements Point
  z :: Number

Module

TypedCoffeeScript has module system like TypeScript

module A.B
    class @C
        a :: Int
abc :: A.B.C = new A.B.C

Typed Function

# pre define 
f1 :: Int -> Int
f1 = (n) -> n
 
# annotation 
f2 :: Number -> Point = (n) -> x: ny: n * 2
 
# multi arguments 
f3 :: (Int, Int) -> Int = (m, n) -> m * n
 
# another form of arguments 
f4 :: Int * Int -> Int = (m, n) -> m * n
 
# partial applying 
fc :: Int -> Int -> Int
fc = (m) -> (n) -> m * n

Class with this scope

class X
  # bound to this 
  num :: Number
  f   :: Number -> Number
 
  f: (n) ->
    @num = n
 
:: = new X
:: Number = x.3

Class with implements

class Point
  x :: Int
  y :: Int
 
struct Size
  width  :: Int
  height :: Int
 
class Entity extends Point implements Size
:: {x :: Intwidth :: Int} = new Entity

Generics and type arguments

# struct 
struct Value<TU>
    value :: U
struct Id<AB>
    id :: Value<AB>
obj :: Id<IntString> =
  id:
    value: 'value'
 
# function type arguments 
map<TU> :: T[* (T -> U) -> U[]
map = (list, fn) ->
  for i in list
    fn(i)
list :: String[= map<IntString> [1..10](n) -> 'i'
 
# class type arguments 
class Class<A>
  f :: Int -> Int
  constructor :: A -> ()
  constructor: (a) ->
= new Class<Int>(1)

Forked from CoffeeScript II: The Wrath of Khan

          {
       }   }   {
      {   {  }  }
       }   }{  {
      {  }{  }  }             _____       __  __
     ( }{ }{  { )            / ____|     / _|/ _|
   .- { { }  { }} -.        | |     ___ | |_| |_ ___  ___
  (  ( } { } { } }  )       | |    / _ \|  _|  _/ _ \/ _ \
  |`-..________ ..-'|       | |___| (_) | | | ||  __/  __/
  |                 |        \_____\___/|_| |_| \___|\___|       .-''-.
  |                 ;--.                                       .' .-.  )
  |                (__  \     _____           _       _       / .'  / /
  |                 | )  )   / ____|         (_)     | |     (_/   / /
  |                 |/  /   | (___   ___ _ __ _ _ __ | |_         / /
  |                 (  /     \___ \ / __| '__| | '_ \| __|       / /
  |                 |/       ____) | (__| |  | | |_) | |_       . '
  |                 |       |_____/ \___|_|  |_| .__/ \__|     / /    _.-')
   `-.._________..-'                           | |           .' '  _.'.-''
                                               |_|          /  /.-'_.'
                                                           /    _.'
                                                          ( _.-'

Status

Complete enough to use for nearly every project. See the roadmap to 2.0.

Getting Started

npm install -g coffee-script-redux
coffee --help
coffee --js <input.coffee >output.js

Before transitioning from Jeremy's compiler, see the intentional deviations from jashkenas/coffee-script wiki page.

Development

git clone git://github.com/michaelficarra/CoffeeScriptRedux.git && cd CoffeeScriptRedux && npm install
make clean && git checkout -- lib && make -j build && make test

Notable Contributors

I'd like to thank the following financial contributors for their large donations to the Kickstarter project that funded the initial work on this compiler. Together, you donated over $10,000. Without you, I wouldn't have been able to do this.

  • Groupon, who is generously allowing me to work in their offices
  • Trevor Burnham
  • Shopify
  • Abakas
  • 37signals
  • Brightcove
  • Gaslight
  • Pantheon
  • Benbria
  • Sam Stephenson
  • Bevan Hunt
  • Meryn Stol
  • Rob Tsuk
  • Dion Almaer
  • Andrew Davey
  • Thomas Burleson
  • Michael Kedzierski
  • Jeremy Kemper
  • Kyle Cordes
  • Jason R. Lauman
  • Martin Drenovac (Envizion Systems - Aust)
  • Julian Bilcke
  • Michael Edmondson

And of course, thank you Jeremy (and all the other contributors) for making the original CoffeeScript compiler.

Package Sidebar

Install

npm i kofuscript

Weekly Downloads

0

Version

0.1.6

License

3-clause BSD

Unpacked Size

1.99 MB

Total Files

136

Last publish

Collaborators

  • arthurbernierjr