aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nomsu.1.peg4
-rw-r--r--nomsu.2.peg17
-rw-r--r--nomsu_compiler.lua12
-rw-r--r--nomsu_compiler.moon8
-rw-r--r--parser.lua7
-rw-r--r--parser.moon7
6 files changed, 31 insertions, 24 deletions
diff --git a/nomsu.1.peg b/nomsu.1.peg
index 39c0a9a..10a7715 100644
--- a/nomsu.1.peg
+++ b/nomsu.1.peg
@@ -1,7 +1,7 @@
-- Nomsu version 2
file (FileChunks):
{:curr_indent: ' '* :}
- ("#!" (!"nomsu" [^%nl])* "nomsu" %ws+ "-V" %ws* {:version: ([0-9.]+ -> tonumber) :} [^%nl]*)?
+ ("#!" (!"nomsu" [^%nl])* "nomsu" %ws+ "-V" %ws* {:version: [0-9.]+ :} [^%nl]*)?
comment? blank_lines?
(chunk (nl_nodent chunk_delimeter nl_nodent chunk)*)?
blank_lines?
@@ -16,7 +16,7 @@ nl_nodent: blank_lines nodent
nl_indent: blank_lines {:curr_indent: indent :} (comment nl_nodent)?
comment:
- "#" (({} {~ [^%nl]* ((%nl (!indent %ws* %nl)*) (indent -> '') [^%nl]*)* ~} %userdata) => add_comment)
+ "#" (({} {~ [^%nl]* (%nl+ (indent -> '') [^%nl]*)* ~} %userdata) => add_comment)
eol_comment:
"#" (({} {[^%nl]*} %userdata) => add_comment)
diff --git a/nomsu.2.peg b/nomsu.2.peg
index 58ae33d..5f9b398 100644
--- a/nomsu.2.peg
+++ b/nomsu.2.peg
@@ -1,7 +1,7 @@
-- Nomsu version 2
file (FileChunks):
{:curr_indent: ' '* :}
- ("#!" (!"nomsu" [^%nl])* "nomsu" %ws+ "-V" %ws* {:version: ([0-9.]+ -> tonumber) :} [^%nl]*)?
+ ("#!" (!"nomsu" [^%nl])* "nomsu" %ws+ "-V" %ws* {:version: [0-9.]+ :} [^%nl]*)?
comment? blank_lines?
(chunk (nl_nodent section_division nl_nodent chunk)*)?
blank_lines?
@@ -16,7 +16,7 @@ nl_nodent: blank_lines nodent
nl_indent: blank_lines {:curr_indent: indent :} (comment nl_nodent)?
comment:
- "#" (({} {~ [^%nl]* ((%nl (!indent %ws* %nl)*) (indent -> '') [^%nl]*)* ~} %userdata) => add_comment)
+ "#" (({} {~ [^%nl]* (%nl+ (indent -> '') [^%nl]*)* ~} %userdata) => add_comment)
eol_comment:
"#" (({} {[^%nl]*} %userdata) => add_comment)
@@ -27,7 +27,7 @@ inline_block (Block):
chunk (Block):
statement (nl_nodent statement)*
indented_block (Block):
- ":" eol nl_indent statement (nl_nodent statement)*
+ ":" eol nl_indent statement (nl_nodent statement)* (%nl (%ws* %nl)* nodent comment)*
statement: (action / expression) (eol / (!! [^%nl]+ -> "Unexpected character while parsing line" !!))
inline_statement: (inline_action / inline_expression)
@@ -62,16 +62,13 @@ index_chain (IndexChain):
-- Actions need either at least 1 word, or at least 2 tokens
inline_action (Action):
!section_division
- ( ((smushed_action / inline_expression) (%ws* (smushed_action / inline_expression / word))+)
- / (word (%ws* (smushed_action / inline_expression / word))*))
+ ( (inline_expression (%ws* (inline_expression / word))+)
+ / (word (%ws* (inline_expression / word))*))
(%ws* inline_block)?
action (Action):
!section_division
- ( ((smushed_action / expression) ((nl_nodent "..")? %ws* (smushed_action / expression / word))+)
- / (word ((nl_nodent "..")? %ws* (smushed_action / expression / word))*))
-smushed_action (Action):
- !section_division
- (index_chain / noindex_inline_expression / word+) (index_chain / noindex_inline_expression / word+ / "(" %ws* ")")+
+ ( (expression ((nl_nodent "..")? %ws* (expression / word))+)
+ / (word ((nl_nodent "..")? %ws* (expression / word))*))
word: !number { %operator_char+ / %ident_char+ }
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua
index ac3e741..b096659 100644
--- a/nomsu_compiler.lua
+++ b/nomsu_compiler.lua
@@ -94,7 +94,11 @@ local _list_mt = {
__lt = function(self, other)
assert(type(self) == 'table' and type(other) == 'table', "Incompatible types for comparison")
for i = 1, math.max(#self, #other) do
- if self[i] < other[i] then
+ if not self[i] and other[i] then
+ return true
+ elseif self[i] and not other[i] then
+ return false
+ elseif self[i] < other[i] then
return true
elseif self[i] > other[i] then
return false
@@ -105,7 +109,11 @@ local _list_mt = {
__le = function(self, other)
assert(type(self) == 'table' and type(other) == 'table', "Incompatible types for comparison")
for i = 1, math.max(#self, #other) do
- if self[i] < other[i] then
+ if not self[i] and other[i] then
+ return true
+ elseif self[i] and not other[i] then
+ return false
+ elseif self[i] < other[i] then
return true
elseif self[i] > other[i] then
return false
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index 877de6b..e89dffa 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -71,13 +71,17 @@ _list_mt =
__lt: (other)=>
assert type(@) == 'table' and type(other) == 'table', "Incompatible types for comparison"
for i=1,math.max(#@, #other)
- if @[i] < other[i] then return true
+ if not @[i] and other[i] then return true
+ elseif @[i] and not other[i] then return false
+ elseif @[i] < other[i] then return true
elseif @[i] > other[i] then return false
return false
__le: (other)=>
assert type(@) == 'table' and type(other) == 'table', "Incompatible types for comparison"
for i=1,math.max(#@, #other)
- if @[i] < other[i] then return true
+ if not @[i] and other[i] then return true
+ elseif @[i] and not other[i] then return false
+ elseif @[i] < other[i] then return true
elseif @[i] > other[i] then return false
return true
diff --git a/parser.lua b/parser.lua
index 4abe2b9..1ccd263 100644
--- a/parser.lua
+++ b/parser.lua
@@ -151,13 +151,13 @@ Parser.parse = function(nomsu_code, source, version)
source = source or nomsu_code.source
nomsu_code = tostring(nomsu_code)
version = version or nomsu_code:match("^#![^\n]*nomsu[ ]+-V[ ]*([0-9.]+)")
- version = (version and tonumber(version)) or Parser.version
+ local syntax_version = version and tonumber(version:match("^[0-9]+")) or Parser.version
local userdata = {
errors = { },
source = source,
comments = { }
}
- local tree = Parser.patterns[version]:match(nomsu_code, nil, userdata)
+ local tree = Parser.patterns[syntax_version]:match(nomsu_code, nil, userdata)
if not (tree) then
error("In file " .. tostring(colored.blue(tostring(source or "<unknown>"))) .. " failed to parse:\n" .. tostring(colored.onyellow(colored.black(nomsu_code))))
end
@@ -187,7 +187,7 @@ Parser.parse = function(nomsu_code, source, version)
end
errors = _accum_0
end
- error("Errors occurred while parsing (v" .. tostring(version) .. "):\n\n" .. table.concat(errors, "\n\n"), 0)
+ error("Errors occurred while parsing (v" .. tostring(syntax_version) .. "):\n\n" .. table.concat(errors, "\n\n"), 0)
end
local comments
do
@@ -226,7 +226,6 @@ Parser.parse = function(nomsu_code, source, version)
end
end
walk_tree(tree)
- tree.version = userdata.version
return tree
end
Parser.is_operator = function(s)
diff --git a/parser.moon b/parser.moon
index fdf3eca..886f4c4 100644
--- a/parser.moon
+++ b/parser.moon
@@ -103,11 +103,11 @@ Parser.parse = (nomsu_code, source=nil, version=nil)->
source or= nomsu_code.source
nomsu_code = tostring(nomsu_code)
version or= nomsu_code\match("^#![^\n]*nomsu[ ]+-V[ ]*([0-9.]+)")
- version = (version and tonumber(version)) or Parser.version
+ syntax_version = version and tonumber(version\match("^[0-9]+")) or Parser.version
userdata = {
errors: {}, :source, comments: {}
}
- tree = Parser.patterns[version]\match(nomsu_code, nil, userdata)
+ tree = Parser.patterns[syntax_version]\match(nomsu_code, nil, userdata)
unless tree
error "In file #{colored.blue tostring(source or "<unknown>")} failed to parse:\n#{colored.onyellow colored.black nomsu_code}"
if type(tree) == 'number'
@@ -117,7 +117,7 @@ Parser.parse = (nomsu_code, source=nil, version=nil)->
keys = [k for k,v in pairs(userdata.errors)]
table.sort(keys)
errors = [userdata.errors[k] for k in *keys]
- error("Errors occurred while parsing (v#{version}):\n\n"..table.concat(errors, "\n\n"), 0)
+ error("Errors occurred while parsing (v#{syntax_version}):\n\n"..table.concat(errors, "\n\n"), 0)
comments = [{comment:c, pos:p} for p,c in pairs(userdata.comments)]
-- Sort in descending order so we can pop the first comments off the end one at a time
@@ -136,7 +136,6 @@ Parser.parse = (nomsu_code, source=nil, version=nil)->
t.comments = comment_buff if #comment_buff > 0
walk_tree tree
- tree.version = userdata.version
return tree
Parser.is_operator = (s)->