Skip to content

Fix empty class usage #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions armaclass/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

QUOTE = '"'
SEMICOLON = ';'
COLON = ":"
EQUALS = '='
CURLY_OPEN = '{'
CURLY_CLOSE = '}'
Expand All @@ -14,6 +15,8 @@
MINUS = '-'
SLASH = '/'
ASTERISK = '*'
BACKSLASH = '\\'
HASH = '#'

VALID_NAME_CHAR = string.ascii_letters + string.digits + '_.\\'

Expand Down Expand Up @@ -186,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()

Expand All @@ -195,15 +212,15 @@ def parseProperty(self, context):
name = self.parsePropertyName()
self.parseWhitespace()

if self.current() == ':':
if self.current() == COLON:
self.next()
self.parseWhitespace()
self.parsePropertyName()
self.parseWhitespace()


current = self.current()

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to remove the trailing spaces here

if current == SQUARE_OPEN:
self.ensure(self.next() == SQUARE_CLOSE)
self.next()
Expand All @@ -215,6 +232,16 @@ 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()

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance you could add a test for this case? I'm slowly starting to think about merging this ;)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahem! ;)

elif current == EQUALS:
self.next()
self.parseWhitespace()
Expand Down
4 changes: 4 additions & 0 deletions test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down