Commits

catseye  committed f746b04

Make two more tests pass.

  • Participants
  • Parent commits bfc758e

Comments (0)

Files changed (2)

File README.markdown

     = TRUE
 
     | #
-    ? Not in a function body
+    ? Use of "#" outside of a function body
 
     | self(FOO)
-    ? Not in a function body
+    ? Use of "self" outside of a function body
 
     | def id(#)
     |     #

File script/exanoke

 class Parser(object):
     def __init__(self, text):
         self.scanner = Scanner(text)
+        self.defining = None
 
     def program(self):
         fundefs = []
         while self.scanner.on('def'):
             fundefs.append(self.fundef())
+        self.defining = None
         expr = self.expr()
         return AST('Program', [expr] + fundefs)
 
         while self.scanner.consume(','):
             args.append(self.ident())
         self.scanner.expect(')')
+        self.defining = name
         expr = self.expr()
+        self.defining = None
         return AST('FunDef', [expr] + args, value=name)
 
     def expr(self):
             e3 = self.expr()
             return AST('If', [e1, e2, e3])
         elif self.scanner.consume("self"):
+            if self.defining is None:
+                raise SyntaxError('Use of "self" outside of a function body')
             args = []
             self.scanner.expect("(")
             e1 = self.smaller()
             self.scanner.expect(")")
             return AST('Not', [e1])
         elif self.scanner.consume("#"):
+            if self.defining is None:
+                raise SyntaxError('Use of "#" outside of a function body')
             return AST('ArgRef', value=0)
         elif self.scanner.on_type("atom"):
             atom = self.scanner.token