diff --git a/parser/data.go b/parser/data.go index fa4130b..918e0d2 100644 --- a/parser/data.go +++ b/parser/data.go @@ -61,16 +61,51 @@ func (parser *ParsingOperation) parseInitializationValues ( // check if line is indented one more than baseIndent if !parser.token.Is(lexer.TokenKindIndent) { return } if parser.token.Value().(int) != baseIndent + 1 { return } + + err = parser.nextToken() + if err != nil { return } if parser.token.Is(lexer.TokenKindDot) { // TODO: parse as object initialization } else { - // TODO: parse as array initialization + values, err = parser.parseArrayInitializationValues ( + baseIndent + 1) } return } +// parseArrayInitializationValues parses a list of array initialization values +// until the indentation lexel is not equal to indent. +func (parser *ParsingOperation) parseArrayInitializationValues ( + indent int, +) ( + values []Argument, + err error, +) { + for { + if parser.token.Is(lexer.TokenKindNewline) { + println("line break") + err = parser.nextToken() + if err != nil { return } + + if !parser.token.Is(lexer.TokenKindIndent) { break } + if parser.token.Value().(int) != indent { break } + err = parser.nextToken() + if err != nil { return } + } + if err != nil { return } + println(parser.token.Describe()) + + var argument Argument + argument, err = parser.parseArgument() + if err != nil { return } + values = append(values, argument) + } + + return +} + // parseType parses a type notation of the form Name, {Name}, etc. func (parser *ParsingOperation) parseType () (what Type, err error) { err = parser.expect(lexer.TokenKindName, lexer.TokenKindLBrace) diff --git a/tests/parser/data/main.arf b/tests/parser/data/main.arf index 8b03dcc..9d6e347 100644 --- a/tests/parser/data/main.arf +++ b/tests/parser/data/main.arf @@ -17,9 +17,9 @@ data wr integerArrayInitialized:{Int 16} 3948 293 293049 948 912 340 0 2304 0 4785 92 -data wr integerPointerInit:{Int} [& integer] +data wr integerPointerInit:{Int} #[& integer] -data wr mutIntegerPointerInit:{Int}:mut [& integer] +data wr mutIntegerPointerInit:{Int}:mut #[& integer] data wr object:Obj .this 324