mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 12:00:25 +00:00
Added comments to preprocessor.
This commit is contained in:
@@ -4,25 +4,25 @@ if isServer {
|
||||
|
||||
func ZeusGrpPlaced(_curators, _group) {
|
||||
each allCurators-_curators {
|
||||
$addCuratorEditableObjects<_x>(_group, true);
|
||||
$addCuratorEditableObjects(_x)(_group, true);
|
||||
}
|
||||
}
|
||||
|
||||
func ZeusObjPlaced(_curators, _unit) {
|
||||
each allCurators-_curators {
|
||||
$addCuratorEditableObjects<_x>([_unit], true);
|
||||
$addCuratorEditableObjects(_x)([_unit], true);
|
||||
}
|
||||
}
|
||||
|
||||
each allCurators {
|
||||
$addCuratorEditableObjects<_x>(allUnits, true);
|
||||
$addCuratorEditableObjects<_x>(allMissionObjects("All"), false);
|
||||
$addCuratorEditableObjects(_x)(allUnits, true);
|
||||
$addCuratorEditableObjects(_x)(allMissionObjects("All"), false);
|
||||
|
||||
_curator = _x;
|
||||
|
||||
each allUnits {
|
||||
if vehicle(_x) != _x {
|
||||
$addCuratorEditableObjects<_curator>([vehicle(_x)], true);
|
||||
$addCuratorEditableObjects(_curator)([vehicle(_x)], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,23 @@
|
||||
if isServer {
|
||||
exitWith();
|
||||
}
|
||||
// comment
|
||||
func Foo(_a, _b) {
|
||||
var _i = 0;
|
||||
|
||||
func ZeusGrpPlaced(_curators, _group) {
|
||||
each allCurators-_curators {
|
||||
$addCuratorEditableObjects(_x)(_group, true);
|
||||
// yeah...
|
||||
while _a < _b {
|
||||
/*
|
||||
So this will just compile to plain SQF.
|
||||
*/
|
||||
sqf:
|
||||
sleep 3;
|
||||
hint format ["%1", _i];
|
||||
sqf
|
||||
|
||||
_i = _i+1;
|
||||
}
|
||||
}
|
||||
|
||||
func ZeusObjPlaced(_curators, _unit) {
|
||||
each allCurators-_curators {
|
||||
$addCuratorEditableObjects(_x)([_unit], true);
|
||||
}
|
||||
}
|
||||
/* comment */
|
||||
var _a = 1;
|
||||
var _b = 2;
|
||||
|
||||
each allCurators {
|
||||
$addCuratorEditableObjects(_x)(allUnits, true);
|
||||
$addCuratorEditableObjects(_x)(allMissionObjects("All"), false);
|
||||
|
||||
_curator = _x;
|
||||
|
||||
each allUnits {
|
||||
if vehicle(_x) != _x {
|
||||
$addCuratorEditableObjects(_curator)([vehicle(_x)], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Foo(_a, _b);
|
||||
|
||||
Binary file not shown.
@@ -33,6 +33,8 @@ func parseBlock() {
|
||||
parseFunction()
|
||||
} else if accept("return") {
|
||||
parseReturn()
|
||||
} else if accept("sqf") {
|
||||
parseSqf()
|
||||
} else {
|
||||
parseStatement()
|
||||
}
|
||||
@@ -206,6 +208,19 @@ func parseReturn() {
|
||||
appendOut(";\n")
|
||||
}
|
||||
|
||||
func parseSqf() {
|
||||
expect("sqf")
|
||||
expect(":")
|
||||
|
||||
for !accept("sqf") {
|
||||
appendOut(get().token)
|
||||
next()
|
||||
}
|
||||
|
||||
appendOut("\n")
|
||||
expect("sqf")
|
||||
}
|
||||
|
||||
// Everything that does not start with a keyword.
|
||||
func parseStatement() {
|
||||
// empty block
|
||||
|
||||
@@ -2,6 +2,7 @@ package asl
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Token struct{
|
||||
@@ -36,14 +37,19 @@ var keywords = []string{
|
||||
"false",
|
||||
"case",
|
||||
"default",
|
||||
"return"}
|
||||
"return",
|
||||
"sqfstart",
|
||||
"sqf"}
|
||||
|
||||
var whitespace = []byte{' ', '\n', '\t'}
|
||||
|
||||
func Tokenize(code []byte) []Token {
|
||||
code = removeComments(code)
|
||||
tokens := make([]Token, 0)
|
||||
token := ""
|
||||
|
||||
fmt.Println(string(code))
|
||||
|
||||
for i := range code {
|
||||
c := code[i]
|
||||
|
||||
@@ -65,6 +71,54 @@ func Tokenize(code []byte) []Token {
|
||||
return tokens
|
||||
}
|
||||
|
||||
func removeComments(code []byte) []byte {
|
||||
newcode := make([]byte, len(code))
|
||||
j := 0
|
||||
|
||||
for i := 0; i < len(code); i++ {
|
||||
c := code[i]
|
||||
|
||||
if c == '/' && nextChar(code, i) == '/' {
|
||||
i = skipSingleLineComment(code, i+1)
|
||||
continue
|
||||
} else if c == '/' && nextChar(code, i) == '*' {
|
||||
i = skipMultiLineComment(code, i+1)
|
||||
continue
|
||||
}
|
||||
|
||||
newcode[j] = c
|
||||
j++
|
||||
}
|
||||
|
||||
return newcode[:j]
|
||||
}
|
||||
|
||||
func nextChar(code []byte, i int) byte {
|
||||
i++
|
||||
|
||||
if i < len(code) {
|
||||
return code[i]
|
||||
}
|
||||
|
||||
return '0'
|
||||
}
|
||||
|
||||
func skipSingleLineComment(code []byte, i int) int {
|
||||
for i < len(code) && code[i] != '\n' {
|
||||
i++
|
||||
}
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
func skipMultiLineComment(code []byte, i int) int {
|
||||
for i < len(code) && !(code[i] == '*' && nextChar(code, i) == '/') {
|
||||
i++
|
||||
}
|
||||
|
||||
return i+1
|
||||
}
|
||||
|
||||
func byteArrayContains(haystack []byte, needle byte) bool {
|
||||
for i := range haystack {
|
||||
if haystack[i] == needle {
|
||||
|
||||
Reference in New Issue
Block a user