Skip to content

Commit 946a331

Browse files
committed
improve compatibility with older lua, tests and automated issue assignment
1 parent 28b5ede commit 946a331

4 files changed

Lines changed: 55 additions & 13 deletions

File tree

.github/workflows/issue.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Issue assignment
2+
3+
on:
4+
issues:
5+
types: [opened, edited, labeled, unlabeled]
6+
7+
jobs:
8+
run:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: wow-actions/auto-assign@v3
12+
with:
13+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14+
assignees: cryi
15+
skipKeywords: wip, draft

.github/workflows/test.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
pull_request:
6+
branches:
7+
- main
8+
types: [opened, reopened, synchronize]
9+
10+
jobs:
11+
build-linux:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
submodules: recursive
17+
18+
- name: setup eli
19+
uses: alis-is/setup-eli@v1
20+
21+
- name: test hjson
22+
run: |
23+
eli ./tests/test.lua
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package = "hjson-lua"
2-
version = "0.1.4-1"
2+
version = "0.1.5-1"
33
source = {
44
url = "git://github.com/hjson/hjson-lua.git",
55
}

hjson/decoder.lua

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,8 @@ function HjsonDecoder:new(strict, object_hook, object_pairs_hook)
151151

152152
-- callers make sure that string starts with " or '
153153
local exitCh = charAt(s, begin)
154-
while true do
155-
::scan_string_loop_start::
156-
-- From hjson-py --> '(.*?)([\'"\\\x00-\x1f])'
157-
local content, terminator = s:match('(.-)([\'"\\\x00-\x1f])', _end)
154+
local function scan_string()
155+
local content, terminator = s:match('(.-)([\'"\\%z\001-\031])', _end)
158156
if not content then
159157
decodeError(s, begin, "Unterminated string")
160158
end
@@ -163,16 +161,16 @@ function HjsonDecoder:new(strict, object_hook, object_pairs_hook)
163161
chunks = chunks .. content
164162

165163
if terminator == exitCh then
166-
break
164+
return false -- break
167165
elseif terminator == '"' or terminator == "'" then
168166
chunks = chunks .. terminator
169-
goto scan_string_loop_start
167+
return true -- continue
170168
elseif terminator ~= "\\" then
171169
if strict then
172-
decodeError(s, begin, "Invalid control character" .. terminator)
170+
decodeError(s, begin, "Invalid control character " .. terminator)
173171
else
174172
chunks = chunks .. terminator
175-
goto scan_string_loop_start
173+
return true -- continue
176174
end
177175
end
178176

@@ -209,6 +207,7 @@ function HjsonDecoder:new(strict, object_hook, object_pairs_hook)
209207
end
210208
chunks = chunks .. chars
211209
end
210+
while scan_string() do end
212211
return chunks, _end
213212
end
214213

@@ -235,8 +234,7 @@ function HjsonDecoder:new(strict, object_hook, object_pairs_hook)
235234
end
236235

237236
-- When parsing multiline string values, we must look for ' characters
238-
while true do
239-
::scan_mlstring_loop_start::
237+
local function scan_mlstring()
240238
ch = charAt(s, _end)
241239
if ch == "" then
242240
decodeError(s, _end, "Bad multiline string")
@@ -250,7 +248,7 @@ function HjsonDecoder:new(strict, object_hook, object_pairs_hook)
250248
end
251249
return string, _end
252250
else
253-
goto scan_mlstring_loop_start
251+
return false
254252
end
255253
else
256254
while triple > 0 do
@@ -269,6 +267,12 @@ function HjsonDecoder:new(strict, object_hook, object_pairs_hook)
269267
_end = _end + 1
270268
end
271269
end
270+
while true do
271+
local s, _end = scan_mlstring()
272+
if s then
273+
return s, _end
274+
end
275+
end
272276
end
273277

274278
local function parsePrimitive(s, _end)
@@ -286,7 +290,7 @@ function HjsonDecoder:new(strict, object_hook, object_pairs_hook)
286290
if
287291
isEol or ch == "," or ch == "}" or ch == "]" or ch == "#" or
288292
ch == "/" and (charAt(s, _end + 1) == "/" or charAt(s, _end + 1) == "*")
289-
then
293+
then
290294
local m = nil
291295
local integer = nil
292296
local frac = nil

0 commit comments

Comments
 (0)