Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zbraniecki/pyast
Basic set of classes for building abstract syntax trees
https://github.com/zbraniecki/pyast
Last synced: 3 months ago
JSON representation
Basic set of classes for building abstract syntax trees
- Host: GitHub
- URL: https://github.com/zbraniecki/pyast
- Owner: zbraniecki
- License: bsd-3-clause
- Created: 2011-06-02T15:21:58.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2018-03-07T07:01:32.000Z (almost 7 years ago)
- Last Synced: 2024-09-10T18:45:27.245Z (4 months ago)
- Language: Python
- Homepage:
- Size: 39.1 KB
- Stars: 9
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README
- License: LICENSE
Awesome Lists containing this project
README
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):
passclass Statement(Node):
passclass Expression(Pattern):
passclass 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.