From 4318df34730435a1998af07893bbe5dc94bd7eaa Mon Sep 17 00:00:00 2001 From: vadim Date: Fri, 1 Dec 2017 15:29:23 +0200 Subject: [PATCH] exclude gocode from parser.y --- main.go | 26 ++ node.go | 44 +++ parser.go | 1028 +++++++++++++++++++++++++---------------------------- parser.y | 63 +--- 4 files changed, 555 insertions(+), 606 deletions(-) create mode 100644 main.go create mode 100644 node.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..9e96ba6 --- /dev/null +++ b/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "bytes" + "os" +) + +const src = ` + 0 { + fmt.Fprintf(out, "\n%v%v %s", indent, n.name, n.attributes) + } else { + fmt.Fprintf(out, "\n%v%v", indent, n.name) + } + for _, nn := range n.children { + nn.print(out, indent+" ") + } +} + +func Node(name string) node { + return node{name: name, attributes: make(map[string]string)} +} + +func (n node) append(nn ...node) node { + n.children = append(n.children, nn...) + return n +} + +func (n node) attribute(key string, value string) node { + n.attributes[key] = value + return n +} diff --git a/parser.go b/parser.go index 553f247..9880e52 100644 --- a/parser.go +++ b/parser.go @@ -5,50 +5,10 @@ import __yyfmt__ "fmt" //line parser.y:2 import ( - "bytes" "fmt" - "io" - "os" ) -type node struct { - name string - children []node - attributes map[string]string -} - -func (n node) String() string { - buf := new(bytes.Buffer) - n.print(buf, " ") - return buf.String() -} - -func (n node) print(out io.Writer, indent string) { - if len(n.attributes) > 0 { - fmt.Fprintf(out, "\n%v%v %s", indent, n.name, n.attributes) - } else { - fmt.Fprintf(out, "\n%v%v", indent, n.name) - } - for _, nn := range n.children { - nn.print(out, indent+" ") - } -} - -func Node(name string) node { - return node{name: name, attributes: make(map[string]string)} -} - -func (n node) append(nn ...node) node { - n.children = append(n.children, nn...) - return n -} - -func (n node) attribute(key string, value string) node { - n.attributes[key] = value - return n -} - -//line parser.y:50 +//line parser.y:10 type yySymType struct { yys int node node @@ -368,27 +328,7 @@ const yyEofCode = 1 const yyErrCode = 2 const yyInitialStackSize = 16 -//line parser.y:1203 -const src = ` - 0) { - fmt.Fprintf(out, "\n%v%v %s", indent, n.name, n.attributes) - } else { - fmt.Fprintf(out, "\n%v%v", indent, n.name) - } - for _, nn := range n.children { - nn.print(out, indent + " ") - } -} - -func Node(name string) node { - return node{name: name, attributes: make(map[string]string)} -} - -func (n node) append(nn...node) node { - n.children = append(n.children, nn...) - return n -} - -func (n node) attribute(key string, value string) node { - n.attributes[key] = value - return n -} - %} %union{ @@ -1200,25 +1160,4 @@ isset_variable: ///////////////////////////////////////////////////////////////////////// -%% - -const src = ` -