Further streamlining PascaLIGO and Ligodity parsers.
This commit is contained in:
parent
2a44e0f084
commit
295f94a09a
@ -3,47 +3,8 @@
|
|||||||
|
|
||||||
open AST
|
open AST
|
||||||
|
|
||||||
(* Rewrite "let pattern = e" as "let x = e;; let x1 = ...;; let x2 = ...;;" *)
|
|
||||||
|
|
||||||
(*
|
|
||||||
module VMap = Utils.String.Map
|
|
||||||
|
|
||||||
let ghost_of value = Region.{region=ghost; value}
|
|
||||||
*)
|
|
||||||
|
|
||||||
let ghost = Region.ghost
|
let ghost = Region.ghost
|
||||||
|
|
||||||
(* let fail_syn_unif type1 type2 : 'a =
|
|
||||||
let reg = AST.region_of_type_expr type1 in
|
|
||||||
let reg = reg#compact ~file:false `Byte in
|
|
||||||
let value =
|
|
||||||
Printf.sprintf "Unification with %s is not\
|
|
||||||
implemented." reg in
|
|
||||||
let region = AST.region_of_type_expr type2 in
|
|
||||||
let err = Region.{value; region} in
|
|
||||||
(Lexer.prerr ~kind:"Syntactical" err; exit 1)
|
|
||||||
|
|
||||||
let mk_component rank =
|
|
||||||
let num = string_of_int rank, Z.of_int rank in
|
|
||||||
let par = {lpar=ghost; inside = ghost_of num; rpar=ghost}
|
|
||||||
in Component (ghost_of par)
|
|
||||||
|
|
||||||
|
|
||||||
let rec mk_field_path (rank, tail) =
|
|
||||||
let head = mk_component rank in
|
|
||||||
match tail with
|
|
||||||
[] -> head, []
|
|
||||||
| hd::tl -> mk_field_path (hd,tl) |> Utils.nsepseq_cons head ghost
|
|
||||||
|
|
||||||
let mk_projection fresh (path : int Utils.nseq) = {
|
|
||||||
struct_name = fresh;
|
|
||||||
selector = ghost;
|
|
||||||
field_path = Utils.nsepseq_rev (mk_field_path path)
|
|
||||||
} *)
|
|
||||||
|
|
||||||
|
|
||||||
(* We rewrite "fun p -> e" into "fun x -> match x with p -> e" *)
|
|
||||||
|
|
||||||
(* END HEADER *)
|
(* END HEADER *)
|
||||||
%}
|
%}
|
||||||
|
|
||||||
@ -53,7 +14,6 @@ let rec mk_field_path (rank, tail) =
|
|||||||
%start program interactive_expr
|
%start program interactive_expr
|
||||||
%type <AST.t> program
|
%type <AST.t> program
|
||||||
%type <AST.expr> interactive_expr
|
%type <AST.expr> interactive_expr
|
||||||
(*%type <('item,'sep) sep_or_term_list> sep_or_term_list*)
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
@ -21,33 +21,22 @@ open AST
|
|||||||
|
|
||||||
(* RULES *)
|
(* RULES *)
|
||||||
|
|
||||||
(* The rule [series(Item,TERM)] parses a non-empty list of [Item]
|
(* The rule [sep_or_term(item,sep)] ("separated or terminated list")
|
||||||
separated by semicolons and optionally terminated by a semicolon,
|
parses a non-empty list of items separated by [sep], and optionally
|
||||||
then the terminal TERM. *)
|
terminated by [sep]. *)
|
||||||
|
|
||||||
series(Item,TERM):
|
sep_or_term_list(item,sep):
|
||||||
Item after_item(Item,TERM) { $1,$2 }
|
nsepseq(item,sep) {
|
||||||
|
$1, None
|
||||||
after_item(Item,TERM):
|
|
||||||
SEMI item_or_closing(Item,TERM) {
|
|
||||||
match $2 with
|
|
||||||
`Some (item, items, term, closing) ->
|
|
||||||
($1, item)::items, term, closing
|
|
||||||
| `Closing closing ->
|
|
||||||
[], Some $1, closing
|
|
||||||
}
|
|
||||||
| TERM {
|
|
||||||
[], None, $1
|
|
||||||
}
|
|
||||||
|
|
||||||
item_or_closing(Item,TERM):
|
|
||||||
TERM {
|
|
||||||
`Closing $1
|
|
||||||
}
|
|
||||||
| series(Item,TERM) {
|
|
||||||
let item, (items, term, closing) = $1
|
|
||||||
in `Some (item, items, term, closing)
|
|
||||||
}
|
}
|
||||||
|
| nseq(item sep {$1,$2}) {
|
||||||
|
let (first,sep), tail = $1 in
|
||||||
|
let rec trans (seq, prev_sep as acc) = function
|
||||||
|
[] -> acc
|
||||||
|
| (item,next_sep)::others ->
|
||||||
|
trans ((prev_sep,item)::seq, next_sep) others in
|
||||||
|
let list, term = trans ([],sep) tail
|
||||||
|
in (first, List.rev list), Some term }
|
||||||
|
|
||||||
(* Compound constructs *)
|
(* Compound constructs *)
|
||||||
|
|
||||||
@ -220,24 +209,24 @@ variant:
|
|||||||
{region=$1.region; value= {constr=$1; args=None}} }
|
{region=$1.region; value= {constr=$1; args=None}} }
|
||||||
|
|
||||||
record_type:
|
record_type:
|
||||||
Record series(field_decl,End) {
|
Record sep_or_term_list(field_decl,SEMI) End {
|
||||||
let first, (others, terminator, closing) = $2 in
|
let elements, terminator = $2 in
|
||||||
let region = cover $1 closing
|
let region = cover $1 $3
|
||||||
and value = {
|
and value = {
|
||||||
opening = Kwd $1;
|
opening = Kwd $1;
|
||||||
elements = Some (first, others);
|
elements = Some elements;
|
||||||
terminator;
|
terminator;
|
||||||
closing = End closing}
|
closing = End $3}
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
| Record LBRACKET series(field_decl,RBRACKET) {
|
| Record LBRACKET sep_or_term_list(field_decl,SEMI) RBRACKET {
|
||||||
let first, (others, terminator, closing) = $3 in
|
let elements, terminator = $3 in
|
||||||
let region = cover $1 closing
|
let region = cover $1 $4
|
||||||
and value = {
|
and value = {
|
||||||
opening = KwdBracket ($1,$2);
|
opening = KwdBracket ($1,$2);
|
||||||
elements = Some (first, others);
|
elements = Some elements;
|
||||||
terminator;
|
terminator;
|
||||||
closing = RBracket closing}
|
closing = RBracket $4}
|
||||||
in {region; value} }
|
in {region; value} }
|
||||||
|
|
||||||
field_decl:
|
field_decl:
|
||||||
@ -369,24 +358,24 @@ param_type:
|
|||||||
cartesian { TProd $1 }
|
cartesian { TProd $1 }
|
||||||
|
|
||||||
block:
|
block:
|
||||||
Begin series(statement,End) {
|
Begin sep_or_term_list(statement,SEMI) End {
|
||||||
let first, (others, terminator, closing) = $2 in
|
let statements, terminator = $2 in
|
||||||
let region = cover $1 closing
|
let region = cover $1 $3
|
||||||
and value = {
|
and value = {
|
||||||
opening = Begin $1;
|
opening = Begin $1;
|
||||||
statements = first, others;
|
statements;
|
||||||
terminator;
|
terminator;
|
||||||
closing = End closing}
|
closing = End $3}
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
| Block LBRACE series(statement,RBRACE) {
|
| Block LBRACE sep_or_term_list(statement,SEMI) RBRACE {
|
||||||
let first, (others, terminator, closing) = $3 in
|
let statements, terminator = $3 in
|
||||||
let region = cover $1 closing
|
let region = cover $1 $4
|
||||||
and value = {
|
and value = {
|
||||||
opening = Block ($1,$2);
|
opening = Block ($1,$2);
|
||||||
statements = first, others;
|
statements;
|
||||||
terminator;
|
terminator;
|
||||||
closing = Block closing}
|
closing = Block $4}
|
||||||
in {region; value}}
|
in {region; value}}
|
||||||
|
|
||||||
statement:
|
statement:
|
||||||
@ -523,14 +512,14 @@ map_patch:
|
|||||||
in {region; value}}
|
in {region; value}}
|
||||||
|
|
||||||
injection(Kind,element):
|
injection(Kind,element):
|
||||||
Kind series(element,End) {
|
Kind sep_or_term_list(element,SEMI) End {
|
||||||
let first, (others, terminator, closing) = $2 in
|
let elements, terminator = $2 in
|
||||||
let region = cover $1 closing
|
let region = cover $1 $3
|
||||||
and value = {
|
and value = {
|
||||||
opening = Kwd $1;
|
opening = Kwd $1;
|
||||||
elements = Some (first, others);
|
elements = Some elements;
|
||||||
terminator;
|
terminator;
|
||||||
closing = End closing}
|
closing = End $3}
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
| Kind End {
|
| Kind End {
|
||||||
@ -542,14 +531,14 @@ injection(Kind,element):
|
|||||||
closing = End $2}
|
closing = End $2}
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
| Kind LBRACKET series(element,RBRACKET) {
|
| Kind LBRACKET sep_or_term_list(element,SEMI) RBRACKET {
|
||||||
let first, (others, terminator, closing) = $3 in
|
let elements, terminator = $3 in
|
||||||
let region = cover $1 closing
|
let region = cover $1 $4
|
||||||
and value = {
|
and value = {
|
||||||
opening = KwdBracket ($1,$2);
|
opening = KwdBracket ($1,$2);
|
||||||
elements = Some (first, others);
|
elements = Some elements;
|
||||||
terminator;
|
terminator;
|
||||||
closing = RBracket closing}
|
closing = RBracket $4}
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
| Kind LBRACKET RBRACKET {
|
| Kind LBRACKET RBRACKET {
|
||||||
@ -562,14 +551,14 @@ injection(Kind,element):
|
|||||||
in {region; value}}
|
in {region; value}}
|
||||||
|
|
||||||
map_injection:
|
map_injection:
|
||||||
Map series(binding,End) {
|
Map sep_or_term_list(binding,SEMI) End {
|
||||||
let first, (others, terminator, closing) = $2 in
|
let elements, terminator = $2 in
|
||||||
let region = cover $1 closing
|
let region = cover $1 $3
|
||||||
and value = {
|
and value = {
|
||||||
opening = Kwd $1;
|
opening = Kwd $1;
|
||||||
elements = Some (first, others);
|
elements = Some elements;
|
||||||
terminator;
|
terminator;
|
||||||
closing = End closing}
|
closing = End $3}
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
| Map End {
|
| Map End {
|
||||||
@ -581,14 +570,14 @@ map_injection:
|
|||||||
closing = End $2}
|
closing = End $2}
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
| Map LBRACKET series(binding,RBRACKET) {
|
| Map LBRACKET sep_or_term_list(binding,SEMI) RBRACKET {
|
||||||
let first, (others, terminator, closing) = $3 in
|
let elements, terminator = $3 in
|
||||||
let region = cover $1 closing
|
let region = cover $1 $4
|
||||||
and value = {
|
and value = {
|
||||||
opening = KwdBracket ($1,$2);
|
opening = KwdBracket ($1,$2);
|
||||||
elements = Some (first, others);
|
elements = Some elements;
|
||||||
terminator;
|
terminator;
|
||||||
closing = RBracket closing}
|
closing = RBracket $4}
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
| Map LBRACKET RBRACKET {
|
| Map LBRACKET RBRACKET {
|
||||||
@ -647,13 +636,12 @@ if_clause:
|
|||||||
instruction {
|
instruction {
|
||||||
ClauseInstr $1
|
ClauseInstr $1
|
||||||
}
|
}
|
||||||
| LBRACE series(statement,RBRACE) {
|
| LBRACE sep_or_term_list(statement,COMMA) RBRACE {
|
||||||
let first, (others, terminator, closing) = $2 in
|
let region = cover $1 $3 in
|
||||||
let region = cover $1 closing in
|
|
||||||
let value = {
|
let value = {
|
||||||
lbrace = $1;
|
lbrace = $1;
|
||||||
inside = (first, others), terminator;
|
inside = $2;
|
||||||
rbrace = closing} in
|
rbrace = $3} in
|
||||||
ClauseBlock {value; region} }
|
ClauseBlock {value; region} }
|
||||||
|
|
||||||
case_instr:
|
case_instr:
|
||||||
@ -997,24 +985,24 @@ selection:
|
|||||||
| Int { Component $1 }
|
| Int { Component $1 }
|
||||||
|
|
||||||
record_expr:
|
record_expr:
|
||||||
Record series(field_assignment,End) {
|
Record sep_or_term_list(field_assignment,SEMI) End {
|
||||||
let first, (others, terminator, closing) = $2 in
|
let elements, terminator = $2 in
|
||||||
let region = cover $1 closing
|
let region = cover $1 $3
|
||||||
and value = {
|
and value = {
|
||||||
opening = Kwd $1;
|
opening = Kwd $1;
|
||||||
elements = Some (first, others);
|
elements = Some elements;
|
||||||
terminator;
|
terminator;
|
||||||
closing = End closing}
|
closing = End $3}
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
| Record LBRACKET series(field_assignment,RBRACKET) {
|
| Record LBRACKET sep_or_term_list(field_assignment,SEMI) RBRACKET {
|
||||||
let first, (others, terminator, closing) = $3 in
|
let elements, terminator = $3 in
|
||||||
let region = cover $1 closing
|
let region = cover $1 $4
|
||||||
and value = {
|
and value = {
|
||||||
opening = KwdBracket ($1,$2);
|
opening = KwdBracket ($1,$2);
|
||||||
elements = Some (first, others);
|
elements = Some elements;
|
||||||
terminator;
|
terminator;
|
||||||
closing = RBracket closing}
|
closing = RBracket $4}
|
||||||
in {region; value} }
|
in {region; value} }
|
||||||
|
|
||||||
field_assignment:
|
field_assignment:
|
||||||
|
Loading…
Reference in New Issue
Block a user