From dbbe0198d5ca83ee58f733ae2b1a55f246eb17e8 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 2 Sep 2022 23:38:30 -0400 Subject: [PATCH] Phrases in functions are now ToString'd --- parser/argument.go | 9 ++++++--- parser/tree-tostring.go | 36 +++++++++++++++++------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/parser/argument.go b/parser/argument.go index a1e5993..c77d8e8 100644 --- a/parser/argument.go +++ b/parser/argument.go @@ -48,7 +48,7 @@ func (parser *ParsingOperation) parseArgument () (argument Argument, err error) } } else { argument.kind = ArgumentKindIdentifier - argument.value = identifier + argument.value = &identifier } case lexer.TokenKindInt: @@ -77,9 +77,12 @@ func (parser *ParsingOperation) parseArgument () (argument Argument, err error) parser.nextToken() case lexer.TokenKindLBracket: - argument.kind = ArgumentKindPhrase - argument.value, err = parser.parseArgumentLevelPhrase() + argument.kind = ArgumentKindPhrase + var phrase Phrase + phrase, err = parser.parseArgumentLevelPhrase() + argument.value = &phrase parser.nextToken() + default: panic ( diff --git a/parser/tree-tostring.go b/parser/tree-tostring.go index 07734a7..79e1883 100644 --- a/parser/tree-tostring.go +++ b/parser/tree-tostring.go @@ -153,24 +153,15 @@ func (values *ArrayInitializationValues) ToString ( return } -func (phrase *Phrase) ToString (indent int, breakLine bool) (output string) { - if breakLine { - output += doIndent ( - indent, - "[", phrase.command.ToString(0, false)) - output += "\n" - for _, argument := range phrase.arguments { - output += doIndent ( - indent, - argument.ToString(indent + 1, true)) - } - } else { - output += "[" + phrase.command.ToString(0, false) - for _, argument := range phrase.arguments { - output += " " + argument.ToString(0, false) - } +func (phrase *Phrase) ToString (indent int, ownLine bool) (output string) { + if ownLine { + output += doIndent(indent) } + output += "[" + phrase.command.ToString(0, false) + for _, argument := range phrase.arguments { + output += " " + argument.ToString(0, false) + } output += "]" if len(phrase.returnsTo) > 0 { @@ -180,7 +171,7 @@ func (phrase *Phrase) ToString (indent int, breakLine bool) (output string) { } } - if breakLine { + if ownLine { output += "\n" } return @@ -395,6 +386,14 @@ func (behavior *FaceBehavior) ToString (indent int) (output string) { return } +func (block Block) ToString (indent int) (output string) { + for _, phrase := range block { + output += phrase.ToString(indent, true) + } + + return +} + func (section *FuncSection) ToString (indent int) (output string) { output += doIndent ( indent, @@ -422,7 +421,6 @@ func (section *FuncSection) ToString (indent int) (output string) { output += doIndent(indent + 1, "external\n") } - // TODO: print out root block - + output += section.root.ToString(indent + 1) return }