summaryrefslogtreecommitdiff
path: root/parser/expr.go
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2024-03-14 14:37:32 +0100
committerMarc Vertes <mvertes@free.fr>2024-03-14 14:37:32 +0100
commit378683d25bdae89fa446b2b82f8dda5d6b34ea33 (patch)
treecbf624e4eb38fafe51a12a718b48f43192cfcfac /parser/expr.go
parent60170bad25f912e0ba44e4c0095b54f6e26e307e (diff)
feat: initial support of closures
Also detection and automatic execution of main function. Make sure that all debug is output to stderr.
Diffstat (limited to 'parser/expr.go')
-rw-r--r--parser/expr.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/parser/expr.go b/parser/expr.go
index 91c093f..e952f7c 100644
--- a/parser/expr.go
+++ b/parser/expr.go
@@ -17,6 +17,17 @@ func (p *Parser) ParseExpr(in Tokens) (out Tokens, err error) {
// Process tokens from last to first, the goal is to reorder the tokens in
// a stack machine processing order, so it can be directly interpreted.
//
+ if len(in) > 1 && in[0].Id == lang.Func {
+ // Function as value (i.e closure).
+ if out, err = p.ParseFunc(in); err != nil {
+ return out, err
+ }
+ // Get function label and use it as a symbol ident.
+ fid := out[1]
+ fid.Id = lang.Ident
+ out = append(out, fid)
+ return out, err
+ }
for i := len(in) - 1; i >= 0; i-- {
t := in[i]
// temporary assumptions: binary operators, returning 1 value