@@ -77,7 +77,7 @@ export class Parser {
7777 if ( ! token || token . type !== expected ) {
7878 throw new InvalidSyntaxError (
7979 `Expected ${ expected } but got ${ token ? token . type : "EOF" } ` ,
80- token ?. offset || 0
80+ token ?. start || 0
8181 ) ;
8282 }
8383 this . #buffer. shift ( ) ;
@@ -99,17 +99,17 @@ export class Parser {
9999 } else if ( type in this . #types) {
100100 return this . #types[ type ] ;
101101 }
102- throw new InvalidSyntaxError ( `Invalid type "${ type } "` , token . offset ) ;
102+ throw new InvalidSyntaxError ( `Invalid type "${ type } "` , token . start ) ;
103103 }
104104
105105 #parseIdentifier( ) {
106106 const name = this . #consume( TokenTypes . IDENTIFIER ) ;
107- return new Identifier ( name . value ! , name . offset ) ;
107+ return new Identifier ( name . value ! , name . start ) ;
108108 }
109109
110110 #parseBoolLiteral( ) {
111111 const literal = this . #consume( TokenTypes . BOOL_LITERAL ) ;
112- return new BoolLiteral ( literal . value === "true" , literal . offset ) ;
112+ return new BoolLiteral ( literal . value === "true" , literal . start ) ;
113113 }
114114
115115 #parseNumberLiteral( ) {
@@ -124,27 +124,27 @@ export class Parser {
124124 if ( ! isNumericSuffix ( token . value ) ) {
125125 throw new InvalidSyntaxError (
126126 `Invalid suffix "${ token . value } "` ,
127- token . offset
127+ token . start
128128 ) ;
129129 }
130130
131131 suffix = token . value ;
132132 }
133133 }
134- return new NumberLiteral ( BigInt ( literal . value ! ) , suffix , literal . offset ) ;
134+ return new NumberLiteral ( BigInt ( literal . value ! ) , suffix , literal . start ) ;
135135 }
136136
137137 #parseStringLiteral( ) {
138138 const literal = this . #consume( TokenTypes . STRING_LITERAL ) ;
139- return new StringLiteral ( literal . value ! , literal . offset ) ;
139+ return new StringLiteral ( literal . value ! , literal . start ) ;
140140 }
141141
142142 #parseStringInterpolated( ) : InterpolatedString {
143143 const token = this . #consume( TokenTypes . STRING_INTERPOLATED ) ;
144144 const text = token . value ! . slice ( 2 , - 1 ) ;
145145 const parts = [ ] ;
146146
147- const start = token . offset + 2 ;
147+ const start = token . start + 2 ;
148148
149149 let index = 0 ;
150150
@@ -237,7 +237,7 @@ export class Parser {
237237 parts . push (
238238 new StringLiteral (
239239 "}" . repeat ( count / 2 ) ,
240- token . offset + braceStart + 1
240+ token . start + braceStart + 1
241241 )
242242 ) ;
243243 continue ;
@@ -246,7 +246,7 @@ export class Parser {
246246 // Odd number of closing braces with no matching opening
247247 throw new InvalidSyntaxError (
248248 "Unmatched closing brace" ,
249- token . offset + braceStart + 1
249+ token . start + braceStart + 1
250250 ) ;
251251 }
252252
@@ -267,13 +267,13 @@ export class Parser {
267267 ) ;
268268 }
269269 }
270- return new InterpolatedString ( parts , token . offset ) ;
270+ return new InterpolatedString ( parts , token . start ) ;
271271 }
272272
273273 #parseParameter( ) {
274274 const type = this . #type( ) ;
275275 const name = this . #consume( TokenTypes . IDENTIFIER ) ;
276- return new Parameter ( type , name . value ! , name . offset ) ;
276+ return new Parameter ( type , name . value ! , name . start ) ;
277277 }
278278
279279 #parseParameters( ) {
@@ -356,8 +356,8 @@ export class Parser {
356356 }
357357
358358 throw new InvalidSyntaxError (
359- `Unexpected token ${ next . type } at offset ${ next . offset } ` ,
360- next . offset
359+ `Unexpected token ${ next . type } at offset ${ next . start } ` ,
360+ next . start
361361 ) ;
362362 }
363363
@@ -370,7 +370,7 @@ export class Parser {
370370 return new FixExpression (
371371 FIX_TO_BINARY [ next . type ] ,
372372 expression ,
373- next . offset ,
373+ next . start ,
374374 true
375375 ) ;
376376 }
@@ -387,7 +387,7 @@ export class Parser {
387387 expression = new FixExpression (
388388 FIX_TO_BINARY [ next . type ] ,
389389 expression ,
390- next . offset ,
390+ next . start ,
391391 false
392392 ) ;
393393 }
@@ -400,7 +400,7 @@ export class Parser {
400400 if ( next && isUnaryOperator ( next . type ) ) {
401401 this . #consume( next . type ) ;
402402 const operand = this . #parseUnaryExpression( ) ;
403- return new UnaryExpression ( next . type , operand , next . offset ) ;
403+ return new UnaryExpression ( next . type , operand , next . start ) ;
404404 }
405405 return this . #parsePrefixExpression( ) ;
406406 }
@@ -420,7 +420,7 @@ export class Parser {
420420 const right = this . #parseBinaryExpression(
421421 info . associativity === "left" ? info . precedence + 1 : info . precedence
422422 ) ;
423- left = new BinaryExpression ( next . type , left , right , next . offset ) ;
423+ left = new BinaryExpression ( next . type , left , right , next . start ) ;
424424 next = this . #peek( ) ;
425425 }
426426 return left ;
@@ -440,7 +440,7 @@ export class Parser {
440440 condition ,
441441 consequent ,
442442 alternate ,
443- token . offset
443+ token . start
444444 ) ;
445445 }
446446 return condition ;
@@ -454,7 +454,7 @@ export class Parser {
454454 const type = this . #type( ) ;
455455 const name = this . #consume( TokenTypes . IDENTIFIER ) ;
456456 this . #consume( TokenTypes . SEMICOLON ) ;
457- return new FieldDeclaration ( type , name . value ! , name . offset ) ;
457+ return new FieldDeclaration ( type , name . value ! , name . start ) ;
458458 }
459459
460460 #parseFieldAssignment( ) {
@@ -468,7 +468,7 @@ export class Parser {
468468 parent . value ! ,
469469 member . value ! ,
470470 expression ,
471- member . offset
471+ member . start
472472 ) ;
473473 }
474474
@@ -485,15 +485,15 @@ export class Parser {
485485
486486 this . #consume( TokenTypes . SEMICOLON ) ;
487487
488- return new VariableDeclaration ( type , name . value ! , expression , name . offset ) ;
488+ return new VariableDeclaration ( type , name . value ! , expression , name . start ) ;
489489 }
490490
491491 #parseVariableAssignment( ) {
492492 const name = this . #consume( TokenTypes . IDENTIFIER ) ;
493493 this . #consume( TokenTypes . EQUAL ) ;
494494 const expression = this . parseExpression ( ) ;
495495 this . #consume( TokenTypes . SEMICOLON ) ;
496- return new VariableAssignment ( name . value ! , expression , name . offset ) ;
496+ return new VariableAssignment ( name . value ! , expression , name . start ) ;
497497 }
498498
499499 #parseCompoundVariableAssignment( ) : AnyAstNode {
@@ -503,7 +503,7 @@ export class Parser {
503503 if ( ! token || ! isCompoundOperator ( token . type ) ) {
504504 throw new InvalidSyntaxError (
505505 "Expected compound assignment operator" ,
506- token ?. offset || left . offset
506+ token ?. start || left . offset
507507 ) ;
508508 }
509509
@@ -515,7 +515,7 @@ export class Parser {
515515 COMPOUND_TO_BINARY [ token . type ] ,
516516 left ,
517517 right ,
518- token . offset
518+ token . start
519519 ) ;
520520 return new VariableAssignment ( left . name , expression , left . offset ) ;
521521 }
@@ -527,7 +527,7 @@ export class Parser {
527527 if ( ! token || ! isCompoundOperator ( token . type ) ) {
528528 throw new InvalidSyntaxError (
529529 "Expected compound assignment operator" ,
530- token ?. offset || left . offset
530+ token ?. start || left . offset
531531 ) ;
532532 }
533533
@@ -539,7 +539,7 @@ export class Parser {
539539 COMPOUND_TO_BINARY [ token . type ] ,
540540 left ,
541541 right ,
542- token . offset
542+ token . start
543543 ) ;
544544 return new FieldAssignment (
545545 left . object ,
@@ -591,7 +591,7 @@ export class Parser {
591591 const name = this . #value( TokenTypes . IDENTIFIER ) ;
592592 const fields = this . #parseFields( ) ;
593593 this . #types[ name ] = { kind : TypeKinds . STRUCT , name : name } ;
594- return new StructDeclaration ( name , fields , struct . offset ) ;
594+ return new StructDeclaration ( name , fields , struct . start ) ;
595595 }
596596
597597 #parseFunction( ) {
@@ -614,7 +614,7 @@ export class Parser {
614614 name ,
615615 params ,
616616 body ,
617- func . offset
617+ func . start
618618 ) ;
619619 }
620620
@@ -629,7 +629,7 @@ export class Parser {
629629
630630 this . #consume( TokenTypes . SEMICOLON ) ;
631631
632- return new ReturnStatement ( value , token . offset ) ;
632+ return new ReturnStatement ( value , token . start ) ;
633633 }
634634
635635 #parseIfStatement( ) : IfStatement {
@@ -648,7 +648,7 @@ export class Parser {
648648 alternate = this . #parseBlock( ) ;
649649 }
650650 }
651- return new IfStatement ( condition , consequent , alternate , token . offset ) ;
651+ return new IfStatement ( condition , consequent , alternate , token . start ) ;
652652 }
653653
654654 #parseForLoop( ) {
@@ -677,7 +677,7 @@ export class Parser {
677677
678678 const body = this . #parseBlock( ) ;
679679
680- return new LoopStatement ( declaration , condition , step , body , token . offset ) ;
680+ return new LoopStatement ( declaration , condition , step , body , token . start ) ;
681681 }
682682
683683 #parseStatement( ) : AnyAstNode {
0 commit comments