From 4228d2b4cf368a2687f10e648aad77de90019637 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 27 Sep 2022 14:48:05 -0400 Subject: [PATCH] Operators can no longer be arguments --- parser/phrase.go | 22 +++++++++++++--------- parser/tree.go | 13 +++++++------ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/parser/phrase.go b/parser/phrase.go index 7db3fbd..bcf71f3 100644 --- a/parser/phrase.go +++ b/parser/phrase.go @@ -129,7 +129,10 @@ func (parser *ParsingOperation) parseBlockLevelPhrase ( // get command err = parser.expect(validPhraseStartTokens...) if err != nil { return } - phrase.command, phrase.kind, err = parser.parsePhraseCommand() + phrase.command, + phrase.kind, + phrase.operator, + err = parser.parsePhraseCommand() if err != nil { return } for { @@ -233,7 +236,10 @@ func (parser *ParsingOperation) parseArgumentLevelPhrase () ( // get command err = parser.nextToken(validPhraseStartTokens...) if err != nil { return } - phrase.command, phrase.kind, err = parser.parsePhraseCommand() + phrase.command, + phrase.kind, + phrase.operator, + err = parser.parsePhraseCommand() if err != nil { return } for { @@ -272,24 +278,22 @@ func (parser *ParsingOperation) parseArgumentLevelPhrase () ( // parsePhraseCommand parses the command argument of a phrase. func (parser *ParsingOperation) parsePhraseCommand () ( - command Argument, - kind PhraseKind, - err error, + command Argument, + kind PhraseKind, + operator lexer.TokenKind, + err error, ) { if isTokenOperator(parser.token) { err = parser.expect(operatorTokens...) if err != nil { return } - command.location = parser.token.Location() - command.kind = ArgumentKindOperator - command.value = parser.token.Kind() - if parser.token.Is(lexer.TokenKindColon) { kind = PhraseKindCase } else if parser.token.Is(lexer.TokenKindAssignment) { kind = PhraseKindAssign } else { kind = PhraseKindOperator + operator = parser.token.Kind() } err = parser.nextToken() diff --git a/parser/tree.go b/parser/tree.go index af89a49..cb3a8a2 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -2,6 +2,7 @@ package parser import "git.tebibyte.media/arf/arf/file" import "git.tebibyte.media/arf/arf/types" +import "git.tebibyte.media/arf/arf/lexer" import "git.tebibyte.media/arf/arf/infoerr" // SyntaxTree represents an abstract syntax tree. It covers an entire module. It @@ -135,10 +136,6 @@ const ( // 'S' ArgumentKindRune - - // + - * / etc... - // this is only used as a phrase command - ArgumentKindOperator ) // Argument represents a value that can be placed anywhere a value goes. This @@ -229,11 +226,15 @@ const ( // syntactical concept. type Phrase struct { location file.Location - command Argument returnees []Argument multiValuable - + kind PhraseKind + + command Argument + + // only applicable for PhraseKindOperator + operator lexer.TokenKind // only applicable for control flow phrases block Block