mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 12:00:25 +00:00
Added preprocessor line.
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"tokenizer"
|
||||
)
|
||||
|
||||
const new_line = "\r\n"
|
||||
|
||||
// Parses tokens, validates code to a specific degree
|
||||
// and writes SQF code into desired location.
|
||||
func (c *Compiler) Parse(token []tokenizer.Token, prettyPrinting bool) string {
|
||||
@@ -19,7 +21,9 @@ func (c *Compiler) Parse(token []tokenizer.Token, prettyPrinting bool) string {
|
||||
}
|
||||
|
||||
func (c *Compiler) parseBlock() {
|
||||
if c.accept("var") {
|
||||
if c.get().Preprocessor {
|
||||
c.parsePreprocessor()
|
||||
} else if c.accept("var") {
|
||||
c.parseVar()
|
||||
} else if c.accept("if") {
|
||||
c.parseIf()
|
||||
@@ -52,6 +56,12 @@ func (c *Compiler) parseBlock() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Compiler) parsePreprocessor() {
|
||||
// we definitely want a new line here
|
||||
c.appendOut(c.get().Token+new_line, false)
|
||||
c.next()
|
||||
}
|
||||
|
||||
func (c *Compiler) parseVar() {
|
||||
c.expect("var")
|
||||
c.appendOut(c.get().Token, false)
|
||||
|
||||
@@ -154,6 +154,13 @@ func TestParserInlineCode(t *testing.T) {
|
||||
equal(t, got, want)
|
||||
}
|
||||
|
||||
func TestParserPreprocessor(t *testing.T) {
|
||||
got := getCompiled(t, "test/tokenizer_preprocessor.asl")
|
||||
want := "#define HELLO_WORLD \"Hello World!\"\r\nhint HELLO_WORLD;\r\n"
|
||||
|
||||
equal(t, got, want)
|
||||
}
|
||||
|
||||
func getCompiled(t *testing.T, file string) string {
|
||||
code, err := ioutil.ReadFile(file)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user