From cf3ece41225f5fd97f1ae6cfa1144efe8843e080 Mon Sep 17 00:00:00 2001 From: Adanteh Date: Tue, 10 Sep 2019 16:28:37 +0200 Subject: [PATCH 1/2] Fix empty class usage --- armaclass/parser.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/armaclass/parser.py b/armaclass/parser.py index 894aea9..48102f7 100644 --- a/armaclass/parser.py +++ b/armaclass/parser.py @@ -5,6 +5,7 @@ QUOTE = '"' SEMICOLON = ';' +COLON = ":" EQUALS = '=' CURLY_OPEN = '{' CURLY_CLOSE = '}' @@ -195,7 +196,7 @@ def parseProperty(self, context): name = self.parsePropertyName() self.parseWhitespace() - if self.current() == ':': + if self.current() == COLON: self.next() self.parseWhitespace() self.parsePropertyName() @@ -203,7 +204,7 @@ def parseProperty(self, context): current = self.current() - + if current == SQUARE_OPEN: self.ensure(self.next() == SQUARE_CLOSE) self.next() @@ -215,6 +216,10 @@ def parseProperty(self, context): value = self.parseArray() + elif current == SEMICOLON: + value = self.dict() + self.parseWhitespace() + elif current == EQUALS: self.next() self.parseWhitespace() From 04d4269be6e109e0d44c9a1402f16f94255b7c67 Mon Sep 17 00:00:00 2001 From: Adanteh Date: Thu, 12 Sep 2019 16:51:53 +0200 Subject: [PATCH 2/2] Add handling of basic macros (No preprocessing) --- armaclass/parser.py | 22 ++++++++++++++++++++++ test/test_basic.py | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/armaclass/parser.py b/armaclass/parser.py index 48102f7..c651caf 100644 --- a/armaclass/parser.py +++ b/armaclass/parser.py @@ -15,6 +15,8 @@ MINUS = '-' SLASH = '/' ASTERISK = '*' +BACKSLASH = '\\' +HASH = '#' VALID_NAME_CHAR = string.ascii_letters + string.digits + '_.\\' @@ -187,6 +189,20 @@ def parseWhitespace(self): except IndexError: pass + def parseMacro(self): + macro = "" + try: + while ( + self.raw[self.currentPosition] not in "\r\n" + or self.raw[self.currentPosition - 1: self.currentPosition + 1] in ("\\\r", "\\\n") + ): + macro += self.current() + self.next() + except IndexError: + pass + + return macro + def parseProperty(self, context): name = self.parsePropertyName() @@ -216,6 +232,12 @@ def parseProperty(self, context): value = self.parseArray() + elif name.startswith(HASH): + macros = context.get(name, []) + macros.append(self.parseMacro()) + context[name] = macros + return + elif current == SEMICOLON: value = self.dict() self.parseWhitespace() diff --git a/test/test_basic.py b/test/test_basic.py index 541ddf6..1def1f3 100644 --- a/test/test_basic.py +++ b/test/test_basic.py @@ -58,6 +58,10 @@ def test_ignore_inheritance(self): testString = 'class Moo : foo {};' self.assertEqual(parse(testString), {'Moo': {}}) + def test_macros(self): + self.assertEqual(parse('#include "cfgSurfaces.h"'), {"#include": ['"cfgSurfaces.h"']}) + self.assertEqual(parse('#define TESTING firstline = 1;\\\nsecondline = 2;'), {"#define": ['TESTING firstline = 1;\\\nsecondline = 2;']}) + def test_line_comments(self): self.assertEqual(parse('// foo comment'), {}) self.assertEqual(parse('// foo comment\nx=2;'), {'x': 2})