update parse format

master
Jordan Orelli 10 years ago
parent 88c013b2bc
commit 2dc6b618f0

@ -85,13 +85,12 @@ func (n *rootNode) String() string {
}
func (n *rootNode) pretty(w io.Writer, prefix string) error {
fmt.Fprintf(w, "%sroot{\n", prefix)
fmt.Fprintf(w, "%sroot:\n", prefix)
for _, child := range n.children {
if err := child.pretty(w, prefix+indent); err != nil {
return err
}
}
fmt.Fprintf(w, "%s}\n", prefix)
return nil
}
@ -121,8 +120,8 @@ func (n *commentNode) String() string {
}
func (n *commentNode) pretty(w io.Writer, prefix string) error {
fmt.Fprintf(w, "%scomment:\n", prefix)
r := bufio.NewReader(strings.NewReader(n.body))
fmt.Fprintf(w, "%scomment{\n", prefix)
for {
line, err := r.ReadString('\n')
if err == io.EOF {
@ -136,7 +135,6 @@ func (n *commentNode) pretty(w io.Writer, prefix string) error {
}
fmt.Fprintf(w, "%s%s%s\n", prefix, indent, line)
}
fmt.Fprintf(w, "%s}\n", prefix)
return nil
}
@ -178,12 +176,13 @@ func (n *assignmentNode) String() string {
}
func (n *assignmentNode) pretty(w io.Writer, prefix string) error {
fmt.Fprintf(w, "%sassign{\n", prefix)
fmt.Fprintf(w, "%s%sname: %s\n", prefix, indent, n.name)
if err := n.value.pretty(w, fmt.Sprintf("%s%svalue: ", prefix, indent)); err != nil {
fmt.Fprintf(w, "%sassign:\n", prefix)
fmt.Fprintf(w, "%s%sname:\n", prefix, indent)
fmt.Fprintf(w, "%s%s%s%s\n", prefix, indent, indent, n.name)
fmt.Fprintf(w, "%s%svalue:\n", prefix, indent)
if err := n.value.pretty(w, prefix+indent+indent); err != nil {
return err
}
fmt.Fprintf(w, "%s}\n", prefix)
return nil
}
@ -211,7 +210,8 @@ func (s *stringNode) parse(p *parser) error {
}
func (s *stringNode) pretty(w io.Writer, prefix string) error {
_, err := fmt.Fprintf(w, "%s%s\n", prefix, string(*s))
fmt.Fprintf(w, "%sstring:\n", prefix)
_, err := fmt.Fprintf(w, "%s%s%s\n", prefix, indent, string(*s))
return err
}
@ -275,7 +275,7 @@ func (n *numberNode) pretty(w io.Writer, prefix string) error {
if err != nil {
return err
}
fmt.Fprintf(w, "%s%v\n", prefix, v)
fmt.Fprintf(w, "%snumber:\n%s%s%v\n", prefix, prefix, indent, v)
return nil
}
@ -320,13 +320,12 @@ func (l *listNode) parse(p *parser) error {
}
func (l *listNode) pretty(w io.Writer, prefix string) error {
fmt.Fprintf(w, "%slist{\n", prefix)
fmt.Fprintf(w, "%slist:\n", prefix)
for _, n := range *l {
if err := n.pretty(w, prefix+indent); err != nil {
return err
}
}
fmt.Fprintf(w, "%s}\n", prefix)
return nil
}

@ -1,2 +1 @@
root{
}
root:

@ -1,50 +1,73 @@
root{
assign{
name: a_string
value: a string value
}
assign{
name: an_int
value: 1
}
assign{
name: another_int
value: 9
}
assign{
name: moar_int
value: -12
}
assign{
name: a_float
value: 1
}
assign{
name: another_float
value: -0.9
}
assign{
name: extra_floaty
value: 1.2
}
assign{
name: complex1
value: (1+1i)
}
assign{
name: complex2
value: (1+0i)
}
assign{
name: complex3
value: (1.3+4.7i)
}
assign{
name: complex4
value: (-4.2+8.9i)
}
assign{
name: complex5
value: (4.2-8.9i)
}
}
root:
assign:
name:
a_string
value:
string:
a string value
assign:
name:
an_int
value:
number:
1
assign:
name:
another_int
value:
number:
9
assign:
name:
moar_int
value:
number:
-12
assign:
name:
a_float
value:
number:
1
assign:
name:
another_float
value:
number:
-0.9
assign:
name:
extra_floaty
value:
number:
1.2
assign:
name:
complex1
value:
number:
(1+1i)
assign:
name:
complex2
value:
number:
(1+0i)
assign:
name:
complex3
value:
number:
(1.3+4.7i)
assign:
name:
complex4
value:
number:
(-4.2+8.9i)
assign:
name:
complex5
value:
number:
(4.2-8.9i)

@ -1,10 +1,12 @@
root{
assign{
name: items
value: list{
value: 1
value: 2
value: 3
value: }
}
}
root:
assign:
name:
items
value:
list:
number:
1
number:
2
number:
3

Loading…
Cancel
Save