Skip to content
Browse files

shifted some stuff around

  • Loading branch information...
1 parent cace9fd commit 2915226ba717d9a01f43f1a76e2952d61ca4a920 @lihaoyi committed May 8, 2013
Showing with 65 additions and 71 deletions.
  1. +63 −2 macropy/core/__init__.py
  2. +0 −64 macropy/core/core.py
  3. +1 −1 macropy/core/lift.py
  4. +1 −2 macropy/core/macros.py
  5. +0 −1 macropy/macros/adt.py
  6. +0 −1 macropy/macros2/linq.py
View
65 macropy/core/__init__.py
@@ -1,3 +1,64 @@
"""
-The core of the macropy library
-"""
+This file contains the basic operations necessary to transform between
+code in various forms: Source, ASTs, and Values. These operations wrap
+more primitive forms (e.g. in the ast module) which should not be used
+directly.
+
+This map maps out how to convert from form to form:
+
+ parse_stmt
+ ____________ parse_expr ____________
+ | |----------->| |
+ | Source | | AST |
+ |____________|<-----------|____________|
+ ^ | unparse_ast | ^
+ | | | eval | ast_repr
+ | | | |
+real_repr | | eval _v________|_
+ | --------------->| |
+ | | Value |
+ ----------------------|____________|
+"""
+import ast
+from unparser import Unparser
+
+import StringIO
+
+
+
+def ast_repr(x):
+ """Similar to repr(), but returns an AST instead of a String, which when
+ evaluated will return the given value."""
+ return parse_expr(repr(x))
+
+
+def parse_expr(x):
+ """Parses a string into an `expr` AST"""
+ return ast.parse(x).body[0].value
+
+
+def parse_stmt(x):
+ """Parses a string into an `stmt` AST"""
+ return ast.parse(x).body
+
+
+def real_repr(thing):
+ """Converts the given value into a string which when evaluated will
+ return the value. This one is smart enough to take care of ASTs"""
+ if isinstance(thing, ast.AST):
+ fields = [(a, real_repr(b)) for a, b in ast.iter_fields(thing)]
+ rv = '%s(%s' % (thing.__class__.__name__, ', '.join(
+ (b for a, b in fields)
+ ))
+
+ return rv + ')'
+ elif isinstance(thing, list):
+ return '[%s]' % ', '.join(real_repr(x) for x in thing)
+ return repr(thing)
+
+
+def unparse_ast(ast):
+ """Converts an AST back into the source code from whence it came!"""
+ buffer = StringIO.StringIO()
+ Unparser(ast, buffer)
+ return buffer.getvalue()
View
64 macropy/core/core.py
@@ -1,64 +0,0 @@
-"""
-This file contains the basic operations necessary to transform between
-code in various forms: Source, ASTs, and Values. These operations wrap
-more primitive forms (e.g. in the ast module) which should not be used
-directly.
-
-This map maps out how to convert from form to form:
-
- parse_stmt
- ____________ parse_expr ____________
- | |----------->| |
- | Source | | AST |
- |____________|<-----------|____________|
- ^ | unparse_ast | ^
- | | | eval | ast_repr
- | | | |
-real_repr | | eval _v________|_
- | --------------->| |
- | | Value |
- ----------------------|____________|
-"""
-import ast
-from unparser import Unparser
-
-import StringIO
-
-
-
-def ast_repr(x):
- """Similar to repr(), but returns an AST instead of a String, which when
- evaluated will return the given value."""
- return parse_expr(repr(x))
-
-
-def parse_expr(x):
- """Parses a string into an `expr` AST"""
- return ast.parse(x).body[0].value
-
-
-def parse_stmt(x):
- """Parses a string into an `stmt` AST"""
- return ast.parse(x).body
-
-
-def real_repr(thing):
- """Converts the given value into a string which when evaluated will
- return the value. This one is smart enough to take care of ASTs"""
- if isinstance(thing, ast.AST):
- fields = [(a, real_repr(b)) for a, b in ast.iter_fields(thing)]
- rv = '%s(%s' % (thing.__class__.__name__, ', '.join(
- (b for a, b in fields)
- ))
-
- return rv + ')'
- elif isinstance(thing, list):
- return '[%s]' % ', '.join(real_repr(x) for x in thing)
- return repr(thing)
-
-
-def unparse_ast(ast):
- """Converts an AST back into the source code from whence it came!"""
- buffer = StringIO.StringIO()
- Unparser(ast, buffer)
- return buffer.getvalue()
View
2 macropy/core/lift.py
@@ -1,5 +1,5 @@
from macropy.core.macros import *
-
+from macropy.core import *
macros = Macros()
def u(tree):
View
3 macropy/core/macros.py
@@ -3,9 +3,8 @@
import inspect
import ast
from ast import *
-from macropy.core.core import *
from util import *
-
+from macropy.core import *
class Macros(object):
def __init__(self):
View
1 macropy/macros/adt.py
@@ -1,4 +1,3 @@
-from macropy.core.core import *
from macropy.core.macros import *
from macropy.core.lift import macros, q, u
View
1 macropy/macros2/linq.py
@@ -1,5 +1,4 @@
from macropy.core.macros import Macros
-from macropy.core.core import *
from macropy.core.lift import macros, q, u, name, ast
from macropy.macros.quicklambda import macros, f
from ast import *

0 comments on commit 2915226

Please sign in to comment.
Something went wrong with that request. Please try again.