Raise error on list items or free texts outside a list or a section

master
Philippe PITTOLI 2019-08-10 14:13:52 +02:00
parent 617499d4a6
commit c4901f3ad8
1 changed files with 11 additions and 19 deletions

View File

@ -101,7 +101,7 @@ class Specs
end end
def parse_list(header : String, content : Array(String)) def parse_list(header : String, content : Array(String))
name = /[a-zA-Z][a-zA-Z0-9]*/.match(header).try &.[0] name = /[a-zA-Z][a-zA-Z0-9-_]*/.match(header).try &.[0]
# puts "new list: #{name}" # puts "new list: #{name}"
list = Array(String).new list = Array(String).new
@ -130,7 +130,7 @@ class Specs
end end
def parse_code_block(header : String, content : Array(String)) def parse_code_block(header : String, content : Array(String))
name = /[a-zA-Z][a-zA-Z0-9]*/.match(header).try &.[0] name = /[a-zA-Z][a-zA-Z0-9-_]*/.match(header).try &.[0]
# puts "new code block: #{name}" # puts "new code block: #{name}"
value = String.build do |str| value = String.build do |str|
@ -159,7 +159,7 @@ class Specs
end end
def parse_section(header : String, content : Array(String)) def parse_section(header : String, content : Array(String))
results = /^[%]([a-zA-Z][a-zA-Z0-9]*)[ \t]*([^#]*)/.match(header) results = /^[%]([a-zA-Z][a-zA-Z0-9-_]*)[ \t]*([^#]*)/.match(header)
name = results[1]? if results name = results[1]? if results
options = results[2]? if results options = results[2]? if results
@ -241,31 +241,23 @@ class Specs
end end
def parse_lines(content : Array(String)) def parse_lines(content : Array(String))
count = 0
while line = content.shift? while line = content.shift?
case line case line
when /^[ \t]*$/ when /^[a-zA-Z][a-zA-Z0-9-_]*:[ \t]*([#].*)?$/
else
# puts "line #{count}: #{line}"
end
case line
when /^[a-zA-Z][a-zA-Z0-9]*:[ \t]*([#].*)?$/
parse_list line, content parse_list line, content
when /^[a-zA-Z][a-zA-Z]*:[ \t]+[^#]+/ when /^[a-zA-Z][a-zA-Z0-9-_]*:[ \t]+[^#]+/
parse_assignment line parse_assignment line
when /^[@][a-zA-Z][a-zA-Z]*[ \t]*([#].*)?/ when /^[@][a-zA-Z][a-zA-Z0-9-_]*[ \t]*([#].*)?/
parse_code_block line, content parse_code_block line, content
when /^[%][a-zA-Z][a-zA-Z]*[ \t]*([#].*)?/ when /^[%][a-zA-Z][a-zA-Z0-9-_]*[ \t]*([#].*)?/
parse_section line, content parse_section line, content
when /^[ \t]*#/ when /^[ \t]*#/
# puts "comment" # puts "comment"
when /^[ \t]+/ when /^[ \t]+$/
puts "tab!! should not happen" # puts "empty line"
when /^[ \t]+[^ \t#]/
raise "line starting with spaces or a tabulation outside a list or a section: should not happen"
end end
count += 1
end end
end end