mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 12:00:25 +00:00
Now splits by windows and unix new lines, added parsing structure.
This commit is contained in:
@@ -11,50 +11,52 @@ type Token struct {
|
|||||||
Column int
|
Column int
|
||||||
}
|
}
|
||||||
|
|
||||||
var delimiter = []byte{
|
var (
|
||||||
'=',
|
delimiter = []byte{
|
||||||
';',
|
'=',
|
||||||
'{',
|
';',
|
||||||
'}',
|
'{',
|
||||||
'(',
|
'}',
|
||||||
')',
|
'(',
|
||||||
'[',
|
')',
|
||||||
']',
|
'[',
|
||||||
'<',
|
']',
|
||||||
'>',
|
'<',
|
||||||
'!',
|
'>',
|
||||||
',',
|
'!',
|
||||||
':',
|
',',
|
||||||
'&',
|
':',
|
||||||
'|',
|
'&',
|
||||||
'+',
|
'|',
|
||||||
'-',
|
'+',
|
||||||
'*',
|
'-',
|
||||||
'/'} // TODO: modulo?
|
'*',
|
||||||
|
'/'} // TODO: modulo?
|
||||||
|
|
||||||
var keywords = []string{
|
keywords = []string{
|
||||||
"var",
|
"var",
|
||||||
"if",
|
"if",
|
||||||
"while",
|
"while",
|
||||||
"switch",
|
"switch",
|
||||||
"for",
|
"for",
|
||||||
"foreach",
|
"foreach",
|
||||||
"func",
|
"func",
|
||||||
"true",
|
"true",
|
||||||
"false",
|
"false",
|
||||||
"case",
|
"case",
|
||||||
"default",
|
"default",
|
||||||
"return",
|
"return",
|
||||||
"try",
|
"try",
|
||||||
"catch",
|
"catch",
|
||||||
"exitwith",
|
"exitwith",
|
||||||
"waituntil",
|
"waituntil",
|
||||||
"code"}
|
"code"}
|
||||||
|
|
||||||
var whitespace = []byte{' ', '\n', '\t', '\r'}
|
whitespace = []byte{' ', '\n', '\t', '\r'}
|
||||||
var identifier = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
identifier = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
||||||
var preprocessor = byte('#')
|
preprocessor = byte('#')
|
||||||
var new_line = []byte{'\r', '\n'}
|
new_line = []byte{'\r', '\n'}
|
||||||
|
)
|
||||||
|
|
||||||
// Tokenizes the given byte array into syntax tokens,
|
// Tokenizes the given byte array into syntax tokens,
|
||||||
// which can be parsed later.
|
// which can be parsed later.
|
||||||
|
|||||||
@@ -1,12 +1,45 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"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.
|
// Loads type information from file.
|
||||||
|
// The format is specified by 'supportInfo' command: https://community.bistudio.com/wiki/supportInfo
|
||||||
func LoadTypes(path string) error {
|
func LoadTypes(path string) error {
|
||||||
content, err := ioutil.ReadFile(path)
|
content, err := ioutil.ReadFile(path)
|
||||||
|
|
||||||
@@ -14,19 +47,55 @@ func LoadTypes(path string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := parseTypes(string(content)); err != nil {
|
data := strings.Replace(win_new_line, unix_new_line, string(content), -1) // make this work on windows and unix
|
||||||
return err
|
parseTypes(data)
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTypes(content string) error {
|
func parseTypes(content string) {
|
||||||
lines := strings.Split(content, "\\n")
|
lines := strings.Split(content, unix_new_line)
|
||||||
|
|
||||||
for _, line := range lines {
|
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