Skip to content

Commit

Permalink
Separate grammar string from parser object
Browse files Browse the repository at this point in the history
  • Loading branch information
respatialized committed Aug 3, 2024
1 parent f561b4f commit 1e4d9d2
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/site/fabricate/prototype/read/grammar.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,25 @@

(def delimiters ["" "🔚"])

(def template
(def grammar
"The formal grammar for Fabricate templates."
(insta/parser
(format
"template = EPSILON | ( expr | txt | extended-form )*
initial = '✳' var-settings?
terminal = '🔚' var-settings?
(* Unicode range for variation settings used by Apple in the Private Use Area *)
var-settings = #'[\\uFE00-\\uFE0F]'
ctrl = ('=' | '+' | '+=')
expr = <initial> !'//' ctrl? #'[^=+][^🔚]*' !'//' <terminal>
txt = #'%s'
(format
"template = EPSILON | ( expr | txt | extended-form )*
initial = '✳' var-settings?
terminal = '🔚' var-settings?
(* Unicode range for variation settings used by Apple in the Private Use Area *)
var-settings = #'[\\uFE00-\\uFE0F]'
ctrl = ('=' | '+' | '+=')
expr = <initial> !'//' ctrl? #'[^=+][^🔚]*' !'//' <terminal>
txt = #'%s'
(* extended forms allow arbitrary nesting without breaking the flow *)
form-contents = (expr|txt|extended-form)+
extended-form = (<initial> <'//'> '[' #'[^\n✳🔚]*' <'\n'> form-contents ']' <'//'> <terminal>) |
(<initial> <'//'> '(' #'[^\n✳🔚]*' <'\n'> form-contents ')' <'//'> <terminal>) |
(<initial> <'//'> '{' #'[^\n✳🔚]*' <'\n'> form-contents '}' <'//'> <terminal>)"
txt-insta-regex))

(* extended forms allow arbitrary nesting without breaking the flow *)
form-contents = (expr|txt|extended-form)+
extended-form = (<initial> <'//'> '[' #'[^\n✳🔚]*' <'\n'> form-contents ']' <'//'> <terminal>) |
(<initial> <'//'> '(' #'[^\n✳🔚]*' <'\n'> form-contents ')' <'//'> <terminal>) |
(<initial> <'//'> '{' #'[^\n✳🔚]*' <'\n'> form-contents '}' <'//'> <terminal>)"
txt-insta-regex)))
(def template
"An Instaparse parser for Fabricate templates."
(insta/parser grammar))

0 comments on commit 1e4d9d2

Please sign in to comment.