Skip to content

Commit

Permalink
Merge pull request #632 from pallene-lang/reformat-newlines
Browse files Browse the repository at this point in the history
Stop using /**/ to signal blank lines
  • Loading branch information
hugomg authored Sep 10, 2024
2 parents 104733f + 0e05eb3 commit 6de8cdb
Show file tree
Hide file tree
Showing 3 changed files with 244 additions and 285 deletions.
18 changes: 0 additions & 18 deletions src/pallene/C.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,9 @@ end
function C.reformat(input)
local out = {}
local depth = 0
local previous_line = nil
for line in input:gmatch("([^\n]*)") do
line = line:match("^%s*(.-)%s*$")

-- We ignore blank lines in the input because most of them are garbage produced by the code
-- generator. However, sometimes we want to intentionally leave a blank line for formatting
-- purposes. To do that, use a line that is just an empty C comment: /**/
if line == "" then
goto continue
end
if line == "/**/" then
line = ""
end
if line == "" and previous_line == "" then
goto continue
end

local nspaces
if line:match("^#") then
-- Preprocessor directives are never indented
Expand All @@ -181,10 +167,6 @@ function C.reformat(input)
table.insert(out, string.rep(" ", nspaces))
table.insert(out, line)
table.insert(out, "\n")

previous_line = line

::continue::
end
assert(depth == 0, "Unbalanced indentation at end of file.")
return table.concat(out)
Expand Down
Loading

0 comments on commit 6de8cdb

Please sign in to comment.