Skip to content

Commit

Permalink
fix the syntax in example -- use pure () instead of =>
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Mar 11, 2024
1 parent 3eb36f0 commit 40d8f0e
Showing 1 changed file with 28 additions and 67 deletions.
95 changes: 28 additions & 67 deletions docs/grammar/cicada.grammar
Original file line number Diff line number Diff line change
@@ -1,68 +1,29 @@
(define-grammar <operator>
(var (let name identifier))
(ap (let target operator)
(let arg-entries-group (one-or-more "(" arg-entries ")")))
(sequence-begin (let sequence sequence))
(car "car" "(" (let target exp) ")")
(cdr "cdr" "(" (let target exp) ")")
(dot-field (let target operator) "." (let name identifier))
(dot-method
(let target operator) "." (let name identifier)
(let arg-entries-group (one-or-more "(" arg-entries ")")))
(recursion
"recursion" "(" (let target exp) ")"
"{" (let case-entries (zero-or-more case-entry)) "}")
(induction
"induction" "(" (let target exp) ")"
"{" "motive" (let motive "exp")
(let case-entries (zero-or-more case-entry)) "}"))

(define-grammar <operator>
[var (let name <identifier>) => (Exp::Var (match-string name))]
[ap (let target <operator>)
(let arg-entries-group (one-or-more "(" <arg-entries> ")"))
=> (Exp::Ap (match <exp> target)
(match-list ...))]
[sequence-begin (let sequence <sequence>)
=> (Exp::Sequence (match <sequence> sequence))]
[car "car" "(" (let target <exp>) ")"
=> (Exp::Car (match <exp> target))]
[cdr "cdr" "(" (let target <exp>) ")"
=> (Exp::Cdr (match <exp> target))]
[dot-field (let target <operator>) "." (let name <identifier>)
=> (Exp::Dot (match <exp> target) (match <identifier> name))]
[dot-method
(let target <operator>) "." (let name <identifier>)
(let arg-entries-group (one-or-more "(" <arg-entries> ")"))]
[recursion
"recursion" "(" (let target <exp>) ")"
"{" (let case-entries (zero-or-more <case-entry>)) "}"]
[induction
"induction" "(" (let target exp) ")"
"{" "motive" (let motive "exp")
(let case-entries (zero-or-more <case-entry>)) "}"])

(define-grammar <operator>
[var (let name <identifier>) => (Exp::Var name)]
[ap (let target <operator>)
(let arg-entries-group (one-or-more "(" <arg-entries> ")"))
=> (Exp::Ap target
(TODO arg-entries-group))]
[sequence-begin (let sequence <sequence>)
=> (Exp::Sequence sequence)]
[car "car" "(" (let target <exp>) ")"
=> (Exp::Car target)]
[cdr "cdr" "(" (let target <exp>) ")"
=> (Exp::Cdr target)]
[dot-field (let target <operator>) "." (let name <identifier>)
=> (Exp::Dot target name)]
[dot-method
(let target <operator>) "." (let name <identifier>)
(let arg-entries-group (one-or-more "(" <arg-entries> ")"))]
[recursion
"recursion" "(" (let target <exp>) ")"
"{" (let case-entries (zero-or-more <case-entry>)) "}"]
[induction
"induction" "(" (let target exp) ")"
"{" "motive" (let motive "exp")
(let case-entries (zero-or-more <case-entry>)) "}"])
((<operator::var> (let name <identifier>))
(Exp::Var name))
((<operator::ap>
(let target <operator>)
(let arg-entries-group (one-or-more "(" <arg-entries> ")")))
(Exp::ApUnfolded target (flatten arg-entries-group)))
((<operator::sequence-begin> (let sequence <sequence>))
(Exp::Sequence sequence))
((<operator::car> "car" "(" (let target <exp>) ")")
(Exp::Car target))
((<operator::cdr> "cdr" "(" (let target <exp>) ")")
(Exp::Cdr target))
((<operator::dot-field>
(let target <operator>) "." (let name <identifier>))
(Exp::Dot target name))
((<operator::dot-method>
(let target <operator>) "." (let name <identifier>)
(let arg-entries-group (one-or-more "(" <arg-entries> ")")))
(Exp::ApUnfolded (Exp::Dot target name) (flatten arg-entries-group)))
((<operator::recursion>
"recursion" "(" (let target <exp>) ")"
"{" (let case-entries (zero-or-more <case-entry>)) "}")
(Exp::Recursion target case-entries))
((<operator::induction>
"induction" "(" (let target <exp>) ")"
"{" "motive" (let motive <exp>)
(let case-entries (zero-or-more <case-entry>)) "}")
(Exp::Induction target motive case-entries)))

0 comments on commit 40d8f0e

Please sign in to comment.