mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 12:00:25 +00:00
Init, basic tokenizer setup.
This commit is contained in:
17
.project
Normal file
17
.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>asl</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.googlecode.goclipse.goBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.googlecode.goclipse.core.goNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
10
README.md
Normal file
10
README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# ASL
|
||||
|
||||
ASL stands for Arma Scripting Language, which is a language compiled to SQF.
|
||||
This scripting language tries to simplify Arma mod development and eliminate the pain of bad syntax using SQF.
|
||||
|
||||
## Syntax
|
||||
|
||||
```
|
||||
...
|
||||
```
|
||||
2
in/simple.asl
Normal file
2
in/simple.asl
Normal file
@@ -0,0 +1,2 @@
|
||||
var a = 1;
|
||||
var b = 2;
|
||||
BIN
pkg/linux_amd64/asl.a
Normal file
BIN
pkg/linux_amd64/asl.a
Normal file
Binary file not shown.
7
src/asl/parser.go
Normal file
7
src/asl/parser.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package asl
|
||||
|
||||
import (
|
||||
|
||||
)
|
||||
|
||||
|
||||
60
src/asl/tokenizer.go
Normal file
60
src/asl/tokenizer.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package asl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Token struct{
|
||||
token string
|
||||
}
|
||||
|
||||
var delimiter = []byte{'=', ';'}
|
||||
var keywords = []string{"var"}
|
||||
var whitespace = []byte{' ', '\n', '\t'}
|
||||
|
||||
func Tokenize(code []byte) []Token {
|
||||
tokens := make([]Token, 0)
|
||||
token := ""
|
||||
|
||||
for i := range code {
|
||||
c := code[i]
|
||||
|
||||
if byteArrayContains(delimiter, c) {
|
||||
tokens = append(tokens, Token{token})
|
||||
tokens = append(tokens, Token{string(c)})
|
||||
token = ""
|
||||
} else if stringArrayContains(keywords, token) {
|
||||
tokens = append(tokens, Token{token})
|
||||
token = ""
|
||||
} else if !byteArrayContains(whitespace, c) {
|
||||
token += string(c)
|
||||
}
|
||||
}
|
||||
|
||||
// TEST
|
||||
for i := range tokens {
|
||||
fmt.Println(tokens[i].token)
|
||||
}
|
||||
|
||||
return tokens
|
||||
}
|
||||
|
||||
func byteArrayContains(haystack []byte, needle byte) bool {
|
||||
for i := range haystack {
|
||||
if haystack[i] == needle {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func stringArrayContains(haystack []string, needle string) bool {
|
||||
for i := range haystack {
|
||||
if haystack[i] == needle {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
12
src/main/asl.go
Normal file
12
src/main/asl.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"asl"
|
||||
)
|
||||
|
||||
func main(){
|
||||
// read test file
|
||||
code, _ := ioutil.ReadFile("in/simple.asl")
|
||||
asl.Tokenize(code)
|
||||
}
|
||||
Reference in New Issue
Block a user