mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 08:39:30 +00:00
[internal] normalize newlines and bom
This commit is contained in:
parent
7e29fb87b4
commit
cee00eb13d
1 changed files with 9 additions and 1 deletions
|
|
@ -9,8 +9,16 @@ local function expect_end(exp, rem)
|
|||
return exp
|
||||
end
|
||||
|
||||
-- we require UTF-8 but life is full of disapointments
|
||||
-- remove BOM
|
||||
-- \r\n and \r -> \n
|
||||
local function normalize_encoding(str)
|
||||
return str:gsub("^"..string.char(0xEF, 0xBB, 0xBF), "")
|
||||
:gsub("\r\n?", "\n")
|
||||
end
|
||||
|
||||
-- parse code (string) with the associated source (Source)
|
||||
-- the returned AST tree is stateless and can be stored/evaluated/etc as you please
|
||||
return function(code, source)
|
||||
return expect_end(block(Source:new(source, 1, 1), Options:new(), code))
|
||||
return expect_end(block(Source:new(source, 1, 1), Options:new(), normalize_encoding(code)))
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue