Merge branch 'wmlparser_metadata'

This commit is contained in:
Alexander van Gessel 2014-01-15 18:02:50 +01:00
commit f9308f727d

View file

@ -58,8 +58,9 @@ class AttributeNode:
id=Elfish Archer
[/unit]
"""
def __init__(self, name):
def __init__(self, name, location=None):
self.name = name
self.location = location
self.value = [] # List of StringNode
def debug(self):
@ -83,8 +84,9 @@ class TagNode:
id=Elfish Archer
[/unit]
"""
def __init__(self, name):
def __init__(self, name, location=None):
self.name = name
self.location = location
# List of child elements, which are either of type TagNode or
# AttributeNode.
self.data = []
@ -207,6 +209,8 @@ class Parser:
self.last_wml_line = "?"
self.parser_line = 0
self.line_in_file = 42424242
self.chunk_start = "?"
def parse_file(self, path, defines=""):
self.path = path
@ -381,7 +385,7 @@ class Parser:
if tag[0] == "/":
self.parent_node = self.parent_node[:-1]
else:
node = TagNode(tag)
node = TagNode(tag, location=(self.line_in_file, self.chunk_start))
if self.parent_node:
self.parent_node[-1].append(node)
self.parent_node.append(node)
@ -398,7 +402,7 @@ class Parser:
self.temp_key_nodes = []
for att in line.split(","):
att = att.strip()
node = AttributeNode(att)
node = AttributeNode(att, location=(self.line_in_file, self.chunk_start))
self.temp_key_nodes.append(node)
if self.parent_node:
self.parent_node[-1].append(node)
@ -453,9 +457,11 @@ class Parser:
if not input: input = self.path
for rawline in open(input, "rb"):
compos = rawline.find(command_marker_byte)
self.parser_line += 1
# Everything from chr(254) to newline is the command.
compos = rawline.find(command_marker_byte)
if compos != 0:
self.line_in_file += 1
if compos >= 0:
self.parse_line_without_commands(rawline[:compos])
self.handle_command(rawline[compos + 1:-1])
@ -470,6 +476,9 @@ class Parser:
def handle_command(self, com):
if com.startswith("line "):
self.last_wml_line = com[5:]
_ = self.last_wml_line.split(" ")
self.chunk_start = [(_[i+1], int(_[i])) for i in range(0, len(_), 2)]
self.line_in_file = self.chunk_start[0][1]
elif com.startswith("textdomain "):
self.textdomain = com[11:]
else: