Phrases in functions are now ToString'd

This commit is contained in:
Sasha Koshka 2022-09-02 23:38:30 -04:00
parent eee50dc9b0
commit dbbe0198d5
2 changed files with 23 additions and 22 deletions

View File

@ -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 (

View File

@ -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
}