Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

error message now contains line and column

  • Loading branch information...
commit c0c6035d7d90acef92fd89d9402ca66c54e3bda9 1 parent 45ff1fd
@lm authored
Showing with 23 additions and 15 deletions.
  1. +12 −4 Json/Json.st
  2. +11 −11 tests/JsonTest.st
View
16 Json/Json.st
@@ -1,5 +1,5 @@
Object subclass: Json [
- | stream |
+ | stream line linePosition |
<category: 'json'>
<comment: 'This class reads and writes JSON format data - strings, numbers, boolean, nil, arrays and dictionaries. See http://json.org.'>
@@ -64,6 +64,8 @@ Object subclass: Json [
<category: 'initialising'>
stream := anObject.
+ line := 1.
+ linePosition := 0.
]
stream [
@@ -147,8 +149,10 @@ Object subclass: Json [
| char |
- [(char := stream peek) notNil and: [char isSeparator]]
- whileTrue: [stream next].
+ [(char := stream peek) notNil and: [char isSeparator]] whileTrue: [
+ stream next = Character nl ifTrue: [
+ line := line + 1.
+ linePosition := stream position]].
]
nextDictionary [
@@ -271,6 +275,10 @@ Object subclass: Json [
<category: 'error raising'>
JsonSyntaxError signal:
- 'Expected %1 but %2 found' % {aString. currrentString ifNil: ['end of input']}
+ 'Expected %1 but %2 found on line %3 column %4' %
+ {aString.
+ currrentString ifNil: ['end of input'].
+ line.
+ stream position - linePosition}
]
]
View
22 tests/JsonTest.st
@@ -116,17 +116,17 @@ TestCase subclass: JsonTest [
testErrorMessages [
self
- parseJson: '[' error: 'Expected string, object, array, true, false, null or digit but end of input found';
- parseJson: '{' error: 'Expected string but end of input found';
- parseJson: '{""' error: 'Expected : but end of input found';
- parseJson: 't' error: 'Expected true but t found';
- parseJson: 'f' error: 'Expected false but f found';
- parseJson: 'n' error: 'Expected null but n found';
- parseJson: '"s' error: 'Expected character but end of input found';
- parseJson: '"', Character nl asString, '"' error: 'Expected printable character but control character found';
- parseJson: '"\uA' error: 'Expected 4 hex digits but A found';
- parseJson: '"\x' error: 'Expected ", \, /, b, n, f, r, t, u but x found';
- parseJson: '0 1' error: 'Expected end of input but 1 found'.
+ parseJson: '[' error: 'Expected string, object, array, true, false, null or digit but end of input found on line 1 column 1';
+ parseJson: '{' error: 'Expected string but end of input found on line 1 column 1';
+ parseJson: '{""' error: 'Expected : but end of input found on line 1 column 3';
+ parseJson: 't' error: 'Expected true but t found on line 1 column 1';
+ parseJson: 'f' error: 'Expected false but f found on line 1 column 1';
+ parseJson: 'n' error: 'Expected null but n found on line 1 column 1';
+ parseJson: '"s' error: 'Expected character but end of input found on line 1 column 2';
+ parseJson: '"', Character nl asString, '"' error: 'Expected printable character but control character found on line 1 column 2';
+ parseJson: '"\uA' error: 'Expected 4 hex digits but A found on line 1 column 4';
+ parseJson: '"\x' error: 'Expected ", \, /, b, n, f, r, t, u but x found on line 1 column 3';
+ parseJson: '0 1' error: 'Expected end of input but 1 found on line 1 column 2'.
]
parseJson: aString error: aMessageString [
Please sign in to comment.
Something went wrong with that request. Please try again.