Skip to content

Commit

Permalink
refactor(assembler/parser): inline function
Browse files Browse the repository at this point in the history
  • Loading branch information
exuanbo committed Nov 28, 2023
1 parent 9e0628f commit 18c8a89
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/features/assembler/core/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,21 @@ const parseDoubleOperands =
<T1 extends OperandType, T2 extends OperandType>(
...expectedTypePairs: Array<[firstOperandType: T1, secondOperandType: T2]>
): [firstOperand: Operand<T1>, secondOperand: Operand<T2>] => {
const parseOperand = parseSingleOperand(tokenizer)
const possibleFirstOperandTypes: T1[] = []
expectedTypePairs.forEach(([firstOperandType]) => {
if (!possibleFirstOperandTypes.includes(firstOperandType)) {
possibleFirstOperandTypes.push(firstOperandType)
}
})
const firstOperand = parseOperand(...possibleFirstOperandTypes)
const firstOperand = parseSingleOperand(tokenizer)(...possibleFirstOperandTypes)
tokenizer.match(TokenType.Comma, token => new MissingCommaError(token))
const possibleSecondOperandTypes: T2[] = []
expectedTypePairs.forEach(([firstOperandType, secondOperandType]) => {
if (firstOperandType === firstOperand.type) {
possibleSecondOperandTypes.push(secondOperandType)
}
})
const secondOperand = parseOperand(...possibleSecondOperandTypes)
const secondOperand = parseSingleOperand(tokenizer)(...possibleSecondOperandTypes)
return [firstOperand, secondOperand]
}

Expand Down

0 comments on commit 18c8a89

Please sign in to comment.