Code Monkey home page Code Monkey logo

pyast's Introduction

PyAST is a library that allows for creating AST structures using declarative programming form.

example:

== jsast.py ==

import pyast as ast

class Node(ast.Node):
    pass

class Statement(Node):
    pass

class Expression(Pattern):
    pass

class Operator(Node):
    token = ast.field(("+","=","-","==","!=",">",">"))

class Identifier(Expression):
    name = ast.field((str, unicode))

class Literal(Expression):
    value = ast.field((str, bool, int, NoneType))

class Program(ast.Node):
    body = ast.seq(Statement, null=True)

class ExpressionStatement(Statement):
    expression = ast.field(Expression)

class AssignmentExpression(Expression):
    operator = ast.field(Operator)
    left = ast.field(Expression)
    right = ast.field(Expression)

== main.py ==

from jsast import *

prog = Program()
prog.body.append(
    ExpressionStatement(
        AssignmentExpression(
            Operator("="),
            Identifier("x"),
            Literal(2)
        )))

# result: x=2;
=========

pyast.DEBUG variable defines if pyast operates in DEBUG mode in which the 
strong typing is enforced at cost of performance, or optimized mode when all
the checks are inactive.

pyast's People

Contributors

jgoppert avatar zbraniecki avatar

Stargazers

Mutalisk avatar  avatar Alexandre Nicastro avatar Iury Alves de Souza avatar Trond Jakob Sjøvang avatar Takayuki Muranushi avatar Jeroen van Rijn avatar Andrii Magalich avatar  avatar

Watchers

James Cloos avatar Luka Hadzi-Djokic avatar  avatar

pyast's Issues

Update on PyPi

It seems this package is out of date on PyPi. I would like to use it for a project so if you could update it, it would be much appreciated.

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.