Reworked data section so it stores single initialization argument
This commit is contained in:
parent
bd42c95de0
commit
0dd9368393
@ -36,9 +36,8 @@ func (parser *ParsingOperation) parseDataSection () (
|
|||||||
section.value, err = parser.parseInitializationValues(0)
|
section.value, err = parser.parseInitializationValues(0)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
} else {
|
} else {
|
||||||
var argument Argument
|
section.value, err = parser.parseArgument()
|
||||||
argument, err = parser.parseArgument()
|
if err != nil { return }
|
||||||
section.value = append(section.value, argument)
|
|
||||||
|
|
||||||
err = parser.expect(lexer.TokenKindNewline)
|
err = parser.expect(lexer.TokenKindNewline)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
@ -55,7 +54,7 @@ func (parser *ParsingOperation) parseDataSection () (
|
|||||||
func (parser *ParsingOperation) parseInitializationValues (
|
func (parser *ParsingOperation) parseInitializationValues (
|
||||||
baseIndent int,
|
baseIndent int,
|
||||||
) (
|
) (
|
||||||
values []Argument,
|
value Argument,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
// check if line is indented one more than baseIndent
|
// check if line is indented one more than baseIndent
|
||||||
@ -65,23 +64,20 @@ func (parser *ParsingOperation) parseInitializationValues (
|
|||||||
err = parser.nextToken()
|
err = parser.nextToken()
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
// TODO: make data sections have only one value argument and create a
|
value.location = parser.token.Location()
|
||||||
// similar data structure to ObjectAttributes for arrays
|
|
||||||
if parser.token.Is(lexer.TokenKindDot) {
|
|
||||||
var attributes ObjectAttributes
|
|
||||||
attributes, err = parser.parseObjectInitializationValues (
|
|
||||||
baseIndent + 1)
|
|
||||||
|
|
||||||
values = []Argument {
|
if parser.token.Is(lexer.TokenKindDot) {
|
||||||
Argument {
|
var values ObjectInitializationValues
|
||||||
location: attributes.location,
|
values, err = parser.parseObjectInitializationValues (
|
||||||
value: &attributes,
|
|
||||||
kind: ArgumentKindObjectAttributes,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
values, err = parser.parseArrayInitializationValues (
|
|
||||||
baseIndent + 1)
|
baseIndent + 1)
|
||||||
|
value.kind = ArgumentKindObjectInitializationValues
|
||||||
|
value.value = &values
|
||||||
|
} else {
|
||||||
|
var values ArrayInitializationValues
|
||||||
|
value.value, err = parser.parseArrayInitializationValues (
|
||||||
|
baseIndent + 1)
|
||||||
|
value.kind = ArgumentKindArrayInitializationValues
|
||||||
|
value.value = &values
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -92,7 +88,7 @@ func (parser *ParsingOperation) parseInitializationValues (
|
|||||||
func (parser *ParsingOperation) parseObjectInitializationValues (
|
func (parser *ParsingOperation) parseObjectInitializationValues (
|
||||||
indent int,
|
indent int,
|
||||||
) (
|
) (
|
||||||
values ObjectAttributes,
|
values ObjectInitializationValues,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
values.attributes = make(map[string] Argument)
|
values.attributes = make(map[string] Argument)
|
||||||
@ -142,9 +138,11 @@ func (parser *ParsingOperation) parseObjectInitializationValues (
|
|||||||
func (parser *ParsingOperation) parseArrayInitializationValues (
|
func (parser *ParsingOperation) parseArrayInitializationValues (
|
||||||
indent int,
|
indent int,
|
||||||
) (
|
) (
|
||||||
values []Argument,
|
values ArrayInitializationValues,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
|
values.location = parser.token.Location()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if parser.token.Is(lexer.TokenKindNewline) {
|
if parser.token.Is(lexer.TokenKindNewline) {
|
||||||
err = parser.nextToken()
|
err = parser.nextToken()
|
||||||
@ -159,7 +157,7 @@ func (parser *ParsingOperation) parseArrayInitializationValues (
|
|||||||
var argument Argument
|
var argument Argument
|
||||||
argument, err = parser.parseArgument()
|
argument, err = parser.parseArgument()
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
values = append(values, argument)
|
values.values = append(values.values, argument)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -78,14 +78,14 @@ func (declaration *Declaration) ToString () (output string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (attributes *ObjectAttributes) ToString (
|
func (attributes *ObjectInitializationValues) ToString (
|
||||||
indent int,
|
indent int,
|
||||||
) (
|
) (
|
||||||
output string,
|
output string,
|
||||||
) {
|
) {
|
||||||
for name, value := range attributes.attributes {
|
for name, value := range attributes.attributes {
|
||||||
output += doIndent(indent, ".", name, " ")
|
output += doIndent(indent, ".", name, " ")
|
||||||
if value.kind == ArgumentKindObjectAttributes {
|
if value.kind == ArgumentKindObjectInitializationValues {
|
||||||
output += "\n"
|
output += "\n"
|
||||||
output += value.ToString(indent + 1, true)
|
output += value.ToString(indent + 1, true)
|
||||||
} else {
|
} else {
|
||||||
@ -96,6 +96,18 @@ func (attributes *ObjectAttributes) ToString (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (values *ArrayInitializationValues) ToString (
|
||||||
|
indent int,
|
||||||
|
) (
|
||||||
|
output string,
|
||||||
|
) {
|
||||||
|
for _, value := range values.values {
|
||||||
|
output += value.ToString(indent, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (phrase *Phrase) ToString (indent int, breakLine bool) (output string) {
|
func (phrase *Phrase) ToString (indent int, breakLine bool) (output string) {
|
||||||
if breakLine {
|
if breakLine {
|
||||||
output += doIndent (
|
output += doIndent (
|
||||||
@ -139,17 +151,19 @@ func (argument *Argument) ToString (indent int, breakLine bool) (output string)
|
|||||||
|
|
||||||
switch argument.kind {
|
switch argument.kind {
|
||||||
case ArgumentKindPhrase:
|
case ArgumentKindPhrase:
|
||||||
output += doIndent (
|
output += argument.value.(*Phrase).ToString (
|
||||||
indent,
|
indent,
|
||||||
argument.value.(*Phrase).ToString (
|
breakLine)
|
||||||
indent,
|
|
||||||
breakLine))
|
|
||||||
|
|
||||||
case ArgumentKindObjectAttributes:
|
case ArgumentKindObjectInitializationValues:
|
||||||
// this should only appear in contexts where breakLine is true
|
// this should only appear in contexts where breakLine is true
|
||||||
output += doIndent (
|
output += argument.value.(*ObjectInitializationValues).
|
||||||
indent,
|
ToString (indent)
|
||||||
argument.value.(*ObjectAttributes).ToString (indent))
|
|
||||||
|
case ArgumentKindArrayInitializationValues:
|
||||||
|
// this should only appear in contexts where breakLine is true
|
||||||
|
output += argument.value.(*ArrayInitializationValues).
|
||||||
|
ToString (indent)
|
||||||
|
|
||||||
case ArgumentKindIdentifier:
|
case ArgumentKindIdentifier:
|
||||||
output += doIndent (
|
output += doIndent (
|
||||||
@ -193,16 +207,18 @@ func (section *DataSection) ToString (indent int) (output string) {
|
|||||||
section.name, ":",
|
section.name, ":",
|
||||||
section.what.ToString())
|
section.what.ToString())
|
||||||
|
|
||||||
if len(section.value) == 0 {
|
isComplexInitialization :=
|
||||||
|
section.value.kind == ArgumentKindObjectInitializationValues ||
|
||||||
|
section.value.kind == ArgumentKindArrayInitializationValues
|
||||||
|
|
||||||
|
if section.value.value == nil {
|
||||||
output += "\n"
|
output += "\n"
|
||||||
} else if len(section.value) == 1 {
|
} else if isComplexInitialization {
|
||||||
output += " " + section.value[0].ToString(0, false)
|
|
||||||
output += "\n"
|
output += "\n"
|
||||||
|
output += section.value.ToString(indent + 1, true)
|
||||||
} else {
|
} else {
|
||||||
|
output += " " + section.value.ToString(0, false)
|
||||||
output += "\n"
|
output += "\n"
|
||||||
for _, argument := range(section.value) {
|
|
||||||
output += argument.ToString(indent + 1, true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -60,13 +60,20 @@ type Declaration struct {
|
|||||||
what Type
|
what Type
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectAttributes represents a list of object member initialization
|
// ObjectInitializationValues represents a list of object member initialization
|
||||||
// attributes.
|
// attributes.
|
||||||
type ObjectAttributes struct {
|
type ObjectInitializationValues struct {
|
||||||
location file.Location
|
location file.Location
|
||||||
attributes map[string] Argument
|
attributes map[string] Argument
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ArrayInitializationValues represents a list of attributes initializing an
|
||||||
|
// array.
|
||||||
|
type ArrayInitializationValues struct {
|
||||||
|
location file.Location
|
||||||
|
values []Argument
|
||||||
|
}
|
||||||
|
|
||||||
// Phrase represents a function call or operator. In ARF they are the same
|
// Phrase represents a function call or operator. In ARF they are the same
|
||||||
// syntactical concept.
|
// syntactical concept.
|
||||||
type Phrase struct {
|
type Phrase struct {
|
||||||
@ -94,7 +101,10 @@ const (
|
|||||||
|
|
||||||
// .name value
|
// .name value
|
||||||
// but like, a lot of them
|
// but like, a lot of them
|
||||||
ArgumentKindObjectAttributes
|
ArgumentKindObjectInitializationValues
|
||||||
|
|
||||||
|
// value value...
|
||||||
|
ArgumentKindArrayInitializationValues
|
||||||
|
|
||||||
// name.name
|
// name.name
|
||||||
// name.name.name
|
// name.name.name
|
||||||
@ -144,6 +154,6 @@ type DataSection struct {
|
|||||||
name string
|
name string
|
||||||
|
|
||||||
what Type
|
what Type
|
||||||
value []Argument
|
value Argument
|
||||||
permission types.Permission
|
permission types.Permission
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user