@@ -33,7 +33,6 @@ export class ANplusBParser {
3333 this . lexer . pos = start
3434 this . lexer . line = line
3535
36- let a : string | null = null
3736 let b : string | null = null
3837 let a_start = start
3938 let a_end = start
@@ -56,11 +55,9 @@ export class ANplusBParser {
5655 const text = this . source . substring ( this . lexer . token_start , this . lexer . token_end ) . toLowerCase ( )
5756
5857 if ( text === 'odd' || text === 'even' ) {
59- // Store the keyword as authored
60- a = this . source . substring ( this . lexer . token_start , this . lexer . token_end )
6158 a_start = this . lexer . token_start
6259 a_end = this . lexer . token_end
63- return this . create_anplusb_node ( node_start , a , null , a_start , a_end , 0 , 0 )
60+ return this . create_anplusb_node ( node_start , a_start , a_end , 0 , 0 )
6461 }
6562
6663 // Check if it's 'n', '-n', or starts with 'n'
@@ -74,18 +71,15 @@ export class ANplusBParser {
7471 const third_char = this . source . charCodeAt ( this . lexer . token_start + 2 )
7572 if ( third_char === CHAR_MINUS_HYPHEN /* - */ ) {
7673 // -n-5 pattern
77- a = '-n'
7874 a_start = this . lexer . token_start
7975 a_end = this . lexer . token_start + 2
8076 b = this . source . substring ( this . lexer . token_start + 2 , this . lexer . token_end )
8177 b_start = this . lexer . token_start + 2
8278 b_end = this . lexer . token_end
83- return this . create_anplusb_node ( node_start , a , b , a_start , a_end , b_start , b_end )
79+ return this . create_anplusb_node ( node_start , a_start , a_end , b_start , b_end )
8480 }
8581 }
8682
87- // Store -n as authored
88- a = '-n'
8983 a_start = this . lexer . token_start
9084 a_end = this . lexer . token_start + 2
9185
@@ -95,7 +89,7 @@ export class ANplusBParser {
9589 b_start = this . lexer . token_start
9690 b_end = this . lexer . token_end
9791 }
98- return this . create_anplusb_node ( node_start , a , b , a_start , a_end , b_start , b_end )
92+ return this . create_anplusb_node ( node_start , a_start , a_end , b !== null ? b_start : 0 , b !== null ? b_end : 0 )
9993 }
10094
10195 // n, n+3, n-5
@@ -105,18 +99,16 @@ export class ANplusBParser {
10599 const second_char = this . source . charCodeAt ( this . lexer . token_start + 1 )
106100 if ( second_char === CHAR_MINUS_HYPHEN /* - */ ) {
107101 // n-5 pattern
108- a = 'n'
102+ // a = 'n'
109103 a_start = this . lexer . token_start
110104 a_end = this . lexer . token_start + 1
111105 b = this . source . substring ( this . lexer . token_start + 1 , this . lexer . token_end )
112106 b_start = this . lexer . token_start + 1
113107 b_end = this . lexer . token_end
114- return this . create_anplusb_node ( node_start , a , b , a_start , a_end , b_start , b_end )
108+ return this . create_anplusb_node ( node_start , a_start , a_end , b_start , b_end )
115109 }
116110 }
117111
118- // Store n as authored
119- a = 'n'
120112 a_start = this . lexer . token_start
121113 a_end = this . lexer . token_start + 1
122114
@@ -126,7 +118,7 @@ export class ANplusBParser {
126118 b_start = this . lexer . token_start
127119 b_end = this . lexer . token_end
128120 }
129- return this . create_anplusb_node ( node_start , a , b , a_start , a_end , b_start , b_end )
121+ return this . create_anplusb_node ( node_start , a_start , a_end , b !== null ? b_start : 0 , b !== null ? b_end : 0 )
130122 }
131123
132124 // Not a valid An+B pattern
@@ -144,8 +136,6 @@ export class ANplusBParser {
144136 const first_char = text . charCodeAt ( 0 )
145137
146138 if ( first_char === 0x6e /* n */ ) {
147- // Store +n as authored (including the +)
148- a = '+n'
149139 a_start = saved . pos - 1 // Position of the + delim
150140 a_end = this . lexer . token_start + 1
151141
@@ -157,7 +147,7 @@ export class ANplusBParser {
157147 b = this . source . substring ( this . lexer . token_start + 1 , this . lexer . token_end )
158148 b_start = this . lexer . token_start + 1
159149 b_end = this . lexer . token_end
160- return this . create_anplusb_node ( node_start , a , b , a_start , a_end , b_start , b_end )
150+ return this . create_anplusb_node ( node_start , a_start , a_end , b_start , b_end )
161151 }
162152 }
163153
@@ -167,7 +157,7 @@ export class ANplusBParser {
167157 b_start = this . lexer . token_start
168158 b_end = this . lexer . token_end
169159 }
170- return this . create_anplusb_node ( node_start , a , b , a_start , a_end , b_start , b_end )
160+ return this . create_anplusb_node ( node_start , a_start , a_end , b !== null ? b_start : 0 , b !== null ? b_end : 0 )
171161 }
172162 }
173163
@@ -180,8 +170,6 @@ export class ANplusBParser {
180170 const n_index = token_text . toLowerCase ( ) . indexOf ( 'n' )
181171
182172 if ( n_index !== - 1 ) {
183- // Store 'a' coefficient including the 'n'
184- a = token_text . substring ( 0 , n_index + 1 )
185173 a_start = this . lexer . token_start
186174 a_end = this . lexer . token_start + n_index + 1
187175
@@ -194,7 +182,7 @@ export class ANplusBParser {
194182 b = remainder
195183 b_start = this . lexer . token_start + n_index + 1
196184 b_end = this . lexer . token_end
197- return this . create_anplusb_node ( node_start , a , b , a_start , a_end , b_start , b_end )
185+ return this . create_anplusb_node ( node_start , a_start , a_end , b_start , b_end )
198186 }
199187 }
200188
@@ -204,7 +192,7 @@ export class ANplusBParser {
204192 b_start = this . lexer . token_start
205193 b_end = this . lexer . token_end
206194 }
207- return this . create_anplusb_node ( node_start , a , b , a_start , a_end , b_start , b_end )
195+ return this . create_anplusb_node ( node_start , a_start , a_end , b_start , b_end )
208196 }
209197 }
210198
@@ -214,7 +202,7 @@ export class ANplusBParser {
214202 b = num_text
215203 b_start = this . lexer . token_start
216204 b_end = this . lexer . token_end
217- return this . create_anplusb_node ( node_start , a , b , a_start , a_end , b_start , b_end )
205+ return this . create_anplusb_node ( node_start , 0 , 0 , b_start , b_end )
218206 }
219207
220208 return null
@@ -278,8 +266,6 @@ export class ANplusBParser {
278266
279267 private create_anplusb_node (
280268 start : number ,
281- a : string | null ,
282- b : string | null ,
283269 a_start : number ,
284270 a_end : number ,
285271 b_start : number ,
@@ -291,14 +277,14 @@ export class ANplusBParser {
291277 this . arena . set_length ( node , this . lexer . pos - start )
292278 this . arena . set_start_line ( node , this . lexer . line )
293279
294- // Store 'a' coefficient in content fields
295- if ( a !== null ) {
280+ // Store 'a' coefficient in content fields if it exists (length > 0)
281+ if ( a_end > a_start ) {
296282 this . arena . set_content_start ( node , a_start )
297283 this . arena . set_content_length ( node , a_end - a_start )
298284 }
299285
300- // Store 'b' coefficient in value fields
301- if ( b !== null ) {
286+ // Store 'b' coefficient in value fields if it exists (length > 0)
287+ if ( b_end > b_start ) {
302288 this . arena . set_value_start ( node , b_start )
303289 this . arena . set_value_length ( node , b_end - b_start )
304290 }
0 commit comments