Reduce the scope of the ops_list variables
@@ -583,9 +583,14 @@ function Parser:CastExp()
return exp
end
-local unary_ops_list = "not - ~ #"
-local right_ops_list = "^ .."
-local binops_list = {
+local is_unary_operator = {} -- op => bool
+local is_right_associative = {} -- op => bool
+local binop_precedence = {} -- op => integer
+local unary_precedence = 12
+do
+ local unary_ops = "not - ~ #"
+ local right_ops = "^ .."
+ local binops = {
[14] = "^",
--[13] = reserved for '^'
--[12] = reserved for unary operators
@@ -602,22 +607,18 @@ local binops_list = {
[ 1] = "or",
}
-local is_unary_operator = {} -- op => bool
-local is_right_associative = {} -- op => bool
-local binop_precedence = {} -- op => integer
-local unary_precedence = 12
-
-for op in unary_ops_list:gmatch("%S+") do
+ for op in string.gmatch(unary_ops, "%S+") do
is_unary_operator[op] = true
end
-for op in right_ops_list:gmatch("%S+") do
+ for op in string.gmatch(right_ops, "%S+") do
is_right_associative[op] = true
end
-for prec, ops_str in pairs(binops_list) do
- for op in ops_str:gmatch("%S+") do
+ for prec, ops_str in pairs(binops) do
+ for op in string.gmatch(ops_str, "%S+") do
binop_precedence[op] = prec
end
end
+end
-- subexpr -> (castexp | unop subexpr) { binop subexpr }
-- where 'binop' is any binary operator with a priority higher than 'limit'
