code
stringlengths
1
1.72M
language
stringclasses
1 value
"Constraint Solver in Python." from propagation import Repository, Solver #from distributors import DefaultDistributor import fd #import fi __all__ = ['Repository', 'Solver', 'fd']
Python
"""Internal Python object serialization This module contains functions that can read and write Python values in a binary format. The format is specific to Python, but independent of machine architecture issues (e.g., you can write a Python value to a file on a PC, transport the file to a Sun, and read it back there). ...
Python
"""Python's standard exception class hierarchy. Before Python 1.5, the standard exceptions were all simple string objects. In Python 1.5, the standard exceptions were converted to classes organized into a relatively flat hierarchy. String-based standard exceptions were optional, or used as a fallback if some problem ...
Python
import sys, operator # producing nicer code objects by exec from pypy.tool.sourcetools import NiceCompile _compile = NiceCompile(globals()) def _coerce(left, right): try: return coerce(left, right) except TypeError: return None obj_setattr = object.__setattr__ obj_getattribute = object.__geta...
Python
# NOT_RPYTHON """ A pure Python reimplementation of the _sre module from CPython 2.4 Copyright 2005 Nik Haldimann, licensed under the MIT license This code is based on material licensed under CNRI's Python 1.6 license and copyrighted by: Copyright (c) 1997-2001 by Secret Labs AB """ # Identifying as _sre from Python 2...
Python
# wrapper code generator for gecode library GECODE_WRAP_HH = file("gecode_wrap_tmpl.hh").read() GECODE_WRAP_CC = file("gecode_wrap_tmpl.cc").read() VAR_CLASS_DEF = """ class Py%(var_type)s : public PyVar { public: /* constructor */ Py%(var_type)s( PySpace* space, %(var_factory_args)s ); virtual void upda...
Python
from ctypes import * gecode = cdll.LoadLibrary("./libgecode_wrap.so") IRT_NQ = 1 ES_FAILED = -1 # < Execution has resulted in failure ES_NOFIX = 0 # < Propagation has not computed fixpoint ES_OK = 0 # < Execution is okay ES_FIX = 1 # < Propagation has computed fixpoint...
Python
#
Python
# # StringIO-based cStringIO implementation. # from StringIO import * from StringIO import __doc__ class StringIO(StringIO): def reset(self): """ reset() -- Reset the file position to the beginning """ self.seek(0, 0)
Python
"""Functional tools for creating and using iterators. Infinite iterators: count([n]) --> n, n+1, n+2, ... cycle(p) --> p0, p1, ... plast, p0, p1, ... repeat(elem [,n]) --> elem, elem, elem, ... endlessly or up to n times Iterators terminating on the shortest input sequence: izip(p, q, ...) --> (p[0], q[0]), (p[1], q[...
Python
# This __init__.py shows up in PyPy's app-level standard library. # Let's try to prevent that confusion... if __name__ != 'pypy.lib': raise ImportError, '__init__'
Python
"""Functions to convert between Python values and C structs. Python strings are used to hold the data representing the C struct and also as format strings to describe the layout of data in the C struct. The optional first format char indicates byte order, size and alignment: @: native order, size & alignment (default...
Python
"""Concrete date/time and related types -- prototype implemented in Python. See http://www.zope.org/Members/fdrake/DateTimeWiki/FrontPage See also http://dir.yahoo.com/Reference/calendars/ For a primer on DST, including many current DST rules, see http://webexhibits.org/daylightsaving/ For more about DST than you e...
Python
import parser, operator def binaryVisit(operation): def visit(self, node): left = node.left right = node.right if isinstance(left, parser.ASTConst) and \ isinstance(right, parser.ASTConst): if type(left.value) == type(right.value): return parser.AS...
Python
"""This module is always available. It provides access to mathematical functions for complex numbers.""" # Complex math module # much code borrowed from mathmodule.c import math from math import e, pi # constants _one = complex(1., 0.) _half = complex(0.5, 0.) _i = complex(0., 1.) _halfi = complex(0., 0.5)...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
# Copyright 2000-2004 Michael Hudson mwh@python.net # # All Rights Reserved # # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear in all copies and # that both ...
Python
class Error(Exception): pass class Done(Exception): pass class Incomplete(Exception): pass def a2b_uu(s): if not s: return '' length = (ord(s[0]) - 0x20) % 64 def quadruplets_gen(s): while s: try: yield ord(s[0]), ord(s[1]), ord(s[2]), ord(s[3...
Python
""" The Stackless module allows you to do multitasking without using threads. The essential objects are tasklets and channels. Please refer to their documentation. """ import traceback import sys try: from _stackless import coroutine, greenlet except ImportError: # we are running from CPython from py.magic imp...
Python
""" The Stackless module allows you to do multitasking without using threads. The essential objects are tasklets and channels. Please refer to their documentation. """ import traceback import sys try: deadtask = set() except NameError: from sets import Set as set deadtask = set() switches = 0 try: f...
Python
""" Arguments objects. """ from pypy.interpreter.error import OperationError class AbstractArguments: def parse(self, fnname, signature, defaults_w=[]): """Parse args and kwargs to initialize a frame according to the signature of code object. """ try: return self.match...
Python
import os, sys from pypy.rlib.objectmodel import we_are_translated AUTO_DEBUG = os.getenv('PYPY_DEBUG') RECORD_INTERPLEVEL_TRACEBACK = True class OperationError(Exception): """Interpreter-level exception that signals an exception that should be sent to the application level. OperationError instances hav...
Python
"""Parser for future statements """ from pypy.interpreter.stablecompiler import ast, walk def is_future(stmt): """Return true if statement is a well-formed future statement""" if not isinstance(stmt, ast.From): return 0 if stmt.modname == "__future__": return 1 else: return 0 ...
Python
"""Parse tree transformation module. Transforms Python source code into an abstract syntax tree (AST) defined in the ast module. The simplest ways to invoke this module are via parse and parseFile. parse(buf) -> AST parseFile(path) -> AST """ # Original version written by Greg Stein (gstein@lyra.org) # ...
Python
# operation flags OP_ASSIGN = 0 # 'OP_ASSIGN' OP_DELETE = 1 # 'OP_DELETE' OP_APPLY = 2 # 'OP_APPLY' SC_LOCAL = 1 SC_GLOBAL = 2 SC_FREE = 3 SC_CELL = 4 SC_UNKNOWN = 5 SC_DEFAULT = 6 CO_OPTIMIZED = 0x0001 CO_NEWLOCALS = 0x0002 CO_VARARGS = 0x0004 CO_VARKEYWORDS = 0x0008 CO_NESTED = 0x0010 CO_GENERATOR = 0x0020 CO_GENE...
Python
import types def flatten(tup): elts = [] for elt in tup: if type(elt) == types.TupleType: elts = elts + flatten(elt) else: elts.append(elt) return elts class Set: def __init__(self): self.elts = {} def __len__(self): return len(self.elts) ...
Python
"""A flow graph representation for Python bytecode""" import dis import new import sys import types from pypy.interpreter.stablecompiler import misc from pypy.interpreter.stablecompiler.consts \ import CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS class FlowGraph: def __init__(self): self.c...
Python
"""Package for parsing and compiling Python source code There are several functions defined at the top level that are imported from modules contained in the package. parse(buf, mode="exec") -> AST Converts a string containing Python source code to an abstract syntax tree (AST). The AST is defined in compiler...
Python
"""Check for errs in the AST. The Python parser does not catch all syntax errors. Others, like assignments with invalid targets, are caught in the code generation phase. The compiler package catches some errors in the transformer module. But it seems clearer to write checkers that use the AST to detect errors. """ ...
Python
"""Module symbol-table generator""" from pypy.interpreter.stablecompiler import ast from pypy.interpreter.stablecompiler.consts import SC_LOCAL, SC_GLOBAL, \ SC_FREE, SC_CELL, SC_UNKNOWN, SC_DEFAULT from pypy.interpreter.stablecompiler.misc import mangle import types import sys MANGLE_LEN = 256 class Scope: ...
Python
import imp import os import marshal import struct import sys import types from cStringIO import StringIO from pypy.interpreter.stablecompiler import ast, parse, walk, syntax from pypy.interpreter.stablecompiler import pyassem, misc, future, symbols from pypy.interpreter.stablecompiler.consts import SC_LOCAL, SC_GLOBAL...
Python
from pypy.interpreter.stablecompiler import ast # XXX should probably rename ASTVisitor to ASTWalker # XXX can it be made even more generic? class ASTVisitor: """Performs a depth-first walk of the AST The ASTVisitor will walk the AST, performing either a preorder or postorder traversal depending on which...
Python
from pypy.interpreter import baseobjspace class PyTraceback(baseobjspace.Wrappable): """Traceback object Public fields: * 'tb_frame' * 'tb_lasti' * 'tb_lineno' * 'tb_next' """ def __init__(self, space, frame, lasti, lineno, next): self.space = space self.frame = f...
Python
""" Python-style code objects. PyCode instances have the same co_xxx arguments as CPython code objects. The bytecode interpreter itself is implemented by the PyFrame class. """ import dis, imp, struct, types from pypy.interpreter import eval from pypy.interpreter.error import OperationError from pypy.interpreter.gate...
Python
from pypy.interpreter.executioncontext import ExecutionContext from pypy.interpreter.error import OperationError from pypy.interpreter.argument import Arguments, ArgumentsFromValuestack from pypy.interpreter.pycompiler import CPythonCompiler, PythonAstCompiler from pypy.interpreter.miscutils import ThreadLocals from py...
Python
""" Implementation of a part of the standard Python opcodes. The rest, dealing with variables in optimized ways, is in pyfastscope.py and pynestedscope.py. """ import sys from pypy.interpreter.error import OperationError from pypy.interpreter.baseobjspace import UnpackValueError, Wrappable from pypy.interpreter import...
Python
from pypy.interpreter import module, eval from pypy.interpreter.error import OperationError from pypy.interpreter.pycode import PyCode import sys, types def ensure__main__(space): w_main = space.wrap('__main__') w_modules = space.sys.get('modules') try: return space.getitem(w_modules, w_main) e...
Python
""" PyPy-oriented interface to pdb. """ import pdb def fire(operationerr): if not operationerr.debug_excs: return exc, val, tb = operationerr.debug_excs[-1] pdb.post_mortem(tb)
Python
""" """ import py from pypy.interpreter.gateway import interp2app from pypy.interpreter.argument import Arguments from pypy.interpreter.baseobjspace import Wrappable, W_Root, ObjSpace, \ DescrMismatch from pypy.interpreter.error import OperationError from pypy.tool.sourcetools import compile2, func_with_new_name ...
Python
from pypy.interpreter.module import Module from pypy.interpreter.function import Function, BuiltinFunction from pypy.interpreter import gateway from pypy.interpreter.error import OperationError from pypy.interpreter.baseobjspace import W_Root import os, sys import inspect class MixedModule(Module): NOT_RPYTHON...
Python
""" Function objects. In PyPy there is no difference between built-in and user-defined function objects; the difference lies in the code object found in their func_code attribute. """ from pypy.interpreter.error import OperationError from pypy.interpreter.baseobjspace import Wrappable from pypy.interpreter.eval impor...
Python
""" General classes for bytecode compilers. Compiler instances are stored into 'space.getexecutioncontext().compiler'. """ from codeop import PyCF_DONT_IMPLY_DEDENT from pypy.interpreter.error import OperationError class AbstractCompiler: """Abstract base class for a bytecode compiler.""" # The idea is to gro...
Python
from pypy.interpreter.error import OperationError from pypy.interpreter.baseobjspace import Wrappable class GeneratorIterator(Wrappable): "An iterator created by a generator." def __init__(self, frame): self.space = frame.space self.frame = frame self.running = False def desc...
Python
""" PyFrame class implementation with the interpreter main loop. """ from pypy.tool.pairtype import extendabletype from pypy.interpreter import eval, baseobjspace, pycode from pypy.interpreter.argument import Arguments, ArgumentsFromValuestack from pypy.interpreter.error import OperationError from pypy.interpreter imp...
Python
import sys from pypy.interpreter.miscutils import Stack, Action from pypy.interpreter.error import OperationError def new_framestack(): return Stack() class ExecutionContext: """An ExecutionContext holds the state of an execution thread in the Python interpreter.""" def __init__(self, space): ...
Python
""" Gateway between app-level and interpreter-level: * BuiltinCode (call interp-level code from app-level) * app2interp (embed an app-level function into an interp-level callable) * interp2app (publish an interp-level object to be visible from app-level) """ import types, sys, md5, os NoneNotWrapped = object() f...
Python
from pypy.interpreter.error import OperationError from pypy.interpreter import function, pycode, pyframe from pypy.interpreter.baseobjspace import Wrappable from pypy.interpreter.mixedmodule import MixedModule from pypy.tool.uid import uid class Cell(Wrappable): "A simple container for a wrapped value." d...
Python
from pypy.interpreter.baseobjspace import Wrappable class Ellipsis(Wrappable): def __init__(self, space): self.space = space def descr__repr__(self): return self.space.wrap('Ellipsis') class NotImplemented(Wrappable): def __init__(self, space): self.space = space def descr_...
Python
""" Miscellaneous utilities. """ import types from pypy.rlib.rarithmetic import r_uint class RootStack: pass class Stack(RootStack): """Utility class implementing a stack.""" _annspecialcase_ = "specialize:ctr_location" # polymorphic def __init__(self): self.items = [] def clone(self)...
Python
# empty
Python
"""Parser for future statements """ from pypy.interpreter.pyparser.error import SyntaxError from pypy.interpreter.astcompiler import ast def is_future(stmt): """Return true if statement is a well-formed future statement""" if not isinstance(stmt, ast.From): return 0 if stmt.modname == "__future__"...
Python
"""Generate ast module from specification This script generates the ast module from a simple specification, which makes it easy to accomodate changes in the grammar. This approach would be quite reasonable if the grammar changed often. Instead, it is rather complex to generate the appropriate code. And the Node inte...
Python
# operation flags OP_ASSIGN = 0 # 'OP_ASSIGN' OP_DELETE = 1 # 'OP_DELETE' OP_APPLY = 2 # 'OP_APPLY' OP_NONE = 3 SC_LOCAL = 1 SC_GLOBAL = 2 SC_FREE = 3 SC_CELL = 4 SC_UNKNOWN = 5 SC_DEFAULT = 6 CO_OPTIMIZED = 0x0001 CO_NEWLOCALS = 0x0002 CO_VARARGS = 0x0004 CO_VARKEYWORDS = 0x0008 CO_NESTED = 0x0010 CO_GENERATOR = ...
Python
from pypy.interpreter.astcompiler import ast def flatten(tup): elts = [] for elt in tup: if type(elt) == tuple: elts = elts + flatten(elt) else: elts.append(elt) return elts class Counter: def __init__(self, initial): self.count = initial def next(s...
Python
"""A flow graph representation for Python bytecode""" import sys from pypy.interpreter.astcompiler import misc, ast from pypy.interpreter.astcompiler.consts \ import CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS from pypy.interpreter.pycode import PyCode from pypy.interpreter.baseobjspace import W_Root ...
Python
"""Package for parsing and compiling Python source code There are several functions defined at the top level that are imported from modules contained in the package. parse(buf, mode="exec") -> AST Converts a string containing Python source code to an abstract syntax tree (AST). The AST is defined in compiler...
Python
"""Check for errs in the AST. The Python parser does not catch all syntax errors. Others, like assignments with invalid targets, are caught in the code generation phase. The compiler package catches some errors in the transformer module. But it seems clearer to write checkers that use the AST to detect errors. """ ...
Python
"""Module symbol-table generator""" from pypy.interpreter.astcompiler import ast from pypy.interpreter.astcompiler.consts import SC_LOCAL, SC_GLOBAL, \ SC_FREE, SC_CELL, SC_UNKNOWN, SC_DEFAULT from pypy.interpreter.astcompiler.misc import mangle, Counter from pypy.interpreter.pyparser.error import SyntaxError from...
Python
import imp import os import marshal import struct import sys #from pypy.interpreter.astcompiler import ast, parse, walk, syntax from pypy.interpreter.astcompiler import ast from pypy.interpreter.astcompiler import pyassem, misc, future, symbols from pypy.interpreter.astcompiler.consts import SC_LOCAL, SC_GLOBAL, \ ...
Python
from pypy.interpreter.astcompiler import ast # XXX should probably rename ASTVisitor to ASTWalker # XXX can it be made even more generic? class ASTVisitor: """Performs a depth-first walk of the AST The ASTVisitor will walk the AST, performing either a preorder or postorder traversal depending on which me...
Python
#empty
Python
#!/usr/bin/env python """This module loads the python Grammar (2.3 or 2.4) and builds the parser for this grammar in the global PYTHON_PARSER helper functions are provided that use the grammar to parse using file_input, single_input and eval_input targets """ import sys import os from pypy.interpreter.error import Ope...
Python
from pypy.interpreter.pyparser import symbol # try to avoid numeric values conflict with tokens # it's important for CPython, but I'm not so sure it's still # important here class SymbolMapper(object): """XXX dead""" def __init__(self, sym_name=None ): _anoncount = self._anoncount = -10 _count...
Python
"""This is a lexer for a Python recursive descent parser it obeys the TokenSource interface defined for the grammar analyser in grammar.py """ import sys from codeop import PyCF_DONT_IMPLY_DEDENT from pypy.interpreter.pyparser.grammar import TokenSource, Token, AbstractContext, Parser from pypy.interpreter.pyparser.er...
Python
class SyntaxError(Exception): """Base class for exceptions raised by the parser.""" def __init__(self, msg, lineno=0, offset=0, text=None, filename=None): self.msg = msg self.lineno = lineno self.offset = offset self.text = text self.filename = filename self.pri...
Python
"""This is a lexer for a Python recursive descent parser it obeys the TokenSource interface defined for the grammar analyser in grammar.py """ from grammar import TokenSource, Token, AbstractContext from ebnfgrammar import GRAMMAR_GRAMMAR as G def match_symbol( input, start, stop ): idx = start while idx<sto...
Python
#! /usr/bin/env python # ______________________________________________________________________ """Module pytokenize THIS FILE WAS COPIED FROM pypy/module/parser/pytokenize.py AND ADAPTED TO BE ANNOTABLE (Mainly made lists homogeneous) This is a modified version of Ka-Ping Yee's tokenize module found in the Python st...
Python
#! /usr/bin/env python # ______________________________________________________________________ """Module automata THIS FILE WAS COPIED FROM pypy/module/parser/pytokenize.py AND ADAPTED TO BE ANNOTABLE (Mainly made the DFA's __init__ accept two lists instead of a unique nested one) $Id: automata.py,v 1.2 2003/10/02 1...
Python
# This module contains the grammar parser # and the symbol mappings from grammar import Alternative, Sequence, Token, KleeneStar, \ GrammarElement, Parser class GrammarParser(Parser): pass GRAMMAR_GRAMMAR = GrammarParser() def grammar_grammar(): """ (mostly because of g_add_token I suppose) Bu...
Python
from pypy.interpreter.typedef import TypeDef, GetSetProperty, interp_attrproperty from pypy.interpreter.astcompiler import ast, consts from pypy.interpreter.pyparser.error import SyntaxError ### Parsing utilites ################################################# def parse_except_clause(tokens): """parses 'except' ...
Python
from grammar import Token, GrammarProxy from grammar import AbstractBuilder, AbstractContext ORDA = ord("A") ORDZ = ord("Z") ORDa = ord("a") ORDz = ord("z") ORD0 = ord("0") ORD9 = ord("9") ORD_ = ord("_") def is_py_name( name ): if len(name)<1: return False v = ord(name[0]) if not (ORDA <= v <= O...
Python
#!/usr/bin/env python """This module loads the python Grammar (2.3 or 2.4) and builds the parser for this grammar in the global PYTHON_PARSER helper functions are provided that use the grammar to parse using file_input, single_input and eval_input targets """ import sys import os from pypy.interpreter.error import Ope...
Python
#! /usr/bin/env python # ______________________________________________________________________ """Module pytokenize THIS FILE WAS COPIED FROM pypy/module/parser/pytokenize.py AND ADAPTED TO BE ANNOTABLE (Mainly made lists homogeneous) This is a modified version of Ka-Ping Yee's tokenize module found in the Python st...
Python
#! /usr/bin/env python # ______________________________________________________________________ """Module automata THIS FILE WAS COPIED FROM pypy/module/parser/pytokenize.py AND ADAPTED TO BE ANNOTABLE (Mainly made the DFA's __init__ accept two lists instead of a unique nested one) $Id: automata.py,v 1.2 2003/10/02 1...
Python
"""miscelanneous utility functions XXX: svn mv pythonutil.py gramtools.py / parsertools.py """ import sys import os import parser from pypy.interpreter.pyparser.grammar import Parser from pypy.interpreter.pyparser.pytoken import setup_tokens from pypy.interpreter.pyparser.ebnfgrammar import GRAMMAR_GRAMMAR from pypy...
Python
from pypy.interpreter import gateway from pypy.interpreter.error import OperationError def parsestr(space, encoding, s): # compiler.transformer.Transformer.decode_literal depends on what # might seem like minor details of this function -- changes here # must be reflected there. # we use ps as "point...
Python
"""This module provides the astbuilder class which is to be used by GrammarElements to directly build the AS during parsing without going through the nested tuples step """ from grammar import BaseGrammarBuilder, AbstractContext from pypy.interpreter.function import Function from pypy.interpreter.astcompiler import a...
Python
# This file is automatically generated; please don't muck it up! # # To update the symbols in this file, call this function from python_grammar() # and call PyPy. single_input = 256 file_input = 257 eval_input = 258 decorator = 259 decorators = 260 funcdef = 261 parameters = 262 varargslist = 263 fpdef = 264 fplis...
Python