feat: add molang package
1. upgrade bukkit chat 2. fix config update error Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
22
packages/molang/src/parser/parselets/arrayAccess.ts
Normal file
22
packages/molang/src/parser/parselets/arrayAccess.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Token } from '../../tokenizer/token'
|
||||
import { Parser } from '../parse'
|
||||
import { IInfixParselet } from './infix'
|
||||
import { IExpression } from '../expression'
|
||||
import { ArrayAccessExpression } from '../expressions/arrayAccess'
|
||||
|
||||
export class ArrayAccessParselet implements IInfixParselet {
|
||||
constructor(public precedence = 0) {}
|
||||
|
||||
parse(parser: Parser, left: IExpression, token: Token) {
|
||||
const expr = parser.parseExpression(this.precedence - 1)
|
||||
|
||||
if (!left.setPointer) throw new Error(`"${left.type}" is not an array`)
|
||||
|
||||
if (!parser.match('ARRAY_RIGHT'))
|
||||
throw new Error(
|
||||
`No closing bracket for opening bracket "[${expr.eval()}"`
|
||||
)
|
||||
|
||||
return new ArrayAccessExpression(left, expr)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user