Compare commits
3 Commits
4f16cf5cb0
...
c5d04ddd66
Author | SHA1 | Date | |
---|---|---|---|
|
c5d04ddd66 | ||
|
3466b075af | ||
|
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,44 @@
|
|||
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})
|
||||
|
||||
(defn- tuple-pattern [parser])
|
||||
|
||||
(defn- list-pattern [parser])
|
||||
|
||||
(defn- dict-pattern [parser])
|
||||
|
||||
(defn- string-pattern [parser])
|
||||
|
||||
(defrec pattern [parser]
|
||||
(case (-> parser current type)
|
||||
:nil (nill parser)
|
||||
:true (bool parser)
|
||||
:false (bool parser)
|
||||
:keyword (kw parser)
|
||||
:number (number parser)
|
||||
:string (str parser)
|
||||
:word (word-pattern parser)
|
||||
:placeholder (placeholder parser)
|
||||
:lparen (tuple-pattern parser)
|
||||
:lbracket (list-pattern parser)
|
||||
:startdict (dict-pattern parser)
|
||||
:interpolated (string-pattern parser)
|
||||
(panic parser "expected pattern")
|
||||
))
|
||||
|
||||
### conditional forms
|
||||
# if {simple} then {nonbinding} else {nonbinding}
|
||||
|
@ -338,6 +375,7 @@
|
|||
(while (terminates? parser) (advance parser)))
|
||||
|
||||
# {simple} -> {nonbinding} {terminator}
|
||||
### TODO: add placeholder as valid lhs
|
||||
(defn- when-clause [parser]
|
||||
(try
|
||||
(do
|
||||
|
@ -513,18 +551,12 @@
|
|||
(import ./scanner :as s)
|
||||
(do
|
||||
#(comment
|
||||
(def source `when {
|
||||
a -> b
|
||||
foo -> bar quux
|
||||
-> baz
|
||||
c -> d
|
||||
}
|
||||
`)
|
||||
(def source `"foo {bar} \{baz"`)
|
||||
(def scanned (s/scan source))
|
||||
(def a-parser (new-parser scanned))
|
||||
(def parsed (whenn a-parser))
|
||||
(-> parsed)
|
||||
# (map (fn [t] (t :type)) (scanned :tokens))
|
||||
# (def a-parser (new-parser scanned))
|
||||
# (def parsed (whenn a-parser))
|
||||
# (-> parsed)
|
||||
(first (scanned :tokens))
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -187,7 +187,6 @@
|
|||
:else (add-error scanner (string "Unexpected " curr " after number " num ".")))))
|
||||
(recur scanner (buffer char) false))
|
||||
|
||||
## TODO: activate string interpolation
|
||||
(defn- add-string
|
||||
[scanner]
|
||||
(print "Adding string")
|
||||
|
@ -197,9 +196,10 @@
|
|||
"{" (recur (advance scanner) (buffer/push buff char) true)
|
||||
# allow multiline strings
|
||||
"\n" (recur (update (advance scanner) :line inc) (buffer/push buff char) interpolate?)
|
||||
### TODO: add interpolated strings
|
||||
### :string -> (if (interpolate? :interpolated :string))
|
||||
"\"" (add-token (advance scanner) :string (string buff))
|
||||
"\"" (add-token (advance scanner) (if interpolate? :interpolated :string)(string buff))
|
||||
### FIXME: Actually add the escaped character to the string;
|
||||
### The only weird escapy-thing is actually the lbrace
|
||||
### So only do anything fancy if the next char is "{"
|
||||
"\\" (let [next (next-char scanner)
|
||||
scanner (if (= next "\n")
|
||||
(update scanner :line inc)
|
||||
|
|
Loading…
Reference in New Issue
Block a user