WIP: factorization of lexer and parser implementation - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/expr-actions.lua
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2013年05月10日 18:07:56 +0200
committerFrancesco Abbate <francesco.bbt@gmail.com>2013年05月10日 18:07:56 +0200
commit204fa404431f9c619f0dfc5ae3efc463749fa8ed (patch)
tree825fc39707d7c7b3e734c5ffb3fd04af8f325530 /expr-actions.lua
parent58dd27ba0c1776644db561cc4d565a281e2f7b2b (diff)
downloadgsl-shell-204fa404431f9c619f0dfc5ae3efc463749fa8ed.tar.gz
WIP: factorization of lexer and parser implementation
Diffstat (limited to 'expr-actions.lua')
-rw-r--r--expr-actions.lua 20
1 files changed, 20 insertions, 0 deletions
diff --git a/expr-actions.lua b/expr-actions.lua
index 79862f97..17fc015e 100644
--- a/expr-actions.lua
+++ b/expr-actions.lua
@@ -1,4 +1,6 @@
+local type = type
+
local function mult(a, b)
if a == 1 then return b end
if b == 1 then return a end
@@ -27,6 +29,21 @@ end
local function ident_action(id) return id end
+-- return true iff expr is a variable (with enums or not).
+-- if it is a variable returns, in addition, the var_name and the enumeration flag
+local function is_variable(expr)
+ if type(expr) == 'string' then
+ local esc_name = string.match(expr, "^%%(.*)")
+ return true, esc_name or expr, (esc_name ~= nil)
+ else
+ return false
+ end
+end
+
+local function is_number(expr)
+ return type(expr) == 'number'
+end
+
return {
infix = infix_action,
ident = ident_action,
@@ -36,4 +53,7 @@ return {
number = function(x) return x end,
exprlist = function(a, ls) if ls then ls[#ls+1] = a else ls = {a} end; return ls end,
schema = function(x, y, conds) return {x= x, y= y, conds= conds} end,
+
+ is_variable = is_variable,
+ is_number = is_number,
}
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月15日 06:00:29 +0000

AltStyle によって変換されたページ (->オリジナル) /