mirror of
https://github.com/c0re100/gotdlib.git
synced 2026-02-21 20:20:17 +01:00
schema improvement
This commit is contained in:
parent
ccea55b18f
commit
c780ca35c4
7 changed files with 732 additions and 326 deletions
74
tlparser/code.go
Normal file
74
tlparser/code.go
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
package tlparser
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ParseCode(reader io.Reader, schema *Schema) error {
|
||||
var prevLine string
|
||||
var curLine string
|
||||
|
||||
userMethods := map[string]bool{}
|
||||
botMethods := map[string]bool{}
|
||||
|
||||
scanner := bufio.NewScanner(reader)
|
||||
for scanner.Scan() {
|
||||
prevLine = curLine
|
||||
curLine = scanner.Text()
|
||||
|
||||
if strings.Contains(curLine, "CHECK_IS_USER();") {
|
||||
fields := strings.Fields(prevLine)
|
||||
for _, field := range fields {
|
||||
var methodName string
|
||||
n, err := fmt.Sscanf(field, "td_api::%s", &methodName)
|
||||
if err == nil && n > 0 {
|
||||
userMethods[methodName] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Contains(curLine, "CHECK_IS_BOT();") {
|
||||
fields := strings.Fields(prevLine)
|
||||
for _, field := range fields {
|
||||
var methodName string
|
||||
n, err := fmt.Sscanf(field, "td_api::%s", &methodName)
|
||||
if err == nil && n > 0 {
|
||||
botMethods[methodName] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err := scanner.Err()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var ok bool
|
||||
|
||||
for index, _ := range schema.Functions {
|
||||
hasType := false
|
||||
_, ok = userMethods[schema.Functions[index].Name]
|
||||
if ok {
|
||||
schema.Functions[index].Type = FUNCTION_TYPE_USER
|
||||
hasType = true
|
||||
}
|
||||
|
||||
_, ok = botMethods[schema.Functions[index].Name]
|
||||
if ok {
|
||||
schema.Functions[index].Type = FUNCTION_TYPE_BOT
|
||||
hasType = true
|
||||
}
|
||||
|
||||
if !hasType {
|
||||
schema.Functions[index].Type = FUNCTION_TYPE_COMMON
|
||||
}
|
||||
|
||||
ok = false
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -42,10 +42,12 @@ func Parse(reader io.Reader) (*Schema, error) {
|
|||
class := strings.TrimRight(bodyFields[len(bodyFields)-1], ";")
|
||||
if hitFunctions {
|
||||
schema.Functions = append(schema.Functions, &Function{
|
||||
Name: name,
|
||||
Description: "",
|
||||
Class: class,
|
||||
Properties: []*Property{},
|
||||
Name: name,
|
||||
Description: "",
|
||||
Class: class,
|
||||
Properties: []*Property{},
|
||||
IsSynchronous: false,
|
||||
Type: FUNCTION_TYPE_UNKNOWN,
|
||||
})
|
||||
} else {
|
||||
if name == "vector" {
|
||||
|
|
@ -84,6 +86,7 @@ func parseFunction(firstLine string, scanner *bufio.Scanner) *Function {
|
|||
Class: class,
|
||||
Properties: properties,
|
||||
IsSynchronous: isSynchronous,
|
||||
Type: FUNCTION_TYPE_UNKNOWN,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,12 +18,22 @@ type Class struct {
|
|||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type FunctionType int
|
||||
|
||||
const (
|
||||
FUNCTION_TYPE_UNKNOWN FunctionType = iota
|
||||
FUNCTION_TYPE_COMMON
|
||||
FUNCTION_TYPE_USER
|
||||
FUNCTION_TYPE_BOT
|
||||
)
|
||||
|
||||
type Function struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Class string `json:"class"`
|
||||
Properties []*Property `json:"properties"`
|
||||
IsSynchronous bool `json:"is_synchronous"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Class string `json:"class"`
|
||||
Properties []*Property `json:"properties"`
|
||||
IsSynchronous bool `json:"is_synchronous"`
|
||||
Type FunctionType `json:"type"`
|
||||
}
|
||||
|
||||
type Property struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue