Operators can no longer be arguments

This commit is contained in:
Sasha Koshka 2022-09-27 14:48:05 -04:00
parent 1ed612b3d1
commit 4228d2b4cf
2 changed files with 20 additions and 15 deletions

View File

@ -129,7 +129,10 @@ func (parser *ParsingOperation) parseBlockLevelPhrase (
// get command // get command
err = parser.expect(validPhraseStartTokens...) err = parser.expect(validPhraseStartTokens...)
if err != nil { return } if err != nil { return }
phrase.command, phrase.kind, err = parser.parsePhraseCommand() phrase.command,
phrase.kind,
phrase.operator,
err = parser.parsePhraseCommand()
if err != nil { return } if err != nil { return }
for { for {
@ -233,7 +236,10 @@ func (parser *ParsingOperation) parseArgumentLevelPhrase () (
// get command // get command
err = parser.nextToken(validPhraseStartTokens...) err = parser.nextToken(validPhraseStartTokens...)
if err != nil { return } if err != nil { return }
phrase.command, phrase.kind, err = parser.parsePhraseCommand() phrase.command,
phrase.kind,
phrase.operator,
err = parser.parsePhraseCommand()
if err != nil { return } if err != nil { return }
for { for {
@ -272,24 +278,22 @@ func (parser *ParsingOperation) parseArgumentLevelPhrase () (
// parsePhraseCommand parses the command argument of a phrase. // parsePhraseCommand parses the command argument of a phrase.
func (parser *ParsingOperation) parsePhraseCommand () ( func (parser *ParsingOperation) parsePhraseCommand () (
command Argument, command Argument,
kind PhraseKind, kind PhraseKind,
err error, operator lexer.TokenKind,
err error,
) { ) {
if isTokenOperator(parser.token) { if isTokenOperator(parser.token) {
err = parser.expect(operatorTokens...) err = parser.expect(operatorTokens...)
if err != nil { return } if err != nil { return }
command.location = parser.token.Location()
command.kind = ArgumentKindOperator
command.value = parser.token.Kind()
if parser.token.Is(lexer.TokenKindColon) { if parser.token.Is(lexer.TokenKindColon) {
kind = PhraseKindCase kind = PhraseKindCase
} else if parser.token.Is(lexer.TokenKindAssignment) { } else if parser.token.Is(lexer.TokenKindAssignment) {
kind = PhraseKindAssign kind = PhraseKindAssign
} else { } else {
kind = PhraseKindOperator kind = PhraseKindOperator
operator = parser.token.Kind()
} }
err = parser.nextToken() err = parser.nextToken()

View File

@ -2,6 +2,7 @@ package parser
import "git.tebibyte.media/arf/arf/file" import "git.tebibyte.media/arf/arf/file"
import "git.tebibyte.media/arf/arf/types" import "git.tebibyte.media/arf/arf/types"
import "git.tebibyte.media/arf/arf/lexer"
import "git.tebibyte.media/arf/arf/infoerr" import "git.tebibyte.media/arf/arf/infoerr"
// SyntaxTree represents an abstract syntax tree. It covers an entire module. It // SyntaxTree represents an abstract syntax tree. It covers an entire module. It
@ -135,10 +136,6 @@ const (
// 'S' // 'S'
ArgumentKindRune ArgumentKindRune
// + - * / etc...
// this is only used as a phrase command
ArgumentKindOperator
) )
// Argument represents a value that can be placed anywhere a value goes. This // Argument represents a value that can be placed anywhere a value goes. This
@ -229,11 +226,15 @@ const (
// syntactical concept. // syntactical concept.
type Phrase struct { type Phrase struct {
location file.Location location file.Location
command Argument
returnees []Argument returnees []Argument
multiValuable multiValuable
kind PhraseKind kind PhraseKind
command Argument
// only applicable for PhraseKindOperator
operator lexer.TokenKind
// only applicable for control flow phrases // only applicable for control flow phrases
block Block block Block