Reindent--clean up
This commit is contained in:
parent
aa7f2ac8fc
commit
3d080403dc
|
@ -88,8 +88,8 @@
|
||||||
|
|
||||||
(defn- expect* [tokens message parser]
|
(defn- expect* [tokens message parser]
|
||||||
(let [curr (current parser)
|
(let [curr (current parser)
|
||||||
tokens (if (set? tokens) tokens #{tokens})
|
tokens (if (set? tokens) tokens #{tokens})
|
||||||
type (::token/type curr)]
|
type (::token/type curr)]
|
||||||
(if (contains? tokens type)
|
(if (contains? tokens type)
|
||||||
{:success true :parser (advance parser)}
|
{:success true :parser (advance parser)}
|
||||||
{:success false :parser (panic (advance parser) message)}
|
{:success false :parser (panic (advance parser) message)}
|
||||||
|
@ -337,7 +337,7 @@
|
||||||
|
|
||||||
(defn- parse-assignment [parser]
|
(defn- parse-assignment [parser]
|
||||||
(let [assignment (expect* ::token/equals "Expected assignment" parser)
|
(let [assignment (expect* ::token/equals "Expected assignment" parser)
|
||||||
success (:success assignment)]
|
success (:success assignment)]
|
||||||
(if success
|
(if success
|
||||||
(parse-let-expr (:parser assignment) parser)
|
(parse-let-expr (:parser assignment) parser)
|
||||||
(panic parser "Expected assignment"))))
|
(panic parser "Expected assignment"))))
|
||||||
|
@ -356,29 +356,29 @@
|
||||||
|
|
||||||
(defn- parse-else [parser]
|
(defn- parse-else [parser]
|
||||||
(let [ast (::ast parser)
|
(let [ast (::ast parser)
|
||||||
else-kw (expect* ::token/else "Expected else clause after then" parser)
|
else-kw (expect* ::token/else "Expected else clause after then" parser)
|
||||||
success (:success else-kw)
|
success (:success else-kw)
|
||||||
else-kw-parser (:parser else-kw)]
|
else-kw-parser (:parser else-kw)]
|
||||||
(if success
|
(if success
|
||||||
(let [expr (parse-expr else-kw-parser)
|
(let [expr (parse-expr else-kw-parser)
|
||||||
else-expr (::ast expr)]
|
else-expr (::ast expr)]
|
||||||
(assoc expr ::ast (assoc ast :else else-expr)))
|
(assoc expr ::ast (assoc ast :else else-expr)))
|
||||||
else-kw-parser)))
|
else-kw-parser)))
|
||||||
|
|
||||||
(defn- parse-then [parser]
|
(defn- parse-then [parser]
|
||||||
(let [ast (::ast parser)
|
(let [ast (::ast parser)
|
||||||
then-kw (expect* ::token/then "Expected then clause after if" parser)
|
then-kw (expect* ::token/then "Expected then clause after if" parser)
|
||||||
success (:success then-kw)
|
success (:success then-kw)
|
||||||
then-kw-parser (:parser then-kw)]
|
then-kw-parser (:parser then-kw)]
|
||||||
(if success
|
(if success
|
||||||
(let [expr (parse-expr then-kw-parser (conj sync-on ::token/else))
|
(let [expr (parse-expr then-kw-parser (conj sync-on ::token/else))
|
||||||
then-expr (::ast expr)]
|
then-expr (::ast expr)]
|
||||||
(parse-else (accept ::token/newline (assoc expr ::ast (assoc ast :then then-expr)))))
|
(parse-else (accept ::token/newline (assoc expr ::ast (assoc ast :then then-expr)))))
|
||||||
then-kw-parser)))
|
then-kw-parser)))
|
||||||
|
|
||||||
(defn- parse-if* [parser]
|
(defn- parse-if* [parser]
|
||||||
(let [if-expr (parse-expr (advance parser) #{::token/newline ::token/then})
|
(let [if-expr (parse-expr (advance parser) #{::token/newline ::token/then})
|
||||||
ast (assoc if-expr ::ast {::ast/type ::ast/if :if (::ast if-expr)})]
|
ast (assoc if-expr ::ast {::ast/type ::ast/if :if (::ast if-expr)})]
|
||||||
(parse-then (accept ::token/newline ast))
|
(parse-then (accept ::token/newline ast))
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@ -405,49 +405,49 @@
|
||||||
(defn- parse-expr
|
(defn- parse-expr
|
||||||
([parser] (parse-expr parser sync-on))
|
([parser] (parse-expr parser sync-on))
|
||||||
([parser sync-on] (let [token (current parser)]
|
([parser sync-on] (let [token (current parser)]
|
||||||
(case (::token/type token)
|
(case (::token/type token)
|
||||||
|
|
||||||
(::token/number ::token/string)
|
(::token/number ::token/string)
|
||||||
(parse-atom parser)
|
(parse-atom parser)
|
||||||
|
|
||||||
::token/keyword (let [next (peek parser)
|
::token/keyword (let [next (peek parser)
|
||||||
type (::token/type next)]
|
type (::token/type next)]
|
||||||
(if (= type ::token/lparen)
|
(if (= type ::token/lparen)
|
||||||
(parse-synthetic parser)
|
(parse-synthetic parser)
|
||||||
(parse-atom parser)))
|
(parse-atom parser)))
|
||||||
|
|
||||||
::token/word (let [next (peek parser)
|
::token/word (let [next (peek parser)
|
||||||
type (::token/type next)]
|
type (::token/type next)]
|
||||||
(case type
|
(case type
|
||||||
(::token/lparen ::token/keyword) (parse-synthetic parser)
|
(::token/lparen ::token/keyword) (parse-synthetic parser)
|
||||||
(parse-word parser)))
|
(parse-word parser)))
|
||||||
|
|
||||||
(::token/nil ::token/true ::token/false)
|
(::token/nil ::token/true ::token/false)
|
||||||
(parse-atomic-word parser)
|
(parse-atomic-word parser)
|
||||||
|
|
||||||
::token/lparen (parse-tuple parser)
|
::token/lparen (parse-tuple parser)
|
||||||
|
|
||||||
::token/lbracket (parse-list parser)
|
::token/lbracket (parse-list parser)
|
||||||
|
|
||||||
::token/startset (parse-set parser)
|
::token/startset (parse-set parser)
|
||||||
|
|
||||||
::token/lbrace (parse-block parser)
|
::token/lbrace (parse-block parser)
|
||||||
|
|
||||||
::token/let (parse-let* parser)
|
::token/let (parse-let* parser)
|
||||||
|
|
||||||
::token/if (parse-if* parser)
|
::token/if (parse-if* parser)
|
||||||
|
|
||||||
::token/error (panic parser (:message token) sync-on)
|
::token/error (panic parser (:message token) sync-on)
|
||||||
|
|
||||||
(::token/rparen ::token/rbrace ::token/rbracket)
|
(::token/rparen ::token/rbrace ::token/rbracket)
|
||||||
(panic parser (str "Unbalanced enclosure: " (::token/lexeme token)))
|
(panic parser (str "Unbalanced enclosure: " (::token/lexeme token)))
|
||||||
|
|
||||||
(::token/semicolon ::token/comma)
|
(::token/semicolon ::token/comma)
|
||||||
(panic parser (str "Unexpected delimiter: " (::token/lexeme token)))
|
(panic parser (str "Unexpected delimiter: " (::token/lexeme token)))
|
||||||
|
|
||||||
(panic parser "Expected expression" sync-on)
|
(panic parser "Expected expression" sync-on)
|
||||||
|
|
||||||
))))
|
))))
|
||||||
|
|
||||||
(do
|
(do
|
||||||
(def pp pp/pprint)
|
(def pp pp/pprint)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user