finally fix script, block, tuple, list, dict, etc. off by one errors for last term
This commit is contained in:
parent
e9fee4c0e1
commit
4a069278b8
|
@ -305,7 +305,9 @@
|
||||||
(advance parser) # consume the :lparen
|
(advance parser) # consume the :lparen
|
||||||
(def ast @{:type :args :data @[] :token origin :partial false})
|
(def ast @{:type :args :data @[] :token origin :partial false})
|
||||||
(while (not (check parser :rparen))
|
(while (not (check parser :rparen))
|
||||||
(accept-many parser ;separates)
|
(accept-many parser :newline :comma)
|
||||||
|
(when (= :break ((current parser) :type))
|
||||||
|
(break (advance parser)))
|
||||||
(when (check parser :eof)
|
(when (check parser :eof)
|
||||||
(def err {:type :error :token origin :msg "unclosed paren"})
|
(def err {:type :error :token origin :msg "unclosed paren"})
|
||||||
(array/push (parser :errors) err)
|
(array/push (parser :errors) err)
|
||||||
|
@ -367,7 +369,9 @@
|
||||||
(advance parser) # consume the :lparen
|
(advance parser) # consume the :lparen
|
||||||
(def ast {:type :tuple :data @[] :token origin})
|
(def ast {:type :tuple :data @[] :token origin})
|
||||||
(while (not (check parser :rparen))
|
(while (not (check parser :rparen))
|
||||||
(accept-many parser ;separates)
|
(accept-many parser :newline :comma)
|
||||||
|
(when (= :break ((current parser) :type))
|
||||||
|
(break (advance parser)))
|
||||||
(when (check parser :eof)
|
(when (check parser :eof)
|
||||||
(def err {:type :error :token origin :msg "unclosed paren"})
|
(def err {:type :error :token origin :msg "unclosed paren"})
|
||||||
(array/push (parser :errors) err)
|
(array/push (parser :errors) err)
|
||||||
|
@ -383,7 +387,9 @@
|
||||||
(advance parser)
|
(advance parser)
|
||||||
(def ast {:type :list :data @[] :token origin})
|
(def ast {:type :list :data @[] :token origin})
|
||||||
(while (not (check parser :rbracket))
|
(while (not (check parser :rbracket))
|
||||||
(accept-many parser ;separates)
|
(accept-many parser :newline :comma)
|
||||||
|
(when (= :break ((current parser) :type))
|
||||||
|
(break (advance parser)))
|
||||||
(when (check parser :eof)
|
(when (check parser :eof)
|
||||||
(def err {:type :error :token origin :msg "unclosed bracket"})
|
(def err {:type :error :token origin :msg "unclosed bracket"})
|
||||||
(array/push (parser :errors) err)
|
(array/push (parser :errors) err)
|
||||||
|
@ -406,7 +412,9 @@
|
||||||
(advance parser)
|
(advance parser)
|
||||||
(def ast {:type :set :data @[] :token origin})
|
(def ast {:type :set :data @[] :token origin})
|
||||||
(while (not (check parser :rbrace))
|
(while (not (check parser :rbrace))
|
||||||
(accept-many parser ;separates)
|
(accept-many parser :newline :comma)
|
||||||
|
(when (= :break ((current parser) :type))
|
||||||
|
(break (advance parser)))
|
||||||
(when (check parser :eof)
|
(when (check parser :eof)
|
||||||
(def err {:type :error :token origin :msg "unclosed brace"})
|
(def err {:type :error :token origin :msg "unclosed brace"})
|
||||||
(array/push (parser :errors) err)
|
(array/push (parser :errors) err)
|
||||||
|
@ -429,7 +437,9 @@
|
||||||
(advance parser)
|
(advance parser)
|
||||||
(def ast {:type :dict :data @[] :token origin})
|
(def ast {:type :dict :data @[] :token origin})
|
||||||
(while (not (check parser :rbrace))
|
(while (not (check parser :rbrace))
|
||||||
(accept-many parser ;separates)
|
(accept-many parser :newline :comma)
|
||||||
|
(when (= :break ((current parser) :type))
|
||||||
|
(break (advance parser)))
|
||||||
(when (check parser :eof)
|
(when (check parser :eof)
|
||||||
(def err {:type :error :token origin :msg "unclosed brace"})
|
(def err {:type :error :token origin :msg "unclosed brace"})
|
||||||
(array/push (parser :errors) err)
|
(array/push (parser :errors) err)
|
||||||
|
@ -479,7 +489,9 @@
|
||||||
(advance parser) # consume the :lparen
|
(advance parser) # consume the :lparen
|
||||||
(def ast {:type :tuple :data @[] :token origin})
|
(def ast {:type :tuple :data @[] :token origin})
|
||||||
(while (not (check parser :rparen))
|
(while (not (check parser :rparen))
|
||||||
(accept-many parser ;separates)
|
(accept-many parser :newline :comma)
|
||||||
|
(when (= :break ((current parser) :type))
|
||||||
|
(break (advance parser)))
|
||||||
(when (check parser :eof)
|
(when (check parser :eof)
|
||||||
(def err {:type :error :token origin :msg "unclosed paren"})
|
(def err {:type :error :token origin :msg "unclosed paren"})
|
||||||
(array/push (parser :errors) err)
|
(array/push (parser :errors) err)
|
||||||
|
@ -501,7 +513,9 @@
|
||||||
(advance parser)
|
(advance parser)
|
||||||
(def ast {:type :list :data @[] :token origin})
|
(def ast {:type :list :data @[] :token origin})
|
||||||
(while (not (check parser :rbracket))
|
(while (not (check parser :rbracket))
|
||||||
(accept-many parser ;separates)
|
(accept-many parser :newline :comma)
|
||||||
|
(when (= :break ((current parser) :type))
|
||||||
|
(break (advance parser)))
|
||||||
(when (check parser :eof)
|
(when (check parser :eof)
|
||||||
(def err {:type :error :token origin :msg "unclosed bracket"})
|
(def err {:type :error :token origin :msg "unclosed bracket"})
|
||||||
(array/push (parser :errors) err)
|
(array/push (parser :errors) err)
|
||||||
|
@ -523,7 +537,9 @@
|
||||||
(advance parser)
|
(advance parser)
|
||||||
(def ast {:type :dict :data @[] :token origin})
|
(def ast {:type :dict :data @[] :token origin})
|
||||||
(while (not (check parser :rbrace))
|
(while (not (check parser :rbrace))
|
||||||
(accept-many parser ;separates)
|
(accept-many parser :newline :comma)
|
||||||
|
(when (= :break ((current parser) :type))
|
||||||
|
(break (advance parser)))
|
||||||
(when (check parser :eof)
|
(when (check parser :eof)
|
||||||
(def err {:type :error :token origin :msg "unclosed brace"})
|
(def err {:type :error :token origin :msg "unclosed brace"})
|
||||||
(array/push (parser :errors) err)
|
(array/push (parser :errors) err)
|
||||||
|
@ -827,7 +843,9 @@
|
||||||
(expect parser :lbrace) (advance parser)
|
(expect parser :lbrace) (advance parser)
|
||||||
(def data @[])
|
(def data @[])
|
||||||
(while (not (check parser :rbrace))
|
(while (not (check parser :rbrace))
|
||||||
(accept-many parser ;terminators)
|
(accept-many parser :newline :semicolon)
|
||||||
|
(when (= :break ((current parser) :type))
|
||||||
|
(break (advance parser)))
|
||||||
(if (check parser :eof)
|
(if (check parser :eof)
|
||||||
(error {:type :error :token origin :data data :msg "unclosed brace"}))
|
(error {:type :error :token origin :data data :msg "unclosed brace"}))
|
||||||
(array/push data (capture expr parser))
|
(array/push data (capture expr parser))
|
||||||
|
@ -1131,7 +1149,9 @@
|
||||||
(def lines @[])
|
(def lines @[])
|
||||||
(while (not (check parser :eof))
|
(while (not (check parser :eof))
|
||||||
(print "starting script loop with " (pp-tok origin))
|
(print "starting script loop with " (pp-tok origin))
|
||||||
(accept-many parser ;terminators)
|
(accept-many parser :newline :semicolon)
|
||||||
|
(when (= :break ((current parser) :type))
|
||||||
|
(break (advance parser)))
|
||||||
(array/push lines (capture toplevel parser))
|
(array/push lines (capture toplevel parser))
|
||||||
(capture terminator parser))
|
(capture terminator parser))
|
||||||
{:type :script :data lines :token origin})
|
{:type :script :data lines :token origin})
|
||||||
|
@ -1145,13 +1165,11 @@
|
||||||
(do
|
(do
|
||||||
# (comment
|
# (comment
|
||||||
(def source `
|
(def source `
|
||||||
(,,,,,1, 2, foo)
|
(foo bar)
|
||||||
|
|
||||||
`)
|
`)
|
||||||
(def scanned (s/scan source))
|
(def scanned (s/scan source))
|
||||||
# (print "\n***NEW PARSE***\n")
|
# (print "\n***NEW PARSE***\n")
|
||||||
(def a-parser (new-parser scanned))
|
(def parsed (parse scanned))
|
||||||
(def parsed (script a-parser))
|
(pp (map (fn [err] (err :msg)) (parsed :errors)))
|
||||||
(pp (map (fn [err] (err :msg)) ((parse scanned) :errors)))
|
(print (pp-ast (parsed :ast)))
|
||||||
(print (pp-ast ((parse scanned) :ast)))
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user