Compare commits
No commits in common. "c5d04ddd6694721e277672384d7d4fd730a404d3" and "4f16cf5cb06d5e5ecd2d02a5a261332b3bf7c165" have entirely different histories.
c5d04ddd66
...
4f16cf5cb0
|
@ -161,15 +161,16 @@
|
||||||
|
|
||||||
(defn- nill [parser]
|
(defn- nill [parser]
|
||||||
(expect parser :nil)
|
(expect parser :nil)
|
||||||
(def curr (current parser))
|
|
||||||
(advance parser)
|
(advance parser)
|
||||||
{:type :nil :token curr})
|
{:type :nil :token (current parser)}
|
||||||
|
)
|
||||||
|
|
||||||
(defn- str [parser]
|
(defn- str [parser]
|
||||||
(expect parser :string)
|
(expect parser :string)
|
||||||
(def curr (-> parser current))
|
(def curr (-> parser current))
|
||||||
(advance parser)
|
(advance parser)
|
||||||
{:type :string :data (curr :literal) :token curr})
|
{:type :string :data (curr :literal) :token curr}
|
||||||
|
)
|
||||||
|
|
||||||
# words & synthetic expressions
|
# words & synthetic expressions
|
||||||
(def separates [:break :newline :comma])
|
(def separates [:break :newline :comma])
|
||||||
|
@ -310,44 +311,6 @@
|
||||||
ast)
|
ast)
|
||||||
|
|
||||||
### patterns
|
### 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
|
### conditional forms
|
||||||
# if {simple} then {nonbinding} else {nonbinding}
|
# if {simple} then {nonbinding} else {nonbinding}
|
||||||
|
@ -375,7 +338,6 @@
|
||||||
(while (terminates? parser) (advance parser)))
|
(while (terminates? parser) (advance parser)))
|
||||||
|
|
||||||
# {simple} -> {nonbinding} {terminator}
|
# {simple} -> {nonbinding} {terminator}
|
||||||
### TODO: add placeholder as valid lhs
|
|
||||||
(defn- when-clause [parser]
|
(defn- when-clause [parser]
|
||||||
(try
|
(try
|
||||||
(do
|
(do
|
||||||
|
@ -551,12 +513,18 @@
|
||||||
(import ./scanner :as s)
|
(import ./scanner :as s)
|
||||||
(do
|
(do
|
||||||
#(comment
|
#(comment
|
||||||
(def source `"foo {bar} \{baz"`)
|
(def source `when {
|
||||||
|
a -> b
|
||||||
|
foo -> bar quux
|
||||||
|
-> baz
|
||||||
|
c -> d
|
||||||
|
}
|
||||||
|
`)
|
||||||
(def scanned (s/scan source))
|
(def scanned (s/scan source))
|
||||||
# (def a-parser (new-parser scanned))
|
(def a-parser (new-parser scanned))
|
||||||
# (def parsed (whenn a-parser))
|
(def parsed (whenn a-parser))
|
||||||
# (-> parsed)
|
(-> parsed)
|
||||||
(first (scanned :tokens))
|
# (map (fn [t] (t :type)) (scanned :tokens))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -187,6 +187,7 @@
|
||||||
:else (add-error scanner (string "Unexpected " curr " after number " num ".")))))
|
:else (add-error scanner (string "Unexpected " curr " after number " num ".")))))
|
||||||
(recur scanner (buffer char) false))
|
(recur scanner (buffer char) false))
|
||||||
|
|
||||||
|
## TODO: activate string interpolation
|
||||||
(defn- add-string
|
(defn- add-string
|
||||||
[scanner]
|
[scanner]
|
||||||
(print "Adding string")
|
(print "Adding string")
|
||||||
|
@ -196,10 +197,9 @@
|
||||||
"{" (recur (advance scanner) (buffer/push buff char) true)
|
"{" (recur (advance scanner) (buffer/push buff char) true)
|
||||||
# allow multiline strings
|
# allow multiline strings
|
||||||
"\n" (recur (update (advance scanner) :line inc) (buffer/push buff char) interpolate?)
|
"\n" (recur (update (advance scanner) :line inc) (buffer/push buff char) interpolate?)
|
||||||
"\"" (add-token (advance scanner) (if interpolate? :interpolated :string)(string buff))
|
### TODO: add interpolated strings
|
||||||
### FIXME: Actually add the escaped character to the string;
|
### :string -> (if (interpolate? :interpolated :string))
|
||||||
### The only weird escapy-thing is actually the lbrace
|
"\"" (add-token (advance scanner) :string (string buff))
|
||||||
### So only do anything fancy if the next char is "{"
|
|
||||||
"\\" (let [next (next-char scanner)
|
"\\" (let [next (next-char scanner)
|
||||||
scanner (if (= next "\n")
|
scanner (if (= next "\n")
|
||||||
(update scanner :line inc)
|
(update scanner :line inc)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user