mirror of
https://github.com/fumiama/gozel.git
synced 2026-06-19 09:00:28 +08:00
feat(gen): add symbol table
This commit is contained in:
38
gen/symb.go
Normal file
38
gen/symb.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type symbolType uintptr
|
||||
|
||||
const (
|
||||
// symbolTypeConst fields
|
||||
//
|
||||
// 0: const eval
|
||||
symbolTypeConst symbolType = iota
|
||||
// symbolTypeFunc fields
|
||||
//
|
||||
// 0: _para1_name, _para2_name, ...
|
||||
// 1: replaceable eval
|
||||
symbolTypeFunc
|
||||
)
|
||||
|
||||
type symbol struct {
|
||||
stype symbolType
|
||||
name string
|
||||
fields []string
|
||||
}
|
||||
|
||||
func (s *symbol) replace(txt string, args ...string) (string, error) {
|
||||
switch s.stype {
|
||||
case symbolTypeConst:
|
||||
return strings.ReplaceAll(txt, s.name, s.fields[0]), nil
|
||||
case symbolTypeFunc:
|
||||
//TODO: finish
|
||||
return "", nil
|
||||
}
|
||||
return "", errors.New("unsupported symbol type " + strconv.Itoa(int(s.stype)))
|
||||
}
|
||||
Reference in New Issue
Block a user