From a629b2a96762af1a81af869251a5a8d50e1fd4d7 Mon Sep 17 00:00:00 2001 From: sneeker Date: Sun, 29 May 2022 08:59:55 +0000 Subject: [PATCH] feat(ast): model statements, blocks and nested conditionals Keeps written order, so a later branch can observe the result of a check that appeared earlier in the file. --- lib/ast.ml | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 lib/ast.ml diff --git a/lib/ast.ml b/lib/ast.ml new file mode 100644 index 0000000..685427d --- /dev/null +++ b/lib/ast.ml @@ -0,0 +1,45 @@ +type value = { text : string; span : Span.t; quoted : bool } + +type expr = + | Atom of value + | Not of expr * Span.t + | And of expr * expr + | Or of expr * expr + | Cmp of value * string * value + +type field = { key : string; kspan : Span.t; values : value list } + +type fitem = + | FField of field + | FIf of (expr * fitem list) list * fitem list + +type block = { + kind : string; + kspan : Span.t; + bname : string; + nspan : Span.t; + items : fitem list; +} + +type check = + | Header of value + | Func of value * value option + | Symbol of value * value + | Sizeof of value + | Compiles of value * value + +type stmt = + | Project of value + | Set of value * value list + | Append of value * value list + | Option of value * value * value list + | Include of value + | Subdir of value + | If of (expr * stmt list) list * stmt list + | Check of check * Span.t + | Pkg of value * value option * Span.t + | ConfigHeader of value + | Message of value * value list + | Blk of block + +let v text span = { text; span; quoted = false }