Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line continuation #27

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/JSON28_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
linebreak
]
3 changes: 3 additions & 0 deletions assets/JSON28_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"linebreak"
]
File renamed without changes.
5 changes: 5 additions & 0 deletions assets/failStr10a_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
# escaped \n should not cause line continuation in quoteless string
key: Look, Mom! \
No \\n's!
}
4 changes: 4 additions & 0 deletions assets/failStr9a_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
# escaped \r
key: "Look, Mom! \No \\n's!"
}
Expand Down
3 changes: 3 additions & 0 deletions assets/sorted/JSON28_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
linebreak
]
3 changes: 3 additions & 0 deletions assets/sorted/JSON28_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"linebreak"
]
3 changes: 3 additions & 0 deletions assets/sorted/strings4_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
key: Look, Mom! No \n's!
}
3 changes: 3 additions & 0 deletions assets/sorted/strings4_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key": "Look, Mom! No \\n's!"
}
3 changes: 3 additions & 0 deletions assets/sorted/strings5_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
key: Look, Mom! No \n's!
}
3 changes: 3 additions & 0 deletions assets/sorted/strings5_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key": "Look, Mom! No \\n's!"
}
7 changes: 7 additions & 0 deletions assets/sorted/strings6_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
key:
'''
Look, Mom! \
No \\n's!
'''
}
3 changes: 3 additions & 0 deletions assets/sorted/strings6_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key": "Look, Mom! \\\nNo \\\\n's!"
}
3 changes: 3 additions & 0 deletions assets/strings4_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
key: Look, Mom! No \n's!
}
3 changes: 3 additions & 0 deletions assets/strings4_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key": "Look, Mom! No \\n's!"
}
5 changes: 5 additions & 0 deletions assets/strings4_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
# escaped \n
key: "Look, Mom! \
No \\n's!"
}
3 changes: 3 additions & 0 deletions assets/strings5_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
key: Look, Mom! No \n's!
}
3 changes: 3 additions & 0 deletions assets/strings5_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key": "Look, Mom! No \\n's!"
}
5 changes: 5 additions & 0 deletions assets/strings5_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
# escaped \r\n
key: "Look, Mom! \
No \\n's!"
}
7 changes: 7 additions & 0 deletions assets/strings6_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
key:
'''
Look, Mom! \
No \\n's!
'''
}
3 changes: 3 additions & 0 deletions assets/strings6_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key": "Look, Mom! \\\nNo \\\\n's!"
}
8 changes: 8 additions & 0 deletions assets/strings6_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
# escaped \n should not cause line continuation in multiline string
key:
'''
Look, Mom! \
No \\n's!
'''
}
7 changes: 6 additions & 1 deletion assets/testlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ failJSON21_test.json
failJSON22_test.json
failJSON23_test.json
failJSON26_test.json
failJSON28_test.json
failJSON29_test.json
failJSON30_test.json
failJSON31_test.json
Expand Down Expand Up @@ -64,7 +63,10 @@ failStr6c_test.hjson
failStr6d_test.hjson
failStr7a_test.hjson
failStr8a_test.hjson
failStr9a_test.hjson
failStr10a_test.hjson
kan_test.hjson
JSON28_test.json
keys_test.hjson
mltabs_test.json
oa_test.hjson
Expand All @@ -76,6 +78,9 @@ passSingle_test.hjson
stringify1_test.hjson
strings2_test.hjson
strings_test.hjson
strings4_test.hjson
strings5_test.hjson
strings6_test.hjson
trail_test.hjson
stringify/quotes_all_test.hjson
stringify/quotes_always_test.hjson
Expand Down
5 changes: 5 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ func (p *hjsonParser) readString(allowML bool) (string, error) {
uffff = uffff*16 + hex
}
res.WriteRune(rune(uffff))
} else if p.ch == '\n' {
// Escaped line feed is ignored (line continuation is allowed).
} else if p.ch == '\r' && p.peek(0) == '\n' {
// Escaped line feed is ignored (line continuation is allowed).
p.next();
} else if ech, ok := escapee[p.ch]; ok {
res.WriteByte(ech)
} else {
Expand Down