fix nil parser bug, start work on patterns
This commit is contained in:
parent
4f16cf5cb0
commit
736f1024c3
|
@ -161,16 +161,15 @@
|
|||
|
||||
(defn- nill [parser]
|
||||
(expect parser :nil)
|
||||
(def curr (current parser))
|
||||
(advance parser)
|
||||
{:type :nil :token (current parser)}
|
||||
)
|
||||
{:type :nil :token curr})
|
||||
|
||||
(defn- str [parser]
|
||||
(expect parser :string)
|
||||
(def curr (-> parser current))
|
||||
(advance parser)
|
||||
{:type :string :data (curr :literal) :token curr}
|
||||
)
|
||||
{:type :string :data (curr :literal) :token curr})
|
||||
|
||||
# words & synthetic expressions
|
||||
(def separates [:break :newline :comma])
|
||||
|
@ -311,6 +310,32 @@
|
|||
ast)
|
||||
|
||||
### patterns
|
||||
(declare pattern)
|
||||
|
||||
(defn- placeholder [parser]
|
||||
(expect parser :placeholder :ignored)
|
||||
(def origin (current parser))
|
||||
(advance parser)
|
||||
{:type :placeholder :token origin})
|
||||
|
||||
(defn- word-pattern [parser]
|
||||
(expect parser :word)
|
||||
(def origin (current parser))
|
||||
(advance parser)
|
||||
{:type :word :data (origin :lexeme) :token origin})
|
||||
|
||||
(defrec pattern [parser]
|
||||
(case (-> parser current type)
|
||||
:nil (nill parser)
|
||||
:true (bool parser)
|
||||
:false (bool parser)
|
||||
:keyword (kw parser)
|
||||
:number (number parser)
|
||||
:word (word-pattern parser)
|
||||
:placeholder (placeholder parser)
|
||||
|
||||
)
|
||||
)
|
||||
|
||||
### conditional forms
|
||||
# if {simple} then {nonbinding} else {nonbinding}
|
||||
|
@ -338,6 +363,7 @@
|
|||
(while (terminates? parser) (advance parser)))
|
||||
|
||||
# {simple} -> {nonbinding} {terminator}
|
||||
### TODO: add placeholder as valid lhs
|
||||
(defn- when-clause [parser]
|
||||
(try
|
||||
(do
|
||||
|
|
Loading…
Reference in New Issue
Block a user