Skip to content

Commit 9888ec7

Browse files
committed
Add KDoc to the JSONLexer interface
1 parent ce3dc95 commit 9888ec7

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/main/kotlin/lexer/JSONLexer.kt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,62 @@ data class JSONLexeme(
2626
val content: String? = null
2727
)
2828

29+
/**
30+
* The lexer interface for a JSON parser.
31+
*
32+
* It contains two different methods:
33+
* - [getNext] - Returns the next token
34+
* - [getPosition] - Returns the data for a specific position
35+
* It should only be used for error handling as it can be
36+
* quite expensive to calculate this.
37+
*/
2938
interface JSONLexer {
39+
/**
40+
* Returns the next [JSONLexeme]. This lexeme is the next
41+
* token that can be used by the `jsonParse` function.
42+
*
43+
* ## Functionality
44+
*
45+
* This function always returns the next token and won't return the same token
46+
* twice (except if the last token is an `EOF` token). The tokenizer should
47+
* disregard whitespace.
48+
*
49+
* If the token stream has ended an `EOF` (**E**nd **O**f **F**ile) token
50+
* should be emitted.
51+
*
52+
* So if the source would be:
53+
* ```json
54+
* {
55+
* "test": 42
56+
* }
57+
* ```
58+
* it should be called `6` times and return the tokens:
59+
* `CURLY_OPEN`, `STRING`, `COLON`, `NUMBER`, `CURLY_CLOSE`, `EOF`.
60+
*
61+
* ## Error handling
62+
* If an error occurs whilst parsing the next token
63+
* the `getNext` function will throw a [JSONLexerException].
64+
*
65+
* If the source code would be:
66+
* ```json
67+
* truw
68+
* ```
69+
* it should throw a [JSONLexerException] with the correct position
70+
* data.
71+
*/
3072
@Throws(JSONLexerException::class)
3173
fun getNext(): JSONLexeme
3274

75+
/**
76+
* Returns the position data for the given integer position.
77+
*
78+
* This should be used if there is an error as calculating the
79+
* lines is a very expensive operation and does not need to be done
80+
* in a different context.
81+
*
82+
* @param position The starting position where the error occurred
83+
* @param length The length of the erroneous part
84+
*/
3385
fun getPosition(position: Int, length: Int = 1): JSONPositionData
3486
}
3587

0 commit comments

Comments
 (0)