Skip to content

Commit 50b5619

Browse files
committed
Add KDoc comments to JSONPositionData
1 parent 9888ec7 commit 50b5619

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

src/main/kotlin/lexer/JSONLexer.kt

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,87 @@ interface JSONLexer {
8585
fun getPosition(position: Int, length: Int = 1): JSONPositionData
8686
}
8787

88+
/**
89+
* The interface for specific position data for error handling.
90+
* It allows the exceptions to have more information on where
91+
* the error was and what happened.
92+
*
93+
* This exists so that the tokens themselves do not have to
94+
* store this information, as it is very expensive to calculate,
95+
* and if everything is fine, it does not have to be used,
96+
* and with that is completely useless.
97+
*/
8898
interface JSONPositionData {
99+
/**
100+
* Returns the exact line number where the error happened.
101+
* It **must** be `1`-Based as this is a number that is
102+
* for the user and not the computer.
103+
*
104+
* So for example if the error happened in this document:
105+
* ```json
106+
* {
107+
* "test": 42,
108+
* "me": error
109+
* }
110+
* ```
111+
* then the function should return the value `3` as the error is
112+
* in the third line of the document.
113+
*/
89114
fun lineNumber(): Int
115+
116+
/**
117+
* Returns the starting position of the error in the line.
118+
* It **must** be `1`-based as this is a number that
119+
* for the user and not the computer.
120+
*
121+
* So for example if the error happened in this document:
122+
* ```json
123+
* {
124+
* "test": 42,
125+
* "me": error
126+
* }
127+
* ```
128+
* then the function should return the value `11` as the error
129+
* is starting at the eleventh character on that line
130+
* (whitespace is being included).
131+
*/
90132
fun linePosition(): Int
133+
134+
/**
135+
* Returns the length of the error that happened.
136+
*
137+
* If it is just one character that was the erroneous character
138+
* then the value would be `1`.
139+
* So if the document would be `{:}` then the `:` would throw
140+
* an error that is one character long.
141+
*
142+
* And if the erroneous token is longer then the length will
143+
* be according to the length of the token:
144+
*
145+
* Example document:
146+
* ```json
147+
* {
148+
* "test": 42,
149+
* "me": truw
150+
* }
151+
* ```
152+
* In this case the returned value would be `4` as the
153+
* literal `truw` is four characters long.
154+
*/
91155
fun getLength(): Int
156+
157+
/**
158+
* Returns the entire line in string form.
159+
*
160+
* So for example if the error happened in this document:
161+
* ```json
162+
* {
163+
* "test": 42,
164+
* "me": error
165+
* }
166+
* ```
167+
* then the return value would be ` "me": error`
168+
* (with the whitespace at the beginning).
169+
*/
92170
fun getLine(): String
93171
}

0 commit comments

Comments
 (0)