Remove the star from array literals
This commit is contained in:
parent
7f58f7da8b
commit
3cd3384006
|
@ -37,7 +37,7 @@ testStringErr (test,
|
|||
"cannot use array literal as Int", 3, 10,
|
||||
`
|
||||
[main] = {
|
||||
x:Int = (* 5)
|
||||
x:Int = (5)
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
@ -67,27 +67,27 @@ testStringErr (test,
|
|||
"expected 3 elements or less", 3, 12,
|
||||
`
|
||||
[main] = {
|
||||
x:3:Int = (* 1 2 3 4)
|
||||
x:3:Int = (1 2 3 4)
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
func TestAssignmentLiteralErrArrayWrongType (test *testing.T) {
|
||||
testStringErr (test,
|
||||
"cannot use float literal as Int", 3, 17,
|
||||
"cannot use float literal as Int", 3, 15,
|
||||
`
|
||||
[main] = {
|
||||
x:3:Int = (* 1 3.3 4)
|
||||
x:3:Int = (1 3.3 4)
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
func TestAssignmentLiteralErrSliceWrongType (test *testing.T) {
|
||||
testStringErr (test,
|
||||
"cannot use float literal as Int", 3, 17,
|
||||
"cannot use float literal as Int", 3, 15,
|
||||
`
|
||||
[main] = {
|
||||
x:*:Int = (* 1 3.3 4)
|
||||
x:*:Int = (1 3.3 4)
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ testStringErr (test,
|
|||
`
|
||||
Bird: (& [fly distance:F64] [land])
|
||||
[main] = {
|
||||
b:Bird = (* 1 2 3 4)
|
||||
b:Bird = (1 2 3 4)
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
@ -177,12 +177,12 @@ testString (test,
|
|||
e:Byte = 64
|
||||
z:UInt = 5
|
||||
x:Int = -5
|
||||
arr:4:2:Int = (*
|
||||
(* 1 2)
|
||||
(* 3 4)
|
||||
(* 5 6)
|
||||
(* 7 8))
|
||||
slice:*:Int = (* 3 1 2 3)
|
||||
arr:4:2:Int = (
|
||||
(1 2)
|
||||
(3 4)
|
||||
(5 6)
|
||||
(7 8))
|
||||
slice:*:Int = (3 1 2 3)
|
||||
struct:(. x:Int y:Int) = (.
|
||||
x: 9
|
||||
y: 10)
|
||||
|
@ -315,7 +315,7 @@ B:(& [g]:Int)
|
|||
j:Int = i.[g]
|
||||
k:B = i
|
||||
l:Int = k.[g]
|
||||
m:5:Int = (* 0 1 2 3 4)
|
||||
m:5:Int = (0 1 2 3 4)
|
||||
n:Int = [. m 3]
|
||||
o:*:Int = m
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[main]:I32 'main' = {
|
||||
arr:3:Int = (* 5 6 7)
|
||||
arr:3:Int = (5 6 7)
|
||||
for i:Index e:Int in arr {
|
||||
if [>= i 2] then [break]
|
||||
io::[println 'iter']
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[main]:I32 'main' = {
|
||||
arr:5:String = (* 'abc' 'def' 'ghi')
|
||||
arr:5:String = ('abc' 'def' 'ghi')
|
||||
for e:String in arr { io::[println e] [break] }
|
||||
0
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[main]:I32 'main' = {
|
||||
; array
|
||||
arr:3:String = (* 'a' 'b' 'c')
|
||||
arr:3:String = ('a' 'b' 'c')
|
||||
for e:String in arr io::[println e]
|
||||
|
||||
; slice
|
||||
|
|
|
@ -101,9 +101,10 @@ func (this *LiteralArray) Position () errors.Position { return this.Pos }
|
|||
func (this *LiteralArray) Type () Type { return this.Ty }
|
||||
func (this *LiteralArray) HasExplicitType () bool { return false }
|
||||
func (this *LiteralArray) String () string {
|
||||
out := "(*"
|
||||
for _, element := range this.Elements {
|
||||
out += fmt.Sprint(" ", element)
|
||||
out := "("
|
||||
for index, element := range this.Elements {
|
||||
if index > 0 { out += " " }
|
||||
out += fmt.Sprint(element)
|
||||
}
|
||||
return out + ")"
|
||||
}
|
||||
|
|
|
@ -68,9 +68,9 @@ define void @main() {
|
|||
`,
|
||||
`
|
||||
[main] 'main' = {
|
||||
a:3:Int = (* 1 3 5)
|
||||
b:*:Int = (* 4 6 8)
|
||||
c:*Int = (* 7 9 11)
|
||||
a:3:Int = (1 3 5)
|
||||
b:*:Int = (4 6 8)
|
||||
c:*Int = (7 9 11)
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
@ -97,9 +97,9 @@ define void @main() {
|
|||
`
|
||||
A: 2:2:Int
|
||||
[main] 'main' = {
|
||||
a:A = (*
|
||||
(* 70 90)
|
||||
(* 2 4))
|
||||
a:A = (
|
||||
(70 90)
|
||||
( 2 4))
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ testString (test,
|
|||
`,
|
||||
`
|
||||
[main] 'main' = {
|
||||
a:4:Int = (* 5 9 3)
|
||||
a:4:Int = (5 9 3)
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
@ -324,7 +324,7 @@ define void @main() {
|
|||
`
|
||||
A: 2:Int
|
||||
[main] 'main' = {
|
||||
a:A = (* 1 2)
|
||||
a:A = (1 2)
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
|
|
@ -74,9 +74,8 @@ expression, the parser follows this decision tree to determine what to parse:
|
|||
| | +Colon =Declaration
|
||||
| | +DoubleColon =Call
|
||||
|
|
||||
| +LParen X
|
||||
| | +Star =LiteralArray
|
||||
| | +Dot =LiteralStruct
|
||||
| +LParen X =LiteralArray
|
||||
| | +Dot =LiteralStruct
|
||||
|
|
||||
| +LBracket | +Ident =Call
|
||||
| | | 'break' =Break
|
||||
|
|
|
@ -141,16 +141,18 @@ func (this *treeParser) parseExpressionRootIdent () (entity.Expression, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (this *treeParser) parseExpressionRootLParen() (entity.Expression, error) {
|
||||
func (this *treeParser) parseExpressionRootLParen () (entity.Expression, error) {
|
||||
err := this.Expect(lexer.LParen)
|
||||
if err != nil { return nil, err }
|
||||
pos := this.Pos()
|
||||
|
||||
err = this.ExpectNext(lexer.Star, lexer.Dot)
|
||||
err = this.ExpectNextDesc (
|
||||
"struct or array literal",
|
||||
appendCopy(startTokensExpression, lexer.Dot)...)
|
||||
if err != nil { return nil, err }
|
||||
switch this.Kind() {
|
||||
case lexer.Star: return this.parseLiteralArrayCore(pos)
|
||||
case lexer.Dot: return this.parseLiteralStructCore(pos)
|
||||
case lexer.Dot: return this.parseLiteralStructCore(pos)
|
||||
default: return this.parseLiteralArrayCore(pos)
|
||||
}
|
||||
panic(this.bug())
|
||||
}
|
||||
|
@ -557,7 +559,7 @@ func (this *treeParser) parseIfElse () (*entity.IfElse, error) {
|
|||
|
||||
if this.Token.Is(lexer.Ident) && this.Token.ValueIs("else") {
|
||||
// Ident "else": false branch expression
|
||||
this.ExpectNextDesc("Branch expression", startTokensExpression...)
|
||||
this.ExpectNextDesc("branch expression", startTokensExpression...)
|
||||
ifElse.False, err = this.parseExpression()
|
||||
if err != nil { return nil, err }
|
||||
}
|
||||
|
|
|
@ -65,13 +65,10 @@ func (this *treeParser) parseLiteralNil () (*entity.LiteralNil, error) {
|
|||
}
|
||||
|
||||
func (this *treeParser) parseLiteralArrayCore (pos errors.Position) (*entity.LiteralArray, error) {
|
||||
err := this.Expect(lexer.Star)
|
||||
if err != nil { return nil, err }
|
||||
literal := &entity.LiteralArray {
|
||||
Pos: pos,
|
||||
}
|
||||
this.Next()
|
||||
|
||||
|
||||
for {
|
||||
err := this.ExpectDesc (
|
||||
"array literal element or end",
|
||||
|
|
|
@ -62,8 +62,8 @@ testString (test,
|
|||
- [call] = [print 3 1]
|
||||
- [emptyBlock] = {}
|
||||
- [nestedBlock] = {342 93.34 {3948 32}}
|
||||
- [subscript] = [.(* 3 1 2 4) 3]
|
||||
- [slice] = [\(* 1 2 3 4 5 6 7 8 9) consumed/]
|
||||
- [subscript] = [.(3 1 2 4) 3]
|
||||
- [slice] = [\(1 2 3 4 5 6 7 8 9) consumed/]
|
||||
- [dereference] = [.ptr]
|
||||
- [reference] = [@val]
|
||||
- [valueCast] = [~ F32 someValue]
|
||||
|
@ -91,8 +91,8 @@ testString (test,
|
|||
32
|
||||
}
|
||||
}
|
||||
[subscript] = [. (* 3 1 2 4) 3]
|
||||
[slice] = [\ (* 1 2 3 4 5 6 7 8 9) consumed/]
|
||||
[subscript] = [. (3 1 2 4) 3]
|
||||
[slice] = [\ (1 2 3 4 5 6 7 8 9) consumed/]
|
||||
[dereference] = [. ptr]
|
||||
[reference] = [@ val]
|
||||
[valueCast] = [~ F32 someValue]
|
||||
|
|
Loading…
Reference in New Issue