Giter Site home page Giter Site logo

pine's Introduction

Pine

Build Status

Pine is a general purpose, type checked language which is heavily inspired by Rust. Pine compiles to Node.js style JavaScript.

Contents

Foreword

This project is still in early development. Many features may be buggy or not yet implemented.

Install

From GitHub

git clone https://github.com/thomas-crane/pine.git
cd pine
npm link

The CLI

There are several CLI commands available which can be used to compile and inspect Pine code.

The current supported arguments are

print <filename>

Prints the AST representation of the Pine code in the given file.

compile <filename>

Compiles the given Pine file to JavaScript. This is not yet implemented.

Syntax and examples

These examples are also available in the examples/ directory. A full description of the grammar in EBNF form is available in the docs/ directory.

Variables and if statements

num x = 20;
str test;

if x > 15 {
  test = 'x > 15';
} else if x < 10 {
  test = 'x < 10';
} else {
  test = '15 > x > 10';
}

If statements can also be used as expressions, so the following code is equivalent

str test = if x > 15 {
  'x > 15'
} else if x < 10 {
  'x < 10'
} else {
  '15 > x > 15'
}

Functions

fn fib(num n) -> num {
  if n <= 1 {
    1
  } else {
    fib(n - 1) + fib(n - 2)
  }
}

fib(10);

Custom types

# A type which represents a coordinate on a grid.
type Point
  | num x
  | num y
  ;

# Methods which are available on Point type.
type Point has {

  # Static method.
  fn new(num x, num y) -> Point {
    Point {
      x = x,
      y = y,
    }
  }

  # Instance method.
  fn scale(self, num factor) -> Point {
    Point::new(self:x * factor, self:y * factor)
  }
}

Building

If you want to create a custom fork of the Pine compiler, you will need to rebuild the project when you make changes. The package.json has 3 scripts which are used for building.

  • npm run clean - deletes the build directory (dist/)
  • npm run compile - compiles the TypeScript.
  • npm run build - Runs clean, then compile.

Most of the time, build is the script that you want to run. If it is your first time building however, compile will be a bit faster.

Testing and contributing

If you wish to contribute to the Pine compiler, feel free to create a pull request. When contributing, it is important to contribute tested code. To run existing tests, use the command

npm test

This will run the unit tests located in the test/ dir.

When adding a feature, make sure the new feature has tests. Even if some of them do not pass.

There is an additional npm command which can be run to ensure your code follows the project's style guidelines.

npm run lint

This command runs tslint. You should make sure this passes, as pull requests that do not pass this command will be rejected.

pine's People

Contributors

thomas-crane avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.