Skip to content

Python 3 compatibility #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ such as `repeat` and `minrepeat`.
To read JSketch, again, you should generate our parser first:

```sh
cd parser
cd jskparser
make
```

1 change: 1 addition & 0 deletions java_sk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import sys
import os

14 changes: 9 additions & 5 deletions java_sk/decode/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import absolute_import
try: unicode
except: unicode = u"".__class__
import os
import logging

@@ -7,11 +10,11 @@
from .. import util
from ..meta.program import Program

from finder import HFinder, EGFinder
from replacer import HReplacer, EGReplacer, MGReplacer
from .finder import HFinder, EGFinder
from .replacer import HReplacer, EGReplacer, MGReplacer

from collection import Collection
from semantic_checker import SemanticChecker
from .collection import Collection
from .semantic_checker import SemanticChecker


# white-list checking
@@ -79,7 +82,8 @@ def to_java(java_dir, pgr, output_path):
# replace collections of interface types with actual classes, if any
_visitors.append(Collection())
_visitors.append(SemanticChecker())
map(lambda vis: pgr.accept(vis), _visitors)
for vis in _visitors:
pgr.accept(vis)

## trimming of the program
trim(pgr)
5 changes: 4 additions & 1 deletion java_sk/decode/collection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import absolute_import
try: unicode
except: unicode = u"".__class__
from lib.typecheck import *
import lib.visit as v
import lib.const as C
@@ -31,7 +34,7 @@ class Collection(object):
def repl_itf(tname, init=True):
if not util.is_collection(tname): return tname
_ids = util.of_collection(tname)
ids = map(util.autoboxing, _ids)
ids = [util.autoboxing(i) for i in _ids]
collection = ids[0]
if init: collection = Collection.__impl[collection]
generics = ids[1:] # don't be recursive, like map(repl_itf, ids[1:])
1 change: 1 addition & 0 deletions java_sk/decode/finder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import logging

import lib.visit as v
11 changes: 6 additions & 5 deletions java_sk/decode/replacer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import operator as op
from __future__ import absolute_import
try: unicode
except: unicode = u"".__class__
import re
import logging

@@ -29,7 +31,7 @@ def __init__(self, output_path, holes):

## hole assignments for roles
## glblInit_fid__cid_????,StmtAssign,accessor_???? = n
names = map(op.attrgetter("name"), self._holes)
names = [hole.name for hole in self._holes]
regex_role = r"({})__(\S+)_\S+ = (\d+)$".format('|'.join(names))

# interpret the synthesis result
@@ -208,12 +210,11 @@ def visit(self, node):
rty = node.typ if node.typ != C.J.v else C.J.OBJ
node.body = to_statements(node, u"{} _out;".format(rty))

op_strip = op.methodcaller("strip")
_assigns = self._assigns[mname]
for _assign in _assigns:
lhs, rhs = map(op_strip, _assign.split('='))
lhs, rhs = [a.strip() for a in _assign.split('=')]
if len(lhs.split(' ')) > 1: # i.e., var decl
ty, v = map(op_strip, lhs.split(' '))
ty, v = [l.strip() for l in lhs.split(' ')]
ty = ty.split('@')[0] # TODO: cleaner way to retrieve/sanitize type
node.body += to_statements(node, u"{} {} = {};".format(ty, v, rhs))
else: # stmt assign
1 change: 1 addition & 0 deletions java_sk/decode/semantic_checker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import logging

import lib.const as C
Loading