Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions rply/lexergenerator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import re

from rply.lexer import Lexer

try:
import rpython
from rpython.rlib.objectmodel import we_are_translated
except ImportError:
rpython = None

def we_are_translated():
return False

if we_are_translated():
from rpython.annotator import model
from rpython.annotator.bookkeeper import getbookkeeper
from rpython.rlib.objectmodel import instantiate, hlinvoke
Expand All @@ -14,10 +24,6 @@
from rpython.rtyper.lltypesystem.rstr import STR, string_repr
from rpython.rtyper.rmodel import Repr
from rpython.tool.pairtype import pairtype
except ImportError:
rpython = None

from rply.lexer import Lexer


class Rule(object):
Expand Down Expand Up @@ -104,7 +110,8 @@ def build(self):
"""
return Lexer(self.rules, self.ignore_rules)

if rpython:

if we_are_translated():
class RuleEntry(ExtRegistryEntry):
_type_ = Rule

Expand Down
8 changes: 7 additions & 1 deletion tests/test_ztranslation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

try:
from rpython.rtyper.test.test_llinterp import interpret
import rpython.rlib.objectmodel
old = rpython.rlib.objectmodel.we_are_translated
rpython.rlib.objectmodel.we_are_translated = lambda: True
import rply
reload(rply.lexergenerator)
rpython.rlib.objectmodel.we_are_translated = old
except ImportError:
py.test.skip("Needs RPython to be on the PYTHONPATH")
pytestmark = py.test.mark.skip("Needs RPython to be on the PYTHONPATH")

from rply import LexerGenerator, ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ envlist = py26, py27, py33, py34, py35, pypy, docs
deps = pytest
# just running tox with PYTHONPATH=pypy tox fails, see
# https://bitbucket.org/hpk42/tox/issue/146/setting-pythonpath-causes-tox-to-crash
setenv = PYTHONPATH={env:PYPY_LOCATION}
setenv =
py27,pypy: PYTHONPATH={env:PYPY_LOCATION}
commands = py.test

[testenv:docs]
Expand Down