diff --git a/README.md b/README.md index f505fea..546a577 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,7 @@ Keywords should not be used as identifiers. Here is a full list of all keywords | catch | | exitwith | | waituntil | +| code | ## What's missing? diff --git a/in/simple.asl b/in/simple.asl index d717c60..c168559 100644 --- a/in/simple.asl +++ b/in/simple.asl @@ -1 +1 @@ -var inline_code = code("var x = 5;"); +var inline_code = code(""); diff --git a/src/asl/parser.go b/src/asl/parser.go index 6aab297..2766ae0 100644 --- a/src/asl/parser.go +++ b/src/asl/parser.go @@ -4,8 +4,6 @@ import ( ) -const TAB = " " - // Parses tokens, validates code to a specific degree // and writes SQF code into desired location. func Parse(token []Token, prettyPrinting bool) string { @@ -290,6 +288,23 @@ func parseWaitUntil() { appendOut("};", true) } +func parseInlineCode() string { + expect("code") + expect("(") + + code := get().token + next() + output := "{}" + + if len(code) > 2 { + output = "{"+Parse(Tokenize([]byte(code[1:len(code)-1])), pretty)+"}" + } + + expect(")") + + return output +} + // Everything that does not start with a keyword. func parseStatement() { // empty block @@ -426,7 +441,9 @@ func parseExpression(out bool) string { func parseIdentifier() string { output := "" - if seek("(") && !accept("!") && !accept("-") { + if accept("code") { + output += parseInlineCode() + } else if seek("(") && !accept("!") && !accept("-") { name := get().token next() output = "(" + parseFunctionCall(false, name) + ")"