From 35a59a086708848dd9f63e4cb071168f5704bc9a Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 17 Oct 2019 21:33:45 -0700 Subject: [PATCH] Add parser tokens, guru meditation on why the AST types don't work --- src/passes/1-parser/pascaligo/AST.ml | 37 ++++++++++++++-------- src/passes/1-parser/pascaligo/AST.mli | 37 ++++++++++++++-------- src/passes/1-parser/pascaligo/ParToken.mly | 1 + src/passes/1-parser/pascaligo/Parser.mly | 6 ++-- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/passes/1-parser/pascaligo/AST.ml b/src/passes/1-parser/pascaligo/AST.ml index 36cbdf637..f6c4aa26d 100644 --- a/src/passes/1-parser/pascaligo/AST.ml +++ b/src/passes/1-parser/pascaligo/AST.ml @@ -49,6 +49,7 @@ type kwd_contains = Region.t type kwd_down = Region.t type kwd_else = Region.t type kwd_end = Region.t +type kwd_expr = Region.t type kwd_for = Region.t type kwd_from = Region.t type kwd_function = Region.t @@ -210,19 +211,29 @@ and type_tuple = (type_expr, comma) nsepseq par reg (* Function and procedure declarations *) -and fun_decl = { - kwd_function : kwd_function; - name : variable; - param : parameters; - colon : colon; - ret_type : type_expr; - kwd_is : kwd_is; - local_decls : local_decl list; - block : block reg; - kwd_with : kwd_with; - return : expr; - terminator : semi option -} +and fun_decl = + BlockFun of { + kwd_function : kwd_function; + name : variable; + param : parameters; + colon : colon; + ret_type : type_expr; + kwd_is : kwd_is; + local_decls : local_decl list; + block : block reg; + kwd_with : kwd_with; + return : expr; + terminator : semi option } + | BlocklessFun of + { kwd_function : kwd_function; + name : variable; + param : parameters; + colon : colon; + ret_type : type_expr; + kwd_is : kwd_is; + kwd_expr : kwd_expr; + return : expr; + terminator : semi option } and parameters = (param_decl, semi) nsepseq par reg diff --git a/src/passes/1-parser/pascaligo/AST.mli b/src/passes/1-parser/pascaligo/AST.mli index e18903f55..1e3719845 100644 --- a/src/passes/1-parser/pascaligo/AST.mli +++ b/src/passes/1-parser/pascaligo/AST.mli @@ -33,6 +33,7 @@ type kwd_contains = Region.t type kwd_down = Region.t type kwd_else = Region.t type kwd_end = Region.t +type kwd_expr = Region.t type kwd_for = Region.t type kwd_from = Region.t type kwd_function = Region.t @@ -201,19 +202,29 @@ and type_tuple = (type_expr, comma) nsepseq par reg (* Function declarations *) -and fun_decl = { - kwd_function : kwd_function; - name : variable; - param : parameters; - colon : colon; - ret_type : type_expr; - kwd_is : kwd_is; - local_decls : local_decl list; - block : block reg; - kwd_with : kwd_with; - return : expr; - terminator : semi option -} +and fun_decl = + BlockFun of { + kwd_function : kwd_function; + name : variable; + param : parameters; + colon : colon; + ret_type : type_expr; + kwd_is : kwd_is; + local_decls : local_decl list; + block : block reg; + kwd_with : kwd_with; + return : expr; + terminator : semi option } + | BlocklessFun of + { kwd_function : kwd_function; + name : variable; + param : parameters; + colon : colon; + ret_type : type_expr; + kwd_is : kwd_is; + kwd_expr : kwd_expr; + return : expr; + terminator : semi option } and parameters = (param_decl, semi) nsepseq par reg diff --git a/src/passes/1-parser/pascaligo/ParToken.mly b/src/passes/1-parser/pascaligo/ParToken.mly index c236def9e..c5372008e 100644 --- a/src/passes/1-parser/pascaligo/ParToken.mly +++ b/src/passes/1-parser/pascaligo/ParToken.mly @@ -53,6 +53,7 @@ %token Contains (* "contains" *) %token Else (* "else" *) %token End (* "end" *) +%token Expr (* "expr" *) %token For (* "for" *) %token Function (* "function" *) %token From (* "from" *) diff --git a/src/passes/1-parser/pascaligo/Parser.mly b/src/passes/1-parser/pascaligo/Parser.mly index 6c367e186..fc4456c40 100644 --- a/src/passes/1-parser/pascaligo/Parser.mly +++ b/src/passes/1-parser/pascaligo/Parser.mly @@ -263,7 +263,7 @@ fun_decl: kwd_with = $9; return = $10; terminator = $11} - in {region; value}} + in BlockFun {region; value}} | Function fun_name parameters COLON type_expr Is Expr expr option(SEMI) { let stop = @@ -279,10 +279,10 @@ fun_decl: ret_type = $5; kwd_is = $6; kwd_expr = $7; - expr = $8; + return = $8; terminator = $9; } - in {region; value}} + in BlocklessFun {region; value}} parameters: par(nsepseq(param_decl,SEMI)) { $1 }