Skip to content

Commit

Permalink
refactor(compiler): add advance() function
Browse files Browse the repository at this point in the history
  • Loading branch information
minenwerfer committed Jan 18, 2025
1 parent 69a49a3 commit bb235a2
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/compiler/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const parse = (tokens: (Token | undefined)[]) => {

const errors: Diagnostic[] = []

const advance = () => index++

const next = () => {
const token = tokens[index + 1]
if( !token ) {
Expand All @@ -59,10 +61,10 @@ export const parse = (tokens: (Token | undefined)[]) => {

const foldBrackets = () => {
if( match(TokenType.LeftBracket) ) {
index++
advance()
while( !match(TokenType.RightBracket) ) {
foldBrackets()
index++
advance()
}
}
}
Expand All @@ -85,7 +87,7 @@ export const parse = (tokens: (Token | undefined)[]) => {
const consume = <TTokenType extends TokenType, const TValue>(expected: TTokenType, value?: TValue): StrictToken<TTokenType, TValue> => {
const token = current()
if( match(expected, value) ) {
index++
advance()
return token as StrictToken<TTokenType, TValue>
}

Expand Down Expand Up @@ -488,16 +490,16 @@ export const parse = (tokens: (Token | undefined)[]) => {
}

while( match(TokenType.AttributeName) ) {
index++
advance()
if( match(TokenType.LeftParens) ) {
index++
advance()
while( !match(TokenType.RightParens) ) {
index++
advance()
}
}
}

index++
advance()
foldBrackets()
}
continue
Expand Down

0 comments on commit bb235a2

Please sign in to comment.