Rename REAMDE to README.md
[nit.git] / src / semantize / scope.nit
index 00702d0..4ea5f27 100644 (file)
@@ -20,6 +20,7 @@ module scope
 import phase
 
 redef class ToolContext
+       # Run `APropdef::do_scope` on each propdef.
        var scope_phase: Phase = new ScopePhase(self, null)
 end
 
@@ -71,9 +72,8 @@ private class ScopeVisitor
 
        var selfvariable = new Variable("self")
 
-       init(toolcontext: ToolContext)
+       init
        do
-               self.toolcontext = toolcontext
                scopes.add(new Scope)
        end
 
@@ -99,7 +99,7 @@ private class ScopeVisitor
                var name = variable.name
                var found = search_variable(name)
                if found != null then
-                       self.error(node, "Error: A variable named `{name}' already exists")
+                       self.error(node, "Error: a variable named `{name}` already exists.")
                        return false
                end
                scopes.first.variables[name] = variable
@@ -160,14 +160,14 @@ private class ScopeVisitor
                        if nid == null then
                                var res = search_label("")
                                if res != null then
-                                       self.error(nlabel, "Syntax error: anonymous label already defined.")
+                                       self.error(nlabel, "Syntax Error: anonymous label already defined.")
                                end
                                name = ""
                        else
                                name = nid.text
                                var found = self.search_label(name)
                                if found != null then
-                                       self.error(nlabel, "Syntax error: label {name} already defined.")
+                                       self.error(nlabel, "Syntax Error: label `{name}` already defined.")
                                end
                        end
                else
@@ -190,7 +190,7 @@ private class ScopeVisitor
                        if nid == null then
                                var res = search_label("")
                                if res == null then
-                                       self.error(nlabel, "Syntax error: invalid anonymous label.")
+                                       self.error(nlabel, "Syntax Error: invalid anonymous label.")
                                        return null
                                end
                                return res
@@ -198,7 +198,7 @@ private class ScopeVisitor
                        var name = nid.text
                        var res = search_label(name)
                        if res == null then
-                               self.error(nlabel, "Syntax error: invalid label {name}.")
+                               self.error(nlabel, "Syntax Error: invalid label `{name}`.")
                                return null
                        end
                        return res
@@ -209,7 +209,7 @@ private class ScopeVisitor
                                        return res
                                end
                        end
-                       self.error(node, "Syntax Error: 'break' statement outside block.")
+                       self.error(node, "Syntax Error: `break` statement outside block.")
                        return null
                end
        end
@@ -411,6 +411,24 @@ redef class AForExpr
        end
 end
 
+redef class AWithExpr
+       # The break escape mark associated with the 'with'
+       var break_mark: nullable EscapeMark
+
+       redef fun accept_scope_visitor(v)
+       do
+               v.scopes.unshift(new Scope)
+
+               var escapemark = v.make_escape_mark(n_label, true)
+               self.break_mark = escapemark
+
+               v.enter_visit(n_expr)
+               v.enter_visit_block(n_block, escapemark)
+
+               v.shift_scope
+       end
+end
+
 redef class AVarFormExpr
        # The associated variable
        var variable: nullable Variable
@@ -425,7 +443,7 @@ redef class ACallFormExpr
                        if variable != null then
                                var n: AExpr
                                if not n_args.n_exprs.is_empty or n_args isa AParExprs then
-                                       v.error(self, "Error: {name} is variable, not a function.")
+                                       v.error(self, "Error: `{name}` is a variable, not a method.")
                                        return
                                end
                                n = variable_create(variable)