Skip to content

Commit

Permalink
Implemented ReadTypeMap
Browse files Browse the repository at this point in the history
  • Loading branch information
J. Bates committed Oct 22, 2011
1 parent 88ece00 commit 0149fb8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
13 changes: 6 additions & 7 deletions main.go
Expand Up @@ -39,12 +39,11 @@ func main() {
panic(err.String())
}

// TODO: read typemap...
//fmt.Printf("Parsing type map file ...\n")
//typeMap, err := ReadTypeMapFromFile(OpenGLTypeMapFile)
//if err != nil {
// panic(err.String())
//}
fmt.Printf("Parsing type map file ...\n")
typeMap, err := ReadTypeMapFromFile(OpenGLTypeMapFile)
if err != nil {
panic(err.String())
}

fmt.Printf("Parsing gl.spec file ...\n")
functions, err := ReadFunctionsFromFile(OpenGLSpecFile)
Expand All @@ -59,6 +58,6 @@ func main() {
Function{Name:"Foo3", Parameters:[]Parameter{Parameter{"p1", "int"}, Parameter{"p2", "int"}, Parameter{"p3", "float"}}, Return:"void"},
}

Generate(*outGLFile, enums, functions, nil, enumFilter, functionFilter)
Generate(*outGLFile, enums, functions, typeMap, enumFilter, functionFilter)
}

27 changes: 25 additions & 2 deletions tmreader.go
Expand Up @@ -3,6 +3,15 @@ package main
import (
"os"
"io"
"bufio"
"regexp"
"fmt"
)

var (
tmEmptyRE = regexp.MustCompile("^\n")
tmCommentRE = regexp.MustCompile("^#.*")
tmTypePairRE = regexp.MustCompile("^(.+),\\*,\\*,[\\t ]*(.+),\\*,\\*")
)

func ReadTypeMapFromFile(name string) (TypeMap, os.Error) {
Expand All @@ -15,7 +24,21 @@ func ReadTypeMapFromFile(name string) (TypeMap, os.Error) {
}

func ReadTypeMap(r io.Reader) (TypeMap, os.Error) {
// TODO: Implement type map reader
return nil, nil
tm := make(TypeMap)
br := bufio.NewReader(r)
for line, rerr := br.ReadString('\n'); rerr == nil; line, rerr = br.ReadString('\n') {
if tmEmptyRE.MatchString(line) {
continue
}
if tmCommentRE.FindStringSubmatch(line) != nil { // use matchstring?
continue
}
if typePair := tmTypePairRE.FindStringSubmatch(line); typePair != nil {
tm[typePair[1]] = typePair[2]
continue
}
fmt.Fprintf(os.Stderr, "Unable to parse line: " + line)
}
return tm, nil
}

0 comments on commit 0149fb8

Please sign in to comment.