From 778e03a929a6302d4139f38f2d133f4aa0290f3a Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Fri, 5 Feb 2016 13:56:29 -0500 Subject: [PATCH] Fixed Kalypso's scope lookup to handle ::, ported another test (+ got another one from having proper scope operator) --- stdlib/ast_transformation.krak | 13 ++++++++++++- stdlib/string.krak | 21 +++++++++++++++++++-- tests/test_emptyBracesFunction.krak | 4 ++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/stdlib/ast_transformation.krak b/stdlib/ast_transformation.krak index 22e3c41..b93a450 100644 --- a/stdlib/ast_transformation.krak +++ b/stdlib/ast_transformation.krak @@ -579,7 +579,18 @@ fun identifier_lookup(name: string, scope: *ast_node): *ast_node { fun scope_lookup(name: string, scope: *ast_node): vector<*ast_node> { println("*****Doing a name lookup for*****") println(name) - return scope_lookup_helper(name, scope, set<*ast_node>()) + var results = vector(scope) + name.split("::").for_each(fun(i: string) { + println(string("based on split, looking up: ") + i) + var next_results = vector<*ast_node>() + results.for_each(fun(s: *ast_node) { + print("looking in scope: ") + println(s) + next_results += scope_lookup_helper(i, s, set<*ast_node>()) + }) + results = next_results + }) + return results } fun scope_lookup_helper(name: string, scope: *ast_node, visited: set<*ast_node>): vector<*ast_node> { // need to do properly scopded lookups diff --git a/stdlib/string.krak b/stdlib/string.krak index 494cbcf..29344ac 100644 --- a/stdlib/string.krak +++ b/stdlib/string.krak @@ -149,11 +149,28 @@ obj string (Object, Serializable) { return out; } - fun lines(): vector::vector { + fun split(delim: *char): vector::vector return split(string(delim)) + fun split(delim: string): vector::vector { var out.construct(): vector::vector var current = string("") for (var i = 0; i < data.size; i++;) { - if (data[i] == '\n') { + if (i < data.size-delim.length() && slice(i, i+delim.length()) == delim) { + out.add(current) + current = string("") + i += delim.length()-1 + } else { + current += data[i] + } + } + out.add(current) + return out + } + fun lines(): vector::vector return split('\n') + fun split(delim: char): vector::vector { + var out.construct(): vector::vector + var current = string("") + for (var i = 0; i < data.size; i++;) { + if (data[i] == delim) { out.add(current) current = string("") } else { diff --git a/tests/test_emptyBracesFunction.krak b/tests/test_emptyBracesFunction.krak index be178b7..b9ce9b3 100644 --- a/tests/test_emptyBracesFunction.krak +++ b/tests/test_emptyBracesFunction.krak @@ -1,9 +1,9 @@ -import io; +import simple_print; fun nothing(): void {} fun main(): int { nothing(); - io::println("It was nothing"); + simple_print::println("It was nothing"); return 0; }