@@ -11,27 +11,6 @@ import io.github.cybercodernaj.parkour.lexer.internal.Lexer
11
11
* @since 0.2.0
12
12
*/
13
13
class LexerBuilder internal constructor() {
14
- internal var ignorePattern: Regex = Lexer .Defaults .ignorePattern
15
- private set
16
-
17
- internal var singleLineComments: Regex ? = Lexer .Defaults .singleLineComments
18
- private set
19
-
20
- internal var multilineComments: Pair <Regex , Regex >? = Lexer .Defaults .multilineComments
21
- private set
22
-
23
- internal var identifiers: Regex = Lexer .Defaults .identifiers
24
- private set
25
-
26
- private val _hardKeywords : MutableList <String > = mutableListOf ()
27
- internal val hardKeywords: List <String > get() = _hardKeywords
28
-
29
- private val _separators : MutableList <String > = mutableListOf ()
30
- internal val separators: List <String > get() = _separators
31
-
32
- private val _operators : MutableList <String > = mutableListOf ()
33
- internal val operators: List <String > get() = _operators
34
-
35
14
/* *
36
15
* The lexer will skip over any strings that match this regex.
37
16
* This acts like a token separator.
@@ -40,19 +19,15 @@ class LexerBuilder internal constructor() {
40
19
*
41
20
* ```kt
42
21
* val myLexer = lexer {
43
- * ignorePatterns( Regex("""\s+""") )
22
+ * ignorePatterns = Regex("""\s+""")
44
23
* }
45
24
* ```
46
25
*
47
- * @param regex regex of the pattern the lexer will not tokenize.
48
- *
49
26
* @see Lexer.Defaults.ignorePattern
50
27
* @author Nishant Aanjaney Jalan
51
28
* @since 0.2.0
52
29
*/
53
- fun ignorePattern (regex : Regex ) {
54
- ignorePattern = regex
55
- }
30
+ var ignorePattern: Regex = Lexer .Defaults .ignorePattern
56
31
57
32
/* *
58
33
* When the lexer identifies a [singleLineComments] pattern, it will skip to the next line
@@ -62,19 +37,15 @@ class LexerBuilder internal constructor() {
62
37
*
63
38
* ```kt
64
39
* val myLexer = lexer {
65
- * singleLineComments( Regex("//") )
40
+ * singleLineComments = Regex("//")
66
41
* }
67
42
* ```
68
43
*
69
- * @param singleLineComments regex of the pattern the lexer will skip over to the next line.
70
- *
71
44
* @see Lexer.Defaults.singleLineComments
72
45
* @author Nishant Aanjaney Jalan
73
46
* @since 0.2.0
74
47
*/
75
- fun singleLineComments (singleLineComments : Regex ) {
76
- this .singleLineComments = singleLineComments
77
- }
48
+ var singleLineComments: Regex ? = Lexer .Defaults .singleLineComments
78
49
79
50
/* *
80
51
* There are two parts to [multilineComments]: the starting and the ending pattern.
@@ -86,19 +57,15 @@ class LexerBuilder internal constructor() {
86
57
* ```kt
87
58
* val myLexer = lexer {
88
59
* // You don't need the square brackets but KDoc doesn't like it...
89
- * multilineComments( Regex("[/][*]") to Regex("[*][/]") )
60
+ * multilineComments = Regex("[/][*]") to Regex("[*][/]")
90
61
* }
91
62
* ```
92
63
*
93
- * @param multilineComments pair of regexes that define what contents are under comments.
94
- *
95
64
* @see Lexer.Defaults.multilineComments
96
65
* @author Nishant Aanjaney Jalan
97
66
* @since 0.2.0
98
67
*/
99
- fun multilineComments (multilineComments : Pair <Regex , Regex >) {
100
- this .multilineComments = multilineComments
101
- }
68
+ var multilineComments: Pair <Regex , Regex >? = Lexer .Defaults .multilineComments
102
69
103
70
/* *
104
71
* Supply the regex pattern that defines the rules for identifiers.
@@ -110,24 +77,38 @@ class LexerBuilder internal constructor() {
110
77
* ```kt
111
78
* val myLexer = lexer {
112
79
* // If all identifiers must be at least 2 characters and start with a lowercase english alphabet.
113
- * identifiers( Regex("[a-z][a-zA-Z0-9]+") )
80
+ * identifiers = Regex("[a-z][a-zA-Z0-9]+")
114
81
* }
115
82
* ```
116
83
*
117
- * @param identifiers regex defining the rules of the naming identifiers
118
- *
119
84
* @see Lexer.Defaults.identifiers
120
85
* @author Nishant Aanjaney Jalan
121
86
* @since 0.2.0
122
87
*/
123
- fun identifiers (identifiers : Regex ) {
124
- this .identifiers = identifiers
125
- }
88
+ var identifiers: Regex = Lexer .Defaults .identifiers
89
+
90
+ private val _hardKeywords : MutableList <String > = mutableListOf ()
91
+ internal val hardKeywords: List <String > get() = _hardKeywords
92
+
93
+ private val _separators : MutableList <String > = mutableListOf ()
94
+ internal val separators: List <String > get() = _separators
95
+
96
+ private val _operators : MutableList <String > = mutableListOf ()
97
+ internal val operators: List <String > get() = _operators
98
+
99
+ internal var integerLiteral: Regex = Lexer .Defaults .integerLiteral
100
+ private set
101
+
102
+ internal var floatingLiteral: Regex = Lexer .Defaults .floatingLiteral
103
+ private set
104
+
105
+ internal var singleLineString: Set <String > = Lexer .Defaults .singleLineString
106
+ private set
126
107
127
108
/* *
128
109
* Hard keywords are a characters and symbols that give a particular meaning to a program.
129
110
* They may not be used as identifiers.
130
- * (Default: [])
111
+ * You can add multiple keywords over many function calls.
131
112
*
132
113
* ### Usage
133
114
*
@@ -146,7 +127,8 @@ class LexerBuilder internal constructor() {
146
127
}
147
128
148
129
/* *
149
- * Separators are characters and symbols that act like delimiters to separate other meaningful elements. (Default: [])
130
+ * Separators are characters and symbols that act like delimiters to separate other meaningful elements.
131
+ * You can add multiple separators over many function calls.
150
132
*
151
133
* ### Usage
152
134
*
@@ -165,7 +147,8 @@ class LexerBuilder internal constructor() {
165
147
}
166
148
167
149
/* *
168
- * Operators are characters and symbols that may perform arithmetic or logical operations. (Default: [])
150
+ * Operators are characters and symbols that may perform arithmetic or logical operations.
151
+ * You can add multiple separators over many function calls.
169
152
*
170
153
* ### Usage
171
154
*
@@ -214,5 +197,8 @@ fun lexer(init: LexerBuilder.() -> Unit): Lexer {
214
197
hardKeywords = builder.hardKeywords.sortedByDescending(String ::length),
215
198
operators = builder.operators.sortedByDescending(String ::length),
216
199
separators = builder.separators.sortedByDescending(String ::length),
200
+ integerLiteral = builder.integerLiteral,
201
+ floatingLiteral = builder.floatingLiteral,
202
+ singleLineString = builder.singleLineString,
217
203
)
218
204
}
0 commit comments