| Paste number 21936: | Smalltalk-style syntax patch |
| Pasted by: | Arnia |
| When: | 3 years, 1 day ago |
| Share: | Tweet this! | http://paste.lisp.org/+GXC |
| Channel: | #swhack |
| Paste contents: |
Only in pluvo-smalltalk: .DS_Store
diff -ur -x '*.pyc' -x '*.pvo' pluvo-latest/basics.py pluvo-smalltalk/basics.py
--- pluvo-latest/basics.py 2006-06-06 13:41:20.000000000 +0100
+++ pluvo-smalltalk/basics.py 2006-07-02 02:27:14.000000000 +0100
@@ -73,7 +73,7 @@
else: block = value
if weakFunction(block):
- env.evaluate(block)
+ return env.evaluate(block)
else: return var[attrname]
def elsethen(env, block):
@@ -123,6 +123,58 @@
py, object = args
env.bind(var.name, object, condition=py)
else: raise ValueError("Must have one or two args")
+
+def exclaim(env, *args):
+ # ! param1: var1 param2: var2 block
+ if len(args) < 2: raise ValueError("Action must have at least one symbol and a block")
+
+
+ # If we only have one symbol, we're a predicate without parameter
+ if len(args) == 2:
+ predsym = args[0]
+ block = args[1]
+ method(env, predsym, Symbol("="), Table(), block)
+
+ else:
+ block = args[-1] # Block is penultimate argument
+ argspec = Table()
+ symname = ""
+ for i in xrange(len(args[:-1])):
+ if not i%2:
+ name = args[i].name
+ symname = symname + name
+ else:
+ var = args[i]
+ argspec.append(var)
+ actsym = Symbol(symname)
+
+ method(env, actsym, Symbol("="), argspec, block)
+
+def ask(env, var, *args):
+ # ask obj param1: arg1 param2: arg2
+ if not len(args) > 0: raise ValueError("Must ask an object to do something")
+
+ # Predicate execution
+ if len(args) == 1:
+ return dot(env, var, args[0])
+
+ #print var
+
+ # Compile message name and arguments
+ argspec = Table()
+ symname = ""
+ for i in xrange(len(args)):
+ if not i%2:
+ name = args[i].name
+ symname = symname + name
+ else:
+ arg = args[i]
+ argspec.append(arg)
+ actsym = Symbol(symname)
+ #print actsym
+ finalargs = [a for a in argspec]
+ dot(env, var, actsym, *finalargs)
+ #return env.evaluate(block, argspec)
def example(env, block):
pass
@@ -358,10 +410,12 @@
"**": power,
"<": lessthan,
">": morethan,
- ".": dot,
+ ".": dot,
+ "!": exclaim,
"|": pipe,
"add": add, # @@ push?
"args": Table(sys.argv[2:]),
+ "ask": ask,
"check": check,
"def": equals,
"else": elsethen,
@@ -382,6 +436,7 @@
"say": say,
"script": script,
"split": split,
+ "to": ask,
"usage": usage
})
diff -ur -x '*.pyc' -x '*.pvo' pluvo-latest/datatypes/table.py pluvo-smalltalk/datatypes/table.py
--- pluvo-latest/datatypes/table.py 2006-06-01 13:16:46.000000000 +0100
+++ pluvo-smalltalk/datatypes/table.py 2006-07-02 00:49:10.000000000 +0100
@@ -160,6 +160,7 @@
self[i + length] = obj
for (i, obj) in enumerate(item):
self[i + key.start] = obj
+
def __delitem__(self, key):
if isinstance(key, int):
diff -ur -x '*.pyc' -x '*.pvo' pluvo-latest/parser.py pluvo-smalltalk/parser.py
--- pluvo-latest/parser.py 2006-06-01 14:31:55.000000000 +0100
+++ pluvo-smalltalk/parser.py 2006-07-02 01:47:17.000000000 +0100
@@ -14,7 +14,7 @@
('URI', r'<[^ \t\r\n"<>]+>'),
('Documentation', r'%% [^\n]+(?=\n)|% (?:[^\n]+|\n(?!\n))*\n'),
('Comment', r'#[^\n]*'),
- ('Variable', r'[$@%]?[A-Za-z]+'),
+ ('Variable', r'[$@%]?[A-Za-z]+[:\?]?'),
('Flag', r'--?[A-Za-z][A-Za-z0-9]*'),
('Number', r'-?(?:[1-9][0-9]*)?[0-9](?:\.[0-9]+)?'),
('Indent', r'\n +'),
@@ -25,8 +25,9 @@
('CloseParen', r'\)'),
('OpenBrace', r'\{'),
('CloseBrace', r'\}'),
- ('Equals', r'='),
- ('Colon', r':'),
+ ('Equals', r'='),
+ ('Exclaim', r'\!'),
+ ('Colon', r':'),
('Plus', r'\+'),
('Minus', r'-'),
('Star', r'\*'),
@@ -43,7 +44,7 @@
CommandClosers = set(['CloseBrace', 'Newline', 'SemiColon'])
Operators = set([
- 'CloseTriangular', 'Colon', 'DoubleArrow', 'DoubleEquals', 'DoubleStar',
+ 'CloseTriangular', 'Colon','Exclaim', 'DoubleArrow', 'DoubleEquals', 'DoubleStar',
'Equals', 'FullStop', 'Minus', 'OpenTriangular', 'Pipe',
'Plus', 'Slash', 'Star'
])This paste has no annotations.