Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Hacky way of adding new transition syntax. foo -> bar nows works.

  • Loading branch information...
commit 0c684ffbc277716a86444753e736798fb8a94edf 1 parent 1924232
@built authored
View
7 bigwheel.py
@@ -2,11 +2,10 @@
from category import Category
import fileinput
import sys
-from interpreter.tools import parse, evaluate
+from interpreter.tools import parse, evaluate, expand_arrows
from common import *
import os
-
def load_file(filename):
try:
for line in open( os.path.dirname(os.path.abspath(__file__)) + "/%s.w" % filename, "r"):
@@ -16,7 +15,7 @@ def load_file(filename):
# Ignore blank lines
if line:
- evaluate( parse(line, ROOT), ROOT )
+ evaluate( parse( expand_arrows(line), ROOT), ROOT )
except:
print "Can't load that file for some damned reason or another."
@@ -81,7 +80,7 @@ def load_prelude():
# Ignore blank lines
if line:
relations_before = len(ROOT.terms)
- evaluate( parse(line, ROOT), ROOT )
+ evaluate( parse( expand_arrows(line), ROOT), ROOT )
relations_after = len(ROOT.terms)
# print "%i relations created. Current total: %i" % ( (relations_after - relations_before), relations_after)
# print "%i patterns now exist." % len(ROOT.comprehend("pattern"))
View
8 interpreter/tools.py
@@ -326,3 +326,11 @@ def relation_id(relation):
def all_transitions(context):
transitions = [transition for transition in context.comprehend("transition", "!metadata") if "metadata" not in transition.terms]
return sorted(transitions, key=relation_id)
+
+def expand_arrows(line):
+ if '->' not in line: return line
+
+ # Only consider two-part transitions for now.
+ (front, back) = [x.strip() for x in line.split('->')][:2]
+
+ return "transition (pattern %s) (action %s)" % (front, back)
View
22 tests/macro_tests.py
@@ -0,0 +1,22 @@
+import unittest
+
+def expand_arrows(line):
+ if '->' not in line: return line
+
+ # Only consider two-part transitions for now.
+ (front, back) = [x.strip() for x in line.split('->')][:2]
+
+ return "transition (pattern %s) (action %s)" % (front, back)
+
+class TestCategoryOperation(unittest.TestCase):
+
+
+ def test_transition_expansion(self):
+ test_line = "foo -> bar"
+
+ self.assertEqual("transition (pattern foo) (action bar)", expand_arrows(test_line))
+
+
+
+if __name__ == '__main__':
+ unittest.main()
View
4 wheeler.py
@@ -2,7 +2,7 @@
from category import Category
import fileinput
import sys
-from interpreter.tools import parse, evaluate
+from interpreter.tools import parse, evaluate, expand_arrows
from common import *
import os
@@ -15,7 +15,7 @@ def load_prelude():
# Ignore blank lines
if line:
- evaluate( parse(line, ROOT), ROOT )
+ evaluate( parse( expand_arrows(line), ROOT), ROOT )
load_prelude()
Please sign in to comment.
Something went wrong with that request. Please try again.