tree-tostring is free of compiler errors
This commit is contained in:
parent
cd9de16338
commit
26f887dfcc
@ -66,66 +66,12 @@ func (identifier Identifier) ToString () (output string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (values ObjectDefaultValues) ToString (
|
|
||||||
indent int,
|
|
||||||
breakLine bool,
|
|
||||||
) (
|
|
||||||
output string,
|
|
||||||
) {
|
|
||||||
if !breakLine { indent = 0 }
|
|
||||||
output += doIndent(indent, "(")
|
|
||||||
if breakLine { output += "\n" }
|
|
||||||
|
|
||||||
for index, name := range sortMapKeysAlphabetically(values) {
|
|
||||||
if index > 0 && !breakLine { output += " " }
|
|
||||||
|
|
||||||
value := values[name]
|
|
||||||
|
|
||||||
output += doIndent(indent, "." + name + ":")
|
|
||||||
|
|
||||||
isComplexDefaultValue :=
|
|
||||||
value.kind == ArgumentKindObjectDefaultValues ||
|
|
||||||
value.kind == ArgumentKindArrayDefaultValues
|
|
||||||
|
|
||||||
if isComplexDefaultValue {
|
|
||||||
if breakLine { output += "\n" }
|
|
||||||
output += value.ToString(indent + 1, breakLine)
|
|
||||||
} else {
|
|
||||||
output += "<"
|
|
||||||
output += value.ToString(indent + 1, false)
|
|
||||||
output += ">"
|
|
||||||
}
|
|
||||||
if breakLine { output += "\n" }
|
|
||||||
}
|
|
||||||
output += doIndent(indent, ")")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (values ArrayDefaultValues) ToString (
|
|
||||||
indent int,
|
|
||||||
breakLine bool,
|
|
||||||
) (
|
|
||||||
output string,
|
|
||||||
) {
|
|
||||||
if !breakLine { indent = 0 }
|
|
||||||
output += doIndent(indent, "<")
|
|
||||||
if breakLine { output += "\n" }
|
|
||||||
|
|
||||||
for index, value := range values {
|
|
||||||
if index > 0 && !breakLine { output += " " }
|
|
||||||
output += value.ToString(indent, breakLine)
|
|
||||||
}
|
|
||||||
|
|
||||||
output += doIndent(indent, ">")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (member TypeMember) ToString (indent int, breakLine bool) (output string) {
|
func (member TypeMember) ToString (indent int, breakLine bool) (output string) {
|
||||||
output += doIndent(indent, ".")
|
output += doIndent(indent, ".")
|
||||||
|
|
||||||
output += member.permission.ToString() + " "
|
output += member.permission.ToString() + " "
|
||||||
output += member.name + ":"
|
output += member.name + ":"
|
||||||
output += member.what.ToString(indent + 1, breakLine)
|
output += member.what.ToString()
|
||||||
|
|
||||||
if member.bitWidth > 0 {
|
if member.bitWidth > 0 {
|
||||||
output += fmt.Sprint(" & ", member.bitWidth)
|
output += fmt.Sprint(" & ", member.bitWidth)
|
||||||
@ -138,12 +84,12 @@ func (member TypeMember) ToString (indent int, breakLine bool) (output string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (what Type) ToString (indent int, breakLine bool) (output string) {
|
func (what Type) ToString () (output string) {
|
||||||
if what.kind == TypeKindBasic {
|
if what.kind == TypeKindBasic {
|
||||||
output += what.name.ToString()
|
output += what.name.ToString()
|
||||||
} else {
|
} else {
|
||||||
output += "{"
|
output += "{"
|
||||||
output += what.points.ToString(indent, breakLine)
|
output += what.points.ToString()
|
||||||
|
|
||||||
if what.kind == TypeKindVariableArray {
|
if what.kind == TypeKindVariableArray {
|
||||||
output += " .."
|
output += " .."
|
||||||
@ -159,46 +105,26 @@ func (what Type) ToString (indent int, breakLine bool) (output string) {
|
|||||||
if what.mutable {
|
if what.mutable {
|
||||||
output += ":mut"
|
output += ":mut"
|
||||||
}
|
}
|
||||||
|
|
||||||
if what.members != nil {
|
|
||||||
if breakLine {
|
|
||||||
output += ":\n" + doIndent(indent, "(\n")
|
|
||||||
for _, member := range what.members {
|
|
||||||
output += member.ToString(indent, breakLine)
|
|
||||||
}
|
|
||||||
output += doIndent(indent, ")")
|
|
||||||
} else {
|
|
||||||
output += ":("
|
|
||||||
for index, member := range what.members {
|
|
||||||
if index > 0 { output += " " }
|
|
||||||
output += member.ToString(indent, breakLine)
|
|
||||||
}
|
|
||||||
output += ")"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultValueKind := what.defaultValue.kind
|
|
||||||
if defaultValueKind != ArgumentKindNil {
|
|
||||||
isComplexDefaultValue :=
|
|
||||||
defaultValueKind == ArgumentKindObjectDefaultValues ||
|
|
||||||
defaultValueKind == ArgumentKindArrayDefaultValues
|
|
||||||
|
|
||||||
if isComplexDefaultValue {
|
|
||||||
output += ":"
|
|
||||||
if breakLine { output += "\n" }
|
|
||||||
output += what.defaultValue.ToString(indent, breakLine)
|
|
||||||
} else {
|
|
||||||
output += ":<"
|
|
||||||
output += what.defaultValue.ToString(indent, false)
|
|
||||||
output += ">"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (declaration Declaration) ToString (indent int) (output string) {
|
func (declaration Declaration) ToString (indent int) (output string) {
|
||||||
output += declaration.name + ":"
|
output += declaration.name + ":"
|
||||||
output += declaration.what.ToString(indent, false)
|
output += declaration.what.ToString()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (list List) ToString (indent int, breakline bool) (output string) {
|
||||||
|
if !breakline { indent = 0 }
|
||||||
|
output += doIndent(indent, "(")
|
||||||
|
if breakline { output += "\n" }
|
||||||
|
|
||||||
|
for _, argument := range list.arguments {
|
||||||
|
output += argument.ToString(indent, breakline)
|
||||||
|
}
|
||||||
|
|
||||||
|
output += doIndent(indent, "(")
|
||||||
|
if breakline { output += "\n" }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,13 +142,8 @@ func (argument Argument) ToString (indent int, breakLine bool) (output string) {
|
|||||||
indent,
|
indent,
|
||||||
breakLine)
|
breakLine)
|
||||||
|
|
||||||
case ArgumentKindObjectDefaultValues:
|
case ArgumentKindList:
|
||||||
output += argument.value.(ObjectDefaultValues).
|
output += argument.value.(List).ToString(indent, breakLine)
|
||||||
ToString(indent, breakLine)
|
|
||||||
|
|
||||||
case ArgumentKindArrayDefaultValues:
|
|
||||||
output += argument.value.(ArrayDefaultValues).
|
|
||||||
ToString(indent, breakLine)
|
|
||||||
|
|
||||||
case ArgumentKindIdentifier:
|
case ArgumentKindIdentifier:
|
||||||
output += doIndent (
|
output += doIndent (
|
||||||
@ -251,75 +172,6 @@ func (argument Argument) ToString (indent int, breakLine bool) (output string) {
|
|||||||
indent,
|
indent,
|
||||||
"'" + string(argument.value.(rune)) + "'")
|
"'" + string(argument.value.(rune)) + "'")
|
||||||
if breakLine { output += "\n" }
|
if breakLine { output += "\n" }
|
||||||
|
|
||||||
case ArgumentKindOperator:
|
|
||||||
var stringValue string
|
|
||||||
switch argument.value.(lexer.TokenKind) {
|
|
||||||
case lexer.TokenKindColon:
|
|
||||||
stringValue = ":"
|
|
||||||
case lexer.TokenKindPlus:
|
|
||||||
stringValue = "+"
|
|
||||||
case lexer.TokenKindMinus:
|
|
||||||
stringValue = "-"
|
|
||||||
case lexer.TokenKindIncrement:
|
|
||||||
stringValue = "++"
|
|
||||||
case lexer.TokenKindDecrement:
|
|
||||||
stringValue = "--"
|
|
||||||
case lexer.TokenKindAsterisk:
|
|
||||||
stringValue = "*"
|
|
||||||
case lexer.TokenKindSlash:
|
|
||||||
stringValue = "/"
|
|
||||||
case lexer.TokenKindExclamation:
|
|
||||||
stringValue = "!"
|
|
||||||
case lexer.TokenKindPercent:
|
|
||||||
stringValue = "%"
|
|
||||||
case lexer.TokenKindPercentAssignment:
|
|
||||||
stringValue = "%="
|
|
||||||
case lexer.TokenKindTilde:
|
|
||||||
stringValue = "~"
|
|
||||||
case lexer.TokenKindTildeAssignment:
|
|
||||||
stringValue = "~="
|
|
||||||
case lexer.TokenKindAssignment:
|
|
||||||
stringValue = "="
|
|
||||||
case lexer.TokenKindEqualTo:
|
|
||||||
stringValue = "=="
|
|
||||||
case lexer.TokenKindNotEqualTo:
|
|
||||||
stringValue = "!="
|
|
||||||
case lexer.TokenKindLessThanEqualTo:
|
|
||||||
stringValue = "<="
|
|
||||||
case lexer.TokenKindLessThan:
|
|
||||||
stringValue = "<"
|
|
||||||
case lexer.TokenKindLShift:
|
|
||||||
stringValue = "<<"
|
|
||||||
case lexer.TokenKindLShiftAssignment:
|
|
||||||
stringValue = "<<="
|
|
||||||
case lexer.TokenKindGreaterThan:
|
|
||||||
stringValue = ">"
|
|
||||||
case lexer.TokenKindGreaterThanEqualTo:
|
|
||||||
stringValue = ">="
|
|
||||||
case lexer.TokenKindRShift:
|
|
||||||
stringValue = ">>"
|
|
||||||
case lexer.TokenKindRShiftAssignment:
|
|
||||||
stringValue = ">>="
|
|
||||||
case lexer.TokenKindBinaryOr:
|
|
||||||
stringValue = "|"
|
|
||||||
case lexer.TokenKindBinaryOrAssignment:
|
|
||||||
stringValue = "|="
|
|
||||||
case lexer.TokenKindLogicalOr:
|
|
||||||
stringValue = "||"
|
|
||||||
case lexer.TokenKindBinaryAnd:
|
|
||||||
stringValue = "&"
|
|
||||||
case lexer.TokenKindBinaryAndAssignment:
|
|
||||||
stringValue = "&="
|
|
||||||
case lexer.TokenKindLogicalAnd:
|
|
||||||
stringValue = "&&"
|
|
||||||
case lexer.TokenKindBinaryXor:
|
|
||||||
stringValue = "^"
|
|
||||||
case lexer.TokenKindBinaryXorAssignment:
|
|
||||||
stringValue = "^="
|
|
||||||
}
|
|
||||||
output += doIndent(indent, stringValue)
|
|
||||||
if breakLine { output += "\n" }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -331,7 +183,9 @@ func (section DataSection) ToString (indent int) (output string) {
|
|||||||
"data ",
|
"data ",
|
||||||
section.permission.ToString(), " ",
|
section.permission.ToString(), " ",
|
||||||
section.name, ":",
|
section.name, ":",
|
||||||
section.what.ToString(indent + 1, true), "\n")
|
section.what.ToString(), "\n")
|
||||||
|
|
||||||
|
output += section.argument.ToString(indent + 1, true)
|
||||||
|
|
||||||
if section.external {
|
if section.external {
|
||||||
output += doIndent(indent + 1, "external\n")
|
output += doIndent(indent + 1, "external\n")
|
||||||
@ -346,32 +200,23 @@ func (section TypeSection) ToString (indent int) (output string) {
|
|||||||
"type ",
|
"type ",
|
||||||
section.permission.ToString(), " ",
|
section.permission.ToString(), " ",
|
||||||
section.name, ":",
|
section.name, ":",
|
||||||
section.what.ToString(indent + 1, true), "\n")
|
section.what.ToString(), "\n")
|
||||||
|
|
||||||
|
output += section.argument.ToString(indent + 1, true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (section EnumSection) ToString (indent int) (output string) {
|
func (section EnumSection) ToString (indent int) (output string) {
|
||||||
output += doIndent (
|
output += doIndent (
|
||||||
indent,
|
indent,
|
||||||
"enum ",
|
"enum ",
|
||||||
section.permission.ToString(), " ",
|
section.permission.ToString(), " ",
|
||||||
section.name, ":",
|
section.name, ":",
|
||||||
section.what.ToString(indent + 1, true), "\n")
|
section.what.ToString(), "\n")
|
||||||
|
|
||||||
for _, member := range section.members {
|
for _, member := range section.members {
|
||||||
output += doIndent(indent + 1, "- ", member.name)
|
output += doIndent(indent + 1, "- ", member.name, "")
|
||||||
|
output += member.argument.ToString(indent, false)
|
||||||
isComplexInitialization :=
|
|
||||||
member.value.kind == ArgumentKindObjectDefaultValues ||
|
|
||||||
member.value.kind == ArgumentKindArrayDefaultValues
|
|
||||||
|
|
||||||
if isComplexInitialization {
|
|
||||||
output += ":\n"
|
|
||||||
output += member.value.ToString(indent + 2, true)
|
|
||||||
} else if member.value.kind != ArgumentKindNil {
|
|
||||||
output += ":<" + member.value.ToString(0, false) + ">"
|
|
||||||
}
|
|
||||||
output += "\n"
|
output += "\n"
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -411,7 +256,83 @@ func (phrase Phrase) ToString (indent int, ownLine bool) (output string) {
|
|||||||
output += doIndent(indent)
|
output += doIndent(indent)
|
||||||
}
|
}
|
||||||
|
|
||||||
output += "[" + phrase.command.ToString(0, false)
|
output += "["
|
||||||
|
|
||||||
|
switch phrase.kind {
|
||||||
|
case
|
||||||
|
PhraseKindOperator,
|
||||||
|
PhraseKindLet,
|
||||||
|
PhraseKindAssign:
|
||||||
|
|
||||||
|
switch phrase.operator {
|
||||||
|
case lexer.TokenKindColon:
|
||||||
|
output += ":"
|
||||||
|
case lexer.TokenKindPlus:
|
||||||
|
output += "+"
|
||||||
|
case lexer.TokenKindMinus:
|
||||||
|
output += "-"
|
||||||
|
case lexer.TokenKindIncrement:
|
||||||
|
output += "++"
|
||||||
|
case lexer.TokenKindDecrement:
|
||||||
|
output += "--"
|
||||||
|
case lexer.TokenKindAsterisk:
|
||||||
|
output += "*"
|
||||||
|
case lexer.TokenKindSlash:
|
||||||
|
output += "/"
|
||||||
|
case lexer.TokenKindExclamation:
|
||||||
|
output += "!"
|
||||||
|
case lexer.TokenKindPercent:
|
||||||
|
output += "%"
|
||||||
|
case lexer.TokenKindPercentAssignment:
|
||||||
|
output += "%="
|
||||||
|
case lexer.TokenKindTilde:
|
||||||
|
output += "~"
|
||||||
|
case lexer.TokenKindTildeAssignment:
|
||||||
|
output += "~="
|
||||||
|
case lexer.TokenKindAssignment:
|
||||||
|
output += "="
|
||||||
|
case lexer.TokenKindEqualTo:
|
||||||
|
output += "=="
|
||||||
|
case lexer.TokenKindNotEqualTo:
|
||||||
|
output += "!="
|
||||||
|
case lexer.TokenKindLessThanEqualTo:
|
||||||
|
output += "<="
|
||||||
|
case lexer.TokenKindLessThan:
|
||||||
|
output += "<"
|
||||||
|
case lexer.TokenKindLShift:
|
||||||
|
output += "<<"
|
||||||
|
case lexer.TokenKindLShiftAssignment:
|
||||||
|
output += "<<="
|
||||||
|
case lexer.TokenKindGreaterThan:
|
||||||
|
output += ">"
|
||||||
|
case lexer.TokenKindGreaterThanEqualTo:
|
||||||
|
output += ">="
|
||||||
|
case lexer.TokenKindRShift:
|
||||||
|
output += ">>"
|
||||||
|
case lexer.TokenKindRShiftAssignment:
|
||||||
|
output += ">>="
|
||||||
|
case lexer.TokenKindBinaryOr:
|
||||||
|
output += "|"
|
||||||
|
case lexer.TokenKindBinaryOrAssignment:
|
||||||
|
output += "|="
|
||||||
|
case lexer.TokenKindLogicalOr:
|
||||||
|
output += "||"
|
||||||
|
case lexer.TokenKindBinaryAnd:
|
||||||
|
output += "&"
|
||||||
|
case lexer.TokenKindBinaryAndAssignment:
|
||||||
|
output += "&="
|
||||||
|
case lexer.TokenKindLogicalAnd:
|
||||||
|
output += "&&"
|
||||||
|
case lexer.TokenKindBinaryXor:
|
||||||
|
output += "^"
|
||||||
|
case lexer.TokenKindBinaryXorAssignment:
|
||||||
|
output += "^="
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
output += phrase.command.ToString(0, false)
|
||||||
|
}
|
||||||
|
|
||||||
for _, argument := range phrase.arguments {
|
for _, argument := range phrase.arguments {
|
||||||
output += " " + argument.ToString(0, false)
|
output += " " + argument.ToString(0, false)
|
||||||
}
|
}
|
||||||
|
@ -154,6 +154,7 @@ type DataSection struct {
|
|||||||
nameable
|
nameable
|
||||||
typeable
|
typeable
|
||||||
permissionable
|
permissionable
|
||||||
|
valuable
|
||||||
|
|
||||||
external bool
|
external bool
|
||||||
}
|
}
|
||||||
@ -164,6 +165,7 @@ type TypeSection struct {
|
|||||||
nameable
|
nameable
|
||||||
typeable
|
typeable
|
||||||
permissionable
|
permissionable
|
||||||
|
valuable
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnumMember represents a member of an enum section.
|
// EnumMember represents a member of an enum section.
|
||||||
|
Reference in New Issue
Block a user