Parse constant access unit specifiers

This commit is contained in:
Sasha Koshka 2024-04-06 14:01:14 -04:00
parent 2346c34cce
commit e12e83921b
2 changed files with 21 additions and 9 deletions

View File

@ -97,7 +97,7 @@ func (this *treeParser) parseExpressionRoot () (entity.Expression, error) {
switch this.Kind() { switch this.Kind() {
case lexer.Ident: return this.parseExpressionRootIdent() case lexer.Ident: return this.parseExpressionRootIdent()
case lexer.TypeIdent: return this.parseConstant() case lexer.TypeIdent: return this.parseConstantCore(this.Pos(), "")
case lexer.LParen: return this.parseExpressionRootLParen() case lexer.LParen: return this.parseExpressionRootLParen()
case lexer.LBracket: return this.parseExpressionRootLBracket() case lexer.LBracket: return this.parseExpressionRootLBracket()
case lexer.LBrace: return this.parseBlock() case lexer.LBrace: return this.parseBlock()
@ -129,11 +129,19 @@ func (this *treeParser) parseExpressionRootIdent () (entity.Expression, error) {
// Colon: declaration // Colon: declaration
return this.parseDeclarationCore(pos, name) return this.parseDeclarationCore(pos, name)
case lexer.DoubleColon: case lexer.DoubleColon:
// DoubleColon: call // DoubleColon: call, constant
err := this.ExpectNext(lexer.LBracket) err := this.ExpectNext(lexer.LBracket, lexer.TypeIdent)
if err != nil { return nil, err } if err != nil { return nil, err }
this.Next()
return this.parseCallCore(pos, name) switch this.Kind() {
case lexer.TypeIdent:
// TypeIdent: constant
return this.parseConstantCore(pos, name)
case lexer.LBracket:
// LBracket: call
this.Next()
return this.parseCallCore(pos, name)
}
default: default:
// *: variable // *: variable
return &entity.Variable { return &entity.Variable {
@ -142,6 +150,7 @@ func (this *treeParser) parseExpressionRootIdent () (entity.Expression, error) {
}, nil }, nil
} }
} }
panic(this.bug())
} }
func (this *treeParser) parseExpressionRootLParen () (entity.Expression, error) { func (this *treeParser) parseExpressionRootLParen () (entity.Expression, error) {
@ -719,12 +728,14 @@ func (this *treeParser) parseFor () (*entity.For, error) {
return loop, nil return loop, nil
} }
func (this *treeParser) parseConstant () (*entity.Constant, error) { func (this *treeParser) parseConstantCore (pos errors.Position, unitNickname string) (*entity.Constant, error) {
pos = pos.Union(this.Pos())
err := this.Expect(lexer.TypeIdent) err := this.Expect(lexer.TypeIdent)
if err != nil { return nil, err } if err != nil { return nil, err }
constant := &entity.Constant { constant := &entity.Constant {
Pos: this.Pos(), Pos: this.Pos(),
TypeName: this.Value(), UnitNickname: unitNickname,
TypeName: this.Value(),
} }
err = this.ExpectNext(lexer.Dot) err = this.ExpectNext(lexer.Dot)

View File

@ -84,7 +84,8 @@ testString (test,
- [for s:String] = for e:Byte in s [break e] - [for s:String] = for e:Byte in s [break e]
- [matchToInt u:(| Int F64)]:Int = match u | u:Int u | u:F64 [~ Int u] * 0 - [matchToInt u:(| Int F64)]:Int = match u | u:Int u | u:F64 [~ Int u] * 0
- [switch x:Int] = switch x | 0 5 | 1 4 | 2 3 * 0 - [switch x:Int] = switch x | 0 5 | 1 4 | 2 3 * 0
- [whatFile fd:FD]:String = switch fd | FD.stdin 'in' | FD.stdout 'out' * '?'`, - [whatFile fd:FD]:String = switch fd | FD.stdin 'in' | FD.stdout 'out' * '?'
- [whatFile2 fd:io::FD]:String = switch fd | io::FD.stdin 'in' | io::FD.stdout 'out' * '?'`,
// input // input
` `
[var] = sdfdf [var] = sdfdf