aboutsummaryrefslogtreecommitdiff
path: root/lib/render/template.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/render/template.ml')
-rw-r--r--lib/render/template.ml18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/render/template.ml b/lib/render/template.ml
index 8de91a6..3e35d53 100644
--- a/lib/render/template.ml
+++ b/lib/render/template.ml
@@ -38,13 +38,23 @@ let lex src =
let b = trim body in
if b = "" then Error "empty tag {{}}"
else
+ (* Every sigil form (var, #, ^, /) resolves a dotted path; an
+ empty path ("{{.}}", "{{#}}", "{{^}}", "{{/}}") names
+ nothing -- there is no "current context" concept for a bare
+ dot to mean, so it is a parse error rather than an invented
+ behaviour Task 3 would have to define. *)
+ let with_path ctor rest =
+ match path rest with
+ | [] -> Error "empty tag path: {{.}} and {{#}} name nothing"
+ | p -> Ok (ctor p)
+ in
match b.[0] with
- | '#' -> Ok (TOpen (path (String.sub b 1 (String.length b - 1))))
- | '^' -> Ok (TInv (path (String.sub b 1 (String.length b - 1))))
- | '/' -> Ok (TClose (path (String.sub b 1 (String.length b - 1))))
+ | '#' -> with_path (fun p -> TOpen p) (String.sub b 1 (String.length b - 1))
+ | '^' -> with_path (fun p -> TInv p) (String.sub b 1 (String.length b - 1))
+ | '/' -> with_path (fun p -> TClose p) (String.sub b 1 (String.length b - 1))
| '!' -> Ok TComment
| '>' -> Error "partials are not supported: a template may not include another file"
- | _ -> Ok (TVar (path b))
+ | _ -> with_path (fun p -> TVar p) b
in
(match tag with
| Error e -> Error e