Add unit specifiers to constant access

This commit is contained in:
Sasha Koshka 2024-04-06 13:49:11 -04:00
parent 386c39126d
commit d8f897d023
3 changed files with 34 additions and 22 deletions

View File

@ -630,17 +630,24 @@ var _ Expression = &Constant { }
// an interface.
type Constant struct {
// Syntax
Pos errors.Position
TypeName string
Name string
Pos errors.Position
UnitNickname string
TypeName string
Name string
// Semantics
Ty Type
Ty Type
Unit uuid.UUID
}
func (*Constant) expression(){}
func (this *Constant) Position () errors.Position { return this.Pos }
func (this *Constant) Type () Type { return this.Ty }
func (this *Constant) HasExplicitType () bool { return true }
func (this *Constant) String () string {
return fmt.Sprint(this.TypeName, ".", this.Name)
output := ""
if this.UnitNickname != "" {
output += fmt.Sprint(this.UnitNickname, "::")
}
output += fmt.Sprint(this.TypeName, ".", this.Name)
return output
}

View File

@ -74,28 +74,29 @@ expression, the parser follows this decision tree to determine what to parse:
| | 'loop' =Loop
| | 'for' =For
| | +Colon =Declaration
| | +DoubleColon =Call
| | +DoubleColon | +TypeIdent =(A)
| | +LBracket =(B)
|
| +TypeIdent =Constant
| +TypeIdent(A) =Constant
|
| +LParen X =LiteralArray
| | +Dot =LiteralStruct
|
| +LBracket | +Ident =Call
| | | 'break' =Break
| | | 'return' =Return
| |
| | +Dot +Expression =Dereference
| | | +Expression =Subscript
| | +Star =Operation
| |
| | +Symbol X
| | '\' =Slice
| | '#' =Length
| | '@' =Reference
| | '~' =ValueCast
| | '~~' =BitCast
| | OPERATOR =Operation
| +LBracket(B) | +Ident =Call
| | | 'break' =Break
| | | 'return' =Return
| |
| | +Dot +Expression =Dereference
| | | +Expression =Subscript
| | +Star =Operation
| |
| | +Symbol X
| | '\' =Slice
| | '#' =Length
| | '@' =Reference
| | '~' =ValueCast
| | '~~' =BitCast
| | OPERATOR =Operation
|
| +LBrace =Block
| +Int =LiteralInt

View File

@ -147,6 +147,10 @@ testString (test,
| FD.stdin 'in'
| FD.stdout 'out'
* '?'
[whatFile2 fd:io::FD]:String = switch fd
| io::FD.stdin 'in'
| io::FD.stdout 'out'
* '?'
`)
}