mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 16:32:11 +01:00
Rename ParseFile, RenderFile to Parse, Render.
Also make various funcs' arg order consist wrt the IDMap and the input or inputs.
This commit is contained in:
1 parent
3a6ccbae67
commit
54567dbd47
6 files changed
+13
-13
No files matched your search
@@ -107,18 +107,18 @@ func do(r io.Reader, filename string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
idMap := token.IDMap{}
|
||||
tokens, comments, err := token.Tokenize(src, &idMap, filename)
|
||||
idMap := &token.IDMap{}
|
||||
tokens, comments, err := token.Tokenize(idMap, filename, src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// We don't need the AST node to pretty-print, but it's worth puffsfmt
|
||||
// rejecting syntax errors. This is just a parse, not a full type check.
|
||||
if _, err := parse.ParseFile(tokens, &idMap, filename); err != nil {
|
||||
if _, err := parse.Parse(idMap, filename, tokens); err != nil {
|
||||
return err
|
||||
}
|
||||
buf := &bytes.Buffer{}
|
||||
if err := render.RenderFile(buf, tokens, comments, &idMap); err != nil {
|
||||
if err := render.Render(buf, idMap, tokens, comments); err != nil {
|
||||
return err
|
||||
}
|
||||
dst := buf.Bytes()
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ var (
|
||||
)
|
||||
|
||||
// TypeString returns a string form of the type n.
|
||||
func TypeString(n *a.Node, m *t.IDMap) string {
|
||||
func TypeString(m *t.IDMap, n *a.Node) string {
|
||||
if n == nil {
|
||||
return "!nil!"
|
||||
}
|
||||
@@ -38,7 +38,7 @@ func TypeString(n *a.Node, m *t.IDMap) string {
|
||||
case 0:
|
||||
return m.ByID(n.ID1)
|
||||
case t.IDPtr:
|
||||
return "ptr " + TypeString(n.RHS, m)
|
||||
return "ptr " + TypeString(m, n.RHS)
|
||||
case t.IDOpenBracket:
|
||||
// TODO.
|
||||
default:
|
||||
|
||||
@@ -24,14 +24,14 @@ func TestCheck(t *testing.T) {
|
||||
|
||||
idMap := &token.IDMap{}
|
||||
|
||||
tokens, _, err := token.Tokenize([]byte(src), idMap, filename)
|
||||
tokens, _, err := token.Tokenize(idMap, filename, []byte(src))
|
||||
if err != nil {
|
||||
t.Fatalf("Tokenize: %v", err)
|
||||
}
|
||||
|
||||
node, err := parse.ParseFile(tokens, idMap, filename)
|
||||
node, err := parse.Parse(idMap, filename, tokens)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseFile: %v", err)
|
||||
t.Fatalf("Parse: %v", err)
|
||||
}
|
||||
|
||||
c, err := Check(idMap, node)
|
||||
@@ -57,7 +57,7 @@ func TestCheck(t *testing.T) {
|
||||
for id, typ := range bar.LocalVars {
|
||||
got = append(got, [2]string{
|
||||
idMap.ByID(id),
|
||||
TypeString(typ, idMap),
|
||||
TypeString(idMap, typ),
|
||||
})
|
||||
}
|
||||
sort.Slice(got, func(i, j int) bool {
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import (
|
||||
t "github.com/google/puffs/lang/token"
|
||||
)
|
||||
|
||||
func ParseFile(src []t.Token, m *t.IDMap, filename string) (*a.Node, error) {
|
||||
func Parse(m *t.IDMap, filename string, src []t.Token) (*a.Node, error) {
|
||||
p := &parser{
|
||||
src: src,
|
||||
m: m,
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
|
||||
var newLine = []byte{'\n'}
|
||||
|
||||
func RenderFile(w io.Writer, src []token.Token, comments []string, m *token.IDMap) (err error) {
|
||||
func Render(w io.Writer, m *token.IDMap, src []token.Token, comments []string) (err error) {
|
||||
if len(src) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ func hasPrefix(a []byte, s string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func Tokenize(src []byte, m *IDMap, filename string) (tokens []Token, comments []string, retErr error) {
|
||||
func Tokenize(m *IDMap, filename string, src []byte) (tokens []Token, comments []string, retErr error) {
|
||||
line := uint32(1)
|
||||
loop:
|
||||
for i := 0; i < len(src); {
|
||||
|
||||
Reference in new issue
Block a user