From 8d5c0a6905e8ccd08d536cbc016ba471d6ee96d8 Mon Sep 17 00:00:00 2001 From: Marvin Blum Date: Sat, 31 Oct 2015 16:27:10 +0100 Subject: [PATCH] Added documentation, added new line before preprocessor line. --- README.md | 24 ++++++++++++++++++++++++ src/parser/parser.go | 4 ++-- src/parser/parser_test.go | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 57bf232..5471fd4 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,29 @@ var x = code("var y = 5;"); // pass as string x = {y = 5;}; ``` +## Preprocessor + +The preprocessor works like the original one, with some limitations. +Please visit the link at the bottom, to read about the preprocessor and how to use it. Generally, preprocessor lines must start with the hash key (#) and must stay in their own line. They are always printed as seperate lines. +These features are not supported: + +* replacing parts of words +* multi line preprocessor commands +* __EXEC (not used in SQF anyway) + +If you use *__EXEC*, it will be replaced by a function call to it ([] call __EXEC). +*__LINE__* and *__FILE__* can be used, since they are identifiers: + +``` +if __LINE__ == 22 { + // ... +} + +if __FILE__ == "myScript.sqf" { + // ... +} +``` + ## List of all keywords Keywords should not be used as identifiers. Here is a full list of all keywords in ASL. Remember that build in function names should not be used neither. @@ -248,6 +271,7 @@ For further information you can read the SQF tutorial and documentation of scrip * [Arma Wiki](https://community.bistudio.com/wiki/Main_Page) * [Scripting commands](https://community.bistudio.com/wiki/Category:Scripting_Commands_Arma_3) +* [Scripting preprocessor](https://community.bistudio.com/wiki/PreProcessor_Commands) ## License diff --git a/src/parser/parser.go b/src/parser/parser.go index d5eb3f9..6ccfdb8 100644 --- a/src/parser/parser.go +++ b/src/parser/parser.go @@ -57,8 +57,8 @@ func (c *Compiler) parseBlock() { } func (c *Compiler) parsePreprocessor() { - // we definitely want a new line here - c.appendOut(c.get().Token+new_line, false) + // we definitely want a new line before and after + c.appendOut(new_line+c.get().Token+new_line, false) c.next() } diff --git a/src/parser/parser_test.go b/src/parser/parser_test.go index 8926855..c6df8b2 100644 --- a/src/parser/parser_test.go +++ b/src/parser/parser_test.go @@ -156,7 +156,7 @@ func TestParserInlineCode(t *testing.T) { func TestParserPreprocessor(t *testing.T) { got := getCompiled(t, "test/tokenizer_preprocessor.asl") - want := "#define HELLO_WORLD \"Hello World!\"\r\nhint HELLO_WORLD;\r\n" + want := "\r\n#define HELLO_WORLD \"Hello World!\"\r\nhint HELLO_WORLD;\r\n" equal(t, got, want) }