Skip to content

patrickkunka/pine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pine

Pine is a lightweight JavaScript AST Parser for Node.js.

Initially created to power Cortex's JavaScript to C# class transpiler, Pine currently supports only a subset of JavaScript syntax neccasary for the evaluation of class "getter" functions, the content of which can be explicity understood in C#.

The following syntax is currently supported:

MEMBER_EXPRESSION
UNARY_EXPRESSION
PARAMETERS_EXPRESSION
ASSIGNMENT_EXPRESSION
BINARY_EXPRESSION
LOGICAL_EXPRESSION
CALL_EXPRESSION
VARIABLE_DECLARATION
RETURN_STATEMENT
BLOCK_STATEMENT
FUNCTION_DECLARATION
IF_STATEMENT

The intention is to add support for a wider range of syntaxes, with the option to provide a stricter subset to the parser at runtime.

API

import Pine from 'pine';

programString = 'var foo = "bar";';

const program = Pine.parse(programString);

The above example returns an instance of pine.Models.Program which can be considered the AST root. In the above example, the returned value is as follows:

Program {
    body: [
        VariableDeclaration {
            kind: 'var',
            identifier: Identifier {
                content: 'foo'
            },
            init: Literal {
                kind: 'string',
                raw: "'bar'",
                content: 'bar'
            }
        }
    ]
}

Requirements

Node >= 7


© 2017 Patrick Kunka / KunkaLabs Ltd

About

A lightweight JavaScript AST parser for Node.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published