mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 03:50:25 +00:00
Now splits by windows and unix new lines, added parsing structure.
This commit is contained in:
@@ -11,7 +11,8 @@ type Token struct {
|
||||
Column int
|
||||
}
|
||||
|
||||
var delimiter = []byte{
|
||||
var (
|
||||
delimiter = []byte{
|
||||
'=',
|
||||
';',
|
||||
'{',
|
||||
@@ -32,7 +33,7 @@ var delimiter = []byte{
|
||||
'*',
|
||||
'/'} // TODO: modulo?
|
||||
|
||||
var keywords = []string{
|
||||
keywords = []string{
|
||||
"var",
|
||||
"if",
|
||||
"while",
|
||||
@@ -51,10 +52,11 @@ var keywords = []string{
|
||||
"waituntil",
|
||||
"code"}
|
||||
|
||||
var whitespace = []byte{' ', '\n', '\t', '\r'}
|
||||
var identifier = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
||||
var preprocessor = byte('#')
|
||||
var new_line = []byte{'\r', '\n'}
|
||||
whitespace = []byte{' ', '\n', '\t', '\r'}
|
||||
identifier = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
||||
preprocessor = byte('#')
|
||||
new_line = []byte{'\r', '\n'}
|
||||
)
|
||||
|
||||
// Tokenizes the given byte array into syntax tokens,
|
||||
// which can be parsed later.
|
||||
|
||||
@@ -1,12 +1,45 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
// type for object types
|
||||
TYPE = 1
|
||||
|
||||
// types for functions
|
||||
NULL = 2
|
||||
UNARY = 3
|
||||
BINARY = 4
|
||||
|
||||
win_new_line = "\r\n"
|
||||
unix_new_line = "\n"
|
||||
)
|
||||
|
||||
type FunctionType struct {
|
||||
Name string
|
||||
Type int // one of the constants NULL, UNARY, BINARY
|
||||
ArgsCount int
|
||||
}
|
||||
|
||||
var functions []FunctionType
|
||||
|
||||
// Returns function type information by name.
|
||||
// If not found, the first parameter will be false.
|
||||
func GetFunction(name string) (bool, FunctionType) {
|
||||
for _, function := range functions {
|
||||
if function.Name == name {
|
||||
return true, function
|
||||
}
|
||||
}
|
||||
|
||||
return false, FunctionType{}
|
||||
}
|
||||
|
||||
// Loads type information from file.
|
||||
// The format is specified by 'supportInfo' command: https://community.bistudio.com/wiki/supportInfo
|
||||
func LoadTypes(path string) error {
|
||||
content, err := ioutil.ReadFile(path)
|
||||
|
||||
@@ -14,19 +47,55 @@ func LoadTypes(path string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := parseTypes(string(content)); err != nil {
|
||||
return err
|
||||
}
|
||||
data := strings.Replace(win_new_line, unix_new_line, string(content), -1) // make this work on windows and unix
|
||||
parseTypes(data)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseTypes(content string) error {
|
||||
lines := strings.Split(content, "\\n")
|
||||
func parseTypes(content string) {
|
||||
lines := strings.Split(content, unix_new_line)
|
||||
|
||||
for _, line := range lines {
|
||||
fmt.Println(line)
|
||||
if len(line) < 3 {
|
||||
continue
|
||||
}
|
||||
|
||||
return nil
|
||||
if line[0] == 'n' {
|
||||
parseNullFunction(line)
|
||||
} else if line[0] == 'u' {
|
||||
parseUnaryFunction(line)
|
||||
} else if line[0] == 'b' {
|
||||
parseBinaryFunction(line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func parseNullFunction(line string) {
|
||||
parts := getParts(line)
|
||||
|
||||
for _, part := range parts {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func parseUnaryFunction(line string) {
|
||||
parts := getParts(line)
|
||||
|
||||
for _, part := range parts {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func parseBinaryFunction(line string) {
|
||||
parts := getParts(line)
|
||||
|
||||
for _, part := range parts {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func getParts(line string) []string {
|
||||
line = line[2:]
|
||||
return strings.Split(line, " ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user