aboutsummaryrefslogtreecommitdiff
path: root/src/scope.lua
diff options
context:
space:
mode:
authorAlexander Pickering <alex@cogarr.net>2020-08-21 12:45:19 -0400
committerAlexander Pickering <alex@cogarr.net>2020-08-21 12:45:19 -0400
commitb38df089cc2c4694c542e97e9b990a6fda65643b (patch)
treea1ad2013e244bd544d3cab3283d7d0905f5fc6f8 /src/scope.lua
parentf72a03a6c94ade961031db162820f2786795b974 (diff)
downloadglum-b38df089cc2c4694c542e97e9b990a6fda65643b.tar.gz
glum-b38df089cc2c4694c542e97e9b990a6fda65643b.tar.bz2
glum-b38df089cc2c4694c542e97e9b990a6fda65643b.zip
Add rockspec
Add a rockspec for easy packaging
Diffstat (limited to 'src/scope.lua')
-rw-r--r--src/scope.lua148
1 files changed, 74 insertions, 74 deletions
diff --git a/src/scope.lua b/src/scope.lua
index b5fd3c6..acf8eb5 100644
--- a/src/scope.lua
+++ b/src/scope.lua
@@ -1,74 +1,74 @@
---[[
-This module implements functions that handle scoping rules
-]]
-local scope = {}
-
-function scope.lineno (s, i)
- if i == 1 then return 1, 1 end
- local l, lastline = 0, ""
- s = s:sub(1, i) .. "\n"
- for line in s:gmatch("[^\n]*[\n]") do
- l = l + 1
- lastline = line
- end
- local c = lastline:len() - 1
- return l, c ~= 0 and c or 1
-end
-
-function scope.new_scope (env)
- if not env.scope then
- env.scope = 0
- else
- env.scope = env.scope + 1
- end
- local scope = env.scope
- env.maxscope = scope
- env[scope] = {}
- env[scope]["label"] = {}
- env[scope]["local"] = {}
- env[scope]["goto"] = {}
-end
-
-function scope.begin_scope (env)
- env.scope = env.scope + 1
-end
-
-function scope.end_scope (env)
- env.scope = env.scope - 1
-end
-
-function scope.new_function (env)
- if not env.fscope then
- env.fscope = 0
- else
- env.fscope = env.fscope + 1
- end
- local fscope = env.fscope
- env["function"][fscope] = {}
-end
-
-function scope.begin_function (env)
- env.fscope = env.fscope + 1
-end
-
-function scope.end_function (env)
- env.fscope = env.fscope - 1
-end
-
-function scope.begin_loop (env)
- if not env.loop then
- env.loop = 1
- else
- env.loop = env.loop + 1
- end
-end
-
-function scope.end_loop (env)
- env.loop = env.loop - 1
-end
-
-function scope.insideloop (env)
- return env.loop and env.loop > 0
-end
-
-return scope
+--[[
+This module implements functions that handle scoping rules
+]]
+local scope = {}
+
+function scope.lineno (s, i)
+ if i == 1 then return 1, 1 end
+ local l, lastline = 0, ""
+ s = s:sub(1, i) .. "\n"
+ for line in s:gmatch("[^\n]*[\n]") do
+ l = l + 1
+ lastline = line
+ end
+ local c = lastline:len() - 1
+ return l, c ~= 0 and c or 1
+end
+
+function scope.new_scope (env)
+ if not env.scope then
+ env.scope = 0
+ else
+ env.scope = env.scope + 1
+ end
+ local scope = env.scope
+ env.maxscope = scope
+ env[scope] = {}
+ env[scope]["label"] = {}
+ env[scope]["local"] = {}
+ env[scope]["goto"] = {}
+end
+
+function scope.begin_scope (env)
+ env.scope = env.scope + 1
+end
+
+function scope.end_scope (env)
+ env.scope = env.scope - 1
+end
+
+function scope.new_function (env)
+ if not env.fscope then
+ env.fscope = 0
+ else
+ env.fscope = env.fscope + 1
+ end
+ local fscope = env.fscope
+ env["function"][fscope] = {}
+end
+
+function scope.begin_function (env)
+ env.fscope = env.fscope + 1
+end
+
+function scope.end_function (env)
+ env.fscope = env.fscope - 1
+end
+
+function scope.begin_loop (env)
+ if not env.loop then
+ env.loop = 1
+ else
+ env.loop = env.loop + 1
+ end
+end
+
+function scope.end_loop (env)
+ env.loop = env.loop - 1
+end
+
+function scope.insideloop (env)
+ return env.loop and env.loop > 0
+end
+
+return scope