Tweaks and fixes.

This commit is contained in:
Bruce Hill 2017-09-12 17:42:35 -07:00
parent 6e236fa095
commit c0efa6c7d1
2 changed files with 9 additions and 5 deletions

View File

@ -50,7 +50,7 @@ make_parser = (lingo, extra_definitions)->
defs = defs =
:wordchar, :nl, ws:whitespace, :comment :wordchar, :nl, ws:whitespace, :comment
eol: #nl + (P("")-P(1)) eol: #nl + (P("")-P(1))
word_boundary: S(" \t")^1 + B(P("..")) + B(S("\";)]")) + #S("\":([") + #P("..") word_boundary: whitespace + B(P("..")) + B(S("\";)]")) + #S("\":([") + #((whitespace + nl)^0 * P(".."))
indent: #(nl * blank_line^0 * Cmt(whitespace^-1, check_indent)) indent: #(nl * blank_line^0 * Cmt(whitespace^-1, check_indent))
dedent: #(nl * blank_line^0 * Cmt(whitespace^-1, check_dedent)) dedent: #(nl * blank_line^0 * Cmt(whitespace^-1, check_dedent))
new_line: nl * blank_line^0 * Cmt(whitespace^-1, check_nodent) new_line: nl * blank_line^0 * Cmt(whitespace^-1, check_nodent)
@ -152,7 +152,7 @@ class Game
if @debug if @debug
print("PARSING:\n#{str}") print("PARSING:\n#{str}")
lingo = [=[ lingo = [=[
file <- ({ {| %new_line? {:body: block :} %new_line? (errors)? |} }) -> File file <- ({ {| %ws? %new_line? {:body: block :} %new_line? %ws? (errors)? |} }) -> File
errors <- (({.+}) => error_handler) errors <- (({.+}) => error_handler)
block <- ({ {| statement (%new_line statement)* |} }) -> Block block <- ({ {| statement (%new_line statement)* |} }) -> Block
statement <- ({ (functioncall / expression) }) -> Statement statement <- ({ (functioncall / expression) }) -> Statement
@ -169,7 +169,7 @@ class Game
fn_bit <- (expression / word) fn_bit <- (expression / word)
fn_bits <- fn_bits <-
((".." %ws? (%indent %new_line indented_fn_bits %dedent) (%new_line ".." %ws? fn_bits)?) ((".." %ws? (%indent %new_line indented_fn_bits %dedent) (%new_line ".." %ws? fn_bits)?)
/ (%new_line ".." fn_bit fn_bits) / (%new_line ".." fn_bit (%word_boundary fn_bits)?)
/ (fn_bit (%word_boundary fn_bits)?)) / (fn_bit (%word_boundary fn_bits)?))
indented_fn_bits <- indented_fn_bits <-
fn_bit ((%new_line / %word_boundary) indented_fn_bits)? fn_bit ((%new_line / %word_boundary) indented_fn_bits)?
@ -195,10 +195,10 @@ class Game
("[..]" %ws? %indent %new_line indented_list ","? ((%dedent (%new_line "..")?) / errors)) ("[..]" %ws? %indent %new_line indented_list ","? ((%dedent (%new_line "..")?) / errors))
/ ("[" %ws? (list_items ","?)? %ws?"]") / ("[" %ws? (list_items ","?)? %ws?"]")
|} }) -> List |} }) -> List
list_items <- (expression (list_sep list_items)?) list_items <- ((functioncall / expression) (list_sep list_items)?)
list_sep <- %ws? "," %ws? list_sep <- %ws? "," %ws?
indented_list <- indented_list <-
expression (((list_sep %new_line?) / %new_line) indented_list)? (functioncall / expression) (((list_sep %new_line?) / %new_line) indented_list)?
]=] ]=]
lingo = make_parser lingo lingo = make_parser lingo

View File

@ -64,6 +64,10 @@ utils = {
with tot = 0 with tot = 0
for _,x in pairs(t) do tot += x for _,x in pairs(t) do tot += x
product: (t)->
with prod = 1
for _,x in pairs(t) do prod *= x
all: (t)-> all: (t)->
for _,x in pairs t for _,x in pairs t
if not x then return false if not x then return false