Pine is a general purpose, type checked language which is heavily inspired by Rust. Pine compiles to Node.js style JavaScript.
This project is still in early development. Many features may be buggy or not yet implemented.
git clone https://github.com/thomas-crane/pine.git
cd pine
npm link
There are several CLI commands available which can be used to compile and inspect Pine code.
The current supported arguments are
Prints the AST representation of the Pine code in the given file.
Compiles the given Pine file to JavaScript. This is not yet implemented.
These examples are also available in the examples/
directory.
A full description of the grammar in EBNF form is available in the docs/
directory.
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'
}
fn fib(num n) -> num {
if n <= 1 {
1
} else {
fib(n - 1) + fib(n - 2)
}
}
fib(10);
# 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)
}
}
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
- Runsclean
, thencompile
.
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.
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.