1
0
mirror of https://github.com/digarok/radius.git synced 2024-06-13 17:29:31 +00:00

- fix "negative" spacing bug w/better debug out

- now checks for negative values when indenting comments, forces a space
- now catches errors a little more gracefully, giving you the source line where it failed
This commit is contained in:
Dagen Brock 2017-12-27 09:25:32 -06:00
parent a9e13efea6
commit 83ff82b5fe

View File

@ -77,7 +77,13 @@ file.close unless file.nil?
# begin line-by-line processing
output_buf = ""
# most editors will start numbering with line 1
linenum = 1
source_contents.each_line do |line|
# we catch any issue that causes radius to fail and just print out the line
# that it failed on. not the best, but *shrug*
begin
# state machine - resets each line
in_quote = false
in_comment = false
@ -181,7 +187,10 @@ source_contents.each_line do |line|
# (and not in quote or comment)
elsif c == ';' && !in_operand
in_comment = true
buf << " "*(comment_col_x-x)
# protect against "negative" spacing
spaces = 1 > (comment_col_x-x) ? 1 : (comment_col_x-x)
buf << " "*spaces
x+=comment_col_x-x
buf << c
x+=1
@ -221,7 +230,12 @@ source_contents.each_line do |line|
end
end
end
rescue Exception => ex
puts "An error of type #{ex.class} happened, message is #{ex.message}"
abort("We failed to parse on line #{linenum}")
end
linenum+=1
# move line to buffer, stripping trailing spaces
output_buf << buf.rstrip << "\n"
end