exclude gocode from parser.y

This commit is contained in:
vadim 2017-12-01 15:29:23 +02:00
parent f973ed31f5
commit 4318df3473
4 changed files with 555 additions and 606 deletions

26
main.go Normal file
View File

@ -0,0 +1,26 @@
package main
import (
"bytes"
"os"
)
const src = `
<?php
namespace Test;
/**
* Class foo
*/
class foo
{
}
`
func main() {
yyDebug = 0
yyErrorVerbose = true
l := newLexer(bytes.NewBufferString(src), os.Stdout, "file.name")
yyParse(l)
}

44
node.go Normal file
View File

@ -0,0 +1,44 @@
package main
import (
"bytes"
"fmt"
"io"
)
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
}

1028
parser.go

File diff suppressed because it is too large Load Diff

View File

@ -2,49 +2,9 @@
package main package main
import ( import (
"bytes"
"fmt" "fmt"
"os"
"io"
) )
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
}
%} %}
%union{ %union{
@ -1201,24 +1161,3 @@ isset_variable:
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
%% %%
const src = `
<?php
namespace Test;
/**
* Class foo
*/
class foo
{
}
`
func main() {
yyDebug = 0
yyErrorVerbose = true
l := newLexer(bytes.NewBufferString(src), os.Stdout, "file.name")
yyParse(l)
}