From 85f97189acc533b8d1a908d90769c61b612c309e Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 17 Sep 2022 12:30:56 -0400 Subject: [PATCH] Cleaned up phrase parsing a bit --- parser/phrase.go | 28 ++++++++++------------------ parser/tree.go | 1 + 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/parser/phrase.go b/parser/phrase.go index f1c882f..7db3fbd 100644 --- a/parser/phrase.go +++ b/parser/phrase.go @@ -139,25 +139,16 @@ func (parser *ParsingOperation) parseBlockLevelPhrase ( err = parser.expect(validDelimitedPhraseTokens...) if err != nil { return } + // we are delimited so we can safely skip whitespace + err = parser.skipWhitespace() + if err != nil { return } + if parser.token.Is(lexer.TokenKindRBracket) { // this is an ending delimiter err = parser.nextToken() if err != nil { return } break - } else if parser.token.Is(lexer.TokenKindNewline) { - // we are delimited, so we can safely skip - // newlines - err = parser.nextToken() - if err != nil { return } - continue - - } else if parser.token.Is(lexer.TokenKindIndent) { - // we are delimited, so we can safely skip - // indents - err = parser.nextToken() - if err != nil { return } - continue } } else { // not delimited @@ -176,7 +167,7 @@ func (parser *ParsingOperation) parseBlockLevelPhrase ( } } - // this is an argument + // if we've got this far, we are parsing an argument var argument Argument argument, err = parser.parseArgument() phrase.arguments = append(phrase.arguments, argument) @@ -222,10 +213,9 @@ func (parser *ParsingOperation) parseBlockLevelPhrase ( } } - if !isControlFlow { return } - - // if it is any of those, parse the block under it - phrase.block, err = parser.parseBlock(indent + 1) + if isControlFlow { + phrase.block, err = parser.parseBlock(indent + 1) + } return } @@ -318,6 +308,8 @@ func (parser *ParsingOperation) parsePhraseCommand () ( identifier := command.value.(Identifier) if len(identifier.trail) == 1 { switch identifier.trail[0] { + case "let": + kind = PhraseKindLet case "loc": kind = PhraseKindReference case "defer": diff --git a/parser/tree.go b/parser/tree.go index 47862a9..3a7745a 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -231,6 +231,7 @@ const ( PhraseKindCall = iota PhraseKindCallExternal PhraseKindOperator + PhraseKindLet PhraseKindAssign PhraseKindReference PhraseKindDefer