From 51428e3755193ae1d7e3cb5c1880c44e655d0c87 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 29 Sep 2022 11:15:58 -0400 Subject: [PATCH] Pass skim test --- parser/parser.go | 27 +++++++++++++++++++++++---- parser/skim_test.go | 2 +- tests/parser/skim/main.arf | 4 +++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/parser/parser.go b/parser/parser.go index b64f89c..1e54f3f 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -150,16 +150,35 @@ func (parser *ParsingOperation) previousToken () { // skipIndentLevel advances the parser, ignoring every line with an indentation // equal to or greater than the specified indent. func (parser *ParsingOperation) skipIndentLevel (indent int) (err error) { + braceLevel := 0 + parenLevel := 0 + bracketLevel := 0 + for { if parser.token.Is(lexer.TokenKindNewline) { err = parser.nextToken() if err != nil { return } - if !parser.token.Is(lexer.TokenKindIndent) || - parser.token.Value().(int) < indent { + shouldBreak := + !parser.token.Is(lexer.TokenKindIndent) || + parser.token.Value().(int) < indent + + shouldBreak = + shouldBreak && + braceLevel < 1 && + parenLevel < 1 && + bracketLevel < 1 - return - } + if shouldBreak { return } + } + + switch parser.token.Kind() { + case lexer.TokenKindLBrace: braceLevel ++ + case lexer.TokenKindRBrace: braceLevel -- + case lexer.TokenKindLParen: parenLevel ++ + case lexer.TokenKindRParen: parenLevel -- + case lexer.TokenKindLBracket: bracketLevel ++ + case lexer.TokenKindRBracket: bracketLevel -- } err = parser.nextToken() diff --git a/parser/skim_test.go b/parser/skim_test.go index 44eed97..372f0a9 100644 --- a/parser/skim_test.go +++ b/parser/skim_test.go @@ -21,7 +21,7 @@ func ro fComplexFunction external func ro gExternalFunction > x:Int - < arr:Int + < arr:Int 5 --- external `, test) diff --git a/tests/parser/skim/main.arf b/tests/parser/skim/main.arf index bfeba2d..e2bfed6 100644 --- a/tests/parser/skim/main.arf +++ b/tests/parser/skim/main.arf @@ -20,7 +20,9 @@ data ro eIntegerArrayInitialized:Int:16:mut func ro fComplexFunction --- = x:Int 3 - = y:{Int} [loc x] + = y:{Int +} [loc x +] = z:Int:8 ( 398 9 2309 983 -2387 478 555 123)