Skip to content

Commit 27457f7

Browse files
committed
[ADDED] Kdoc for the tokens
1 parent 70a284d commit 27457f7

File tree

1 file changed

+70
-1
lines changed
  • lib/src/main/kotlin/io/github/json5/kotlin

1 file changed

+70
-1
lines changed

lib/src/main/kotlin/io/github/json5/kotlin/Token.kt

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,84 @@
11
package io.github.json5.kotlin
22

33
/**
4-
* Represents a token in the JSON5 syntax
4+
* Represents a token in the JSON5 syntax.
5+
* Each token has a type, a value (if applicable), and its line and column number in the source.
6+
*
7+
* Example usage:
8+
* ```
9+
* // Null token: null
10+
* val nullToken = Token.NullToken(1, 5)
11+
*
12+
* // Boolean token: true
13+
* val trueToken = Token.BooleanToken(true, 2, 3)
14+
*
15+
* // String token: "hello"
16+
* val stringToken = Token.StringToken("hello", 3, 7)
17+
*
18+
* // Numeric token: 42, 3.14, 0xFF, Infinity, NaN
19+
* val intToken = Token.NumericToken(42.0, 4, 2)
20+
* val floatToken = Token.NumericToken(3.14, 4, 7)
21+
* val hexToken = Token.NumericToken(255.0, 4, 12)
22+
* val infToken = Token.NumericToken(Double.POSITIVE_INFINITY, 5, 1)
23+
* val nanToken = Token.NumericToken(Double.NaN, 5, 10)
24+
*
25+
* // Punctuator token: { } [ ] : ,
26+
* val leftBrace = Token.PunctuatorToken("{", 6, 1)
27+
* val comma = Token.PunctuatorToken(",", 6, 2)
28+
*
29+
* // Identifier token: keyName, _foo, $bar
30+
* val identToken = Token.IdentifierToken("keyName", 7, 3)
31+
*
32+
* // End of file token
33+
* val eofToken = Token.EOFToken(8, 1)
34+
* ```
535
*/
636
sealed class Token(val type: TokenType, val value: Any?, val line: Int, val column: Int) {
37+
/**
38+
* Represents a null literal token.
39+
* Example: `null`
40+
*/
741
class NullToken(line: Int, column: Int) : Token(TokenType.NULL, null, line, column)
42+
43+
/**
44+
* Represents a boolean literal token.
45+
* Example: `true`, `false`
46+
* @param boolValue The boolean value (true or false)
47+
*/
848
class BooleanToken(val boolValue: Boolean, line: Int, column: Int) : Token(TokenType.BOOLEAN, boolValue, line, column)
49+
50+
/**
51+
* Represents a string literal token.
52+
* Example: `"hello"`, `'world'`
53+
* @param stringValue The string value
54+
*/
955
class StringToken(val stringValue: String, line: Int, column: Int) : Token(TokenType.STRING, stringValue, line, column)
56+
57+
/**
58+
* Represents a numeric literal token.
59+
* Example: `123`, `3.14`, `0xFF`, `Infinity`, `NaN`
60+
* @param numberValue The numeric value as Double
61+
*/
1062
class NumericToken(val numberValue: Double, line: Int, column: Int) : Token(TokenType.NUMERIC, numberValue, line, column)
63+
64+
/**
65+
* Represents a punctuator token.
66+
* Example: `{`, `}`, `[`, `]`, `:`, `,`
67+
* @param punctuator The punctuator character as string
68+
*/
1169
class PunctuatorToken(val punctuator: String, line: Int, column: Int) : Token(TokenType.PUNCTUATOR, punctuator, line, column)
70+
71+
/**
72+
* Represents an identifier token (unquoted property names).
73+
* Example: `foo`, `_bar`, `$baz`
74+
* @param identifierValue The identifier string
75+
*/
1276
class IdentifierToken(val identifierValue: String, line: Int, column: Int) : Token(TokenType.IDENTIFIER, identifierValue, line, column)
77+
78+
/**
79+
* Represents the end of the input stream.
80+
* Example: (no more tokens)
81+
*/
1382
class EOFToken(line: Int, column: Int) : Token(TokenType.EOF, null, line, column)
1483
}
1584

0 commit comments

Comments
 (0)