Parse records and keyed collection queries
This commit is contained in:
11 files changed
+324
-4
No files matched your search
@@ -32,9 +32,67 @@ and expr_desc =
|
||||
| ETuple of expr list
|
||||
| ERecord of (string * expr) list
|
||||
| EField of expr * string
|
||||
| EFilter of expr
|
||||
| EMap of expr
|
||||
| ESum
|
||||
| ECount
|
||||
|
||||
type tyexpr = {
|
||||
ty : tyexpr_desc;
|
||||
tyspan : Location.span;
|
||||
}
|
||||
|
||||
and tyexpr_desc =
|
||||
| TyName of string
|
||||
| TyCollection of tyexpr
|
||||
| TyTuple of tyexpr list
|
||||
|
||||
type record_decl = {
|
||||
rd_name : string;
|
||||
rd_name_span : Location.span;
|
||||
rd_fields : (string * tyexpr) list;
|
||||
rd_span : Location.span;
|
||||
}
|
||||
|
||||
type input_decl = {
|
||||
in_name : string;
|
||||
in_name_span : Location.span;
|
||||
in_ty : tyexpr;
|
||||
in_span : Location.span;
|
||||
}
|
||||
|
||||
type helper = {
|
||||
h_name : string;
|
||||
h_name_span : Location.span;
|
||||
h_params : string list;
|
||||
h_body : expr;
|
||||
h_span : Location.span;
|
||||
}
|
||||
|
||||
type query = {
|
||||
q_name : string;
|
||||
q_name_span : Location.span;
|
||||
q_body : expr;
|
||||
q_span : Location.span;
|
||||
}
|
||||
|
||||
type declaration =
|
||||
| DRecord of record_decl
|
||||
| DInput of input_decl
|
||||
| DHelper of helper
|
||||
| DQuery of query
|
||||
|
||||
type program = {
|
||||
prog_records : record_decl list;
|
||||
prog_input : input_decl;
|
||||
prog_helpers : helper list;
|
||||
prog_query : query;
|
||||
}
|
||||
|
||||
let make e espan = { e = e; espan = espan }
|
||||
|
||||
let make_ty ty tyspan = { ty = ty; tyspan = tyspan }
|
||||
|
||||
let binop_name = function
|
||||
| Add -> "+"
|
||||
| Sub -> "-"
|
||||
@@ -50,3 +108,9 @@ let binop_name = function
|
||||
| Or -> "||"
|
||||
|
||||
let string_of_binop = binop_name
|
||||
|
||||
let rec string_of_tyexpr tyexpr =
|
||||
match tyexpr.ty with
|
||||
| TyName name -> name
|
||||
| TyCollection element -> "collection " ^ string_of_tyexpr element
|
||||
| TyTuple elements -> "(" ^ String.concat ", " (List.map string_of_tyexpr elements) ^ ")"
|
||||
Reference in new issue
Block a user