Added comments to preprocessor.

This commit is contained in:
Marvin Blum
2015-09-21 21:57:09 +02:00
parent 5a91193cae
commit 1c02007ac3
6 changed files with 93 additions and 29 deletions

BIN
bin/main

Binary file not shown.

View File

@@ -4,25 +4,25 @@ if isServer {
func ZeusGrpPlaced(_curators, _group) { func ZeusGrpPlaced(_curators, _group) {
each allCurators-_curators { each allCurators-_curators {
$addCuratorEditableObjects<_x>(_group, true); $addCuratorEditableObjects(_x)(_group, true);
} }
} }
func ZeusObjPlaced(_curators, _unit) { func ZeusObjPlaced(_curators, _unit) {
each allCurators-_curators { each allCurators-_curators {
$addCuratorEditableObjects<_x>([_unit], true); $addCuratorEditableObjects(_x)([_unit], true);
} }
} }
each allCurators { each allCurators {
$addCuratorEditableObjects<_x>(allUnits, true); $addCuratorEditableObjects(_x)(allUnits, true);
$addCuratorEditableObjects<_x>(allMissionObjects("All"), false); $addCuratorEditableObjects(_x)(allMissionObjects("All"), false);
_curator = _x; _curator = _x;
each allUnits { each allUnits {
if vehicle(_x) != _x { if vehicle(_x) != _x {
$addCuratorEditableObjects<_curator>([vehicle(_x)], true); $addCuratorEditableObjects(_curator)([vehicle(_x)], true);
} }
} }
} }

View File

@@ -1,28 +1,23 @@
if isServer { // comment
exitWith(); func Foo(_a, _b) {
} var _i = 0;
func ZeusGrpPlaced(_curators, _group) { // yeah...
each allCurators-_curators { while _a < _b {
$addCuratorEditableObjects(_x)(_group, true); /*
So this will just compile to plain SQF.
*/
sqf:
sleep 3;
hint format ["%1", _i];
sqf
_i = _i+1;
} }
} }
func ZeusObjPlaced(_curators, _unit) { /* comment */
each allCurators-_curators { var _a = 1;
$addCuratorEditableObjects(_x)([_unit], true); var _b = 2;
}
}
each allCurators { Foo(_a, _b);
$addCuratorEditableObjects(_x)(allUnits, true);
$addCuratorEditableObjects(_x)(allMissionObjects("All"), false);
_curator = _x;
each allUnits {
if vehicle(_x) != _x {
$addCuratorEditableObjects(_curator)([vehicle(_x)], true);
}
}
}

Binary file not shown.

View File

@@ -33,6 +33,8 @@ func parseBlock() {
parseFunction() parseFunction()
} else if accept("return") { } else if accept("return") {
parseReturn() parseReturn()
} else if accept("sqf") {
parseSqf()
} else { } else {
parseStatement() parseStatement()
} }
@@ -206,6 +208,19 @@ func parseReturn() {
appendOut(";\n") 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. // Everything that does not start with a keyword.
func parseStatement() { func parseStatement() {
// empty block // empty block

View File

@@ -2,6 +2,7 @@ package asl
import ( import (
"strings" "strings"
"fmt"
) )
type Token struct{ type Token struct{
@@ -36,14 +37,19 @@ var keywords = []string{
"false", "false",
"case", "case",
"default", "default",
"return"} "return",
"sqfstart",
"sqf"}
var whitespace = []byte{' ', '\n', '\t'} var whitespace = []byte{' ', '\n', '\t'}
func Tokenize(code []byte) []Token { func Tokenize(code []byte) []Token {
code = removeComments(code)
tokens := make([]Token, 0) tokens := make([]Token, 0)
token := "" token := ""
fmt.Println(string(code))
for i := range code { for i := range code {
c := code[i] c := code[i]
@@ -65,6 +71,54 @@ func Tokenize(code []byte) []Token {
return tokens 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 { func byteArrayContains(haystack []byte, needle byte) bool {
for i := range haystack { for i := range haystack {
if haystack[i] == needle { if haystack[i] == needle {