Выделил базовый класс LineParser
This commit is contained in:
parent
6fa21b52ae
commit
0587ffc139
|
|
@ -0,0 +1,15 @@
|
|||
class LineParser:
|
||||
def parseLine(self, line):
|
||||
assert line is not None
|
||||
pass
|
||||
|
||||
def isValidLine(self, line):
|
||||
assert line is not None
|
||||
return False
|
||||
|
||||
def _guardMatch(self, match_object, source, regexpSource = None):
|
||||
if match_object is None:
|
||||
msg = 'Recognition exception: {0} for {1}'.format(source, regexpSource)
|
||||
raise Exception(msg)
|
||||
|
||||
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
from parser.LineParser import LineParser
|
||||
from parser.ProjectParser.ProjectSetting.AttribureSetting import AttributeSetting
|
||||
from parser.ProjectParser.ProjectSetting.KeyValueSetting import KeyValueSetting
|
||||
import re
|
||||
|
||||
class ProjectLineParser:
|
||||
class ProjectLineParser(LineParser):
|
||||
def __init__(self, value_provider, command_token):
|
||||
assert value_provider is not None
|
||||
|
||||
|
|
@ -10,6 +11,7 @@ class ProjectLineParser:
|
|||
self._command_token = command_token
|
||||
|
||||
def parseLine(self, line):
|
||||
LineParser.parseLine(line)
|
||||
ws = ' '
|
||||
cmd_name_regexp = "^(?P<cmd_name>{0})".format(self._command_token)
|
||||
app_regexp = r"(?P<app>app:\S+)"
|
||||
|
|
@ -19,7 +21,7 @@ class ProjectLineParser:
|
|||
regexp = re.compile(source, re.UNICODE)
|
||||
|
||||
match = regexp.search(line)
|
||||
self.__guardMatch(match, line)
|
||||
self._guardMatch(match, line)
|
||||
|
||||
cmd_name = match.group('cmd_name')
|
||||
self.__parseProjectStatement(cmd_name)
|
||||
|
|
@ -40,7 +42,7 @@ class ProjectLineParser:
|
|||
patt = r'app:(?P<app_name>\w+)'
|
||||
|
||||
match = re.match(patt, statement)
|
||||
self.__guardMatch(match, statement)
|
||||
self._guardMatch(match, statement)
|
||||
|
||||
return match.group('app_name')
|
||||
|
||||
|
|
@ -59,7 +61,7 @@ class ProjectLineParser:
|
|||
patt = r"key:(?P<key>\w+) '(?P<value>[^']+)'"
|
||||
|
||||
match = re.search(patt, statement)
|
||||
self.__guardMatch(match, statement)
|
||||
self._guardMatch(match, statement)
|
||||
|
||||
key = match.group('key')
|
||||
value_link = match.group('value')
|
||||
|
|
@ -73,7 +75,7 @@ class ProjectLineParser:
|
|||
patt = r"(?P<attribute_name>\w+) '(?P<attribute_value>[^']+)'"
|
||||
|
||||
match = re.search(patt, statement)
|
||||
self.__guardMatch(match, statement)
|
||||
self._guardMatch(match, statement)
|
||||
|
||||
attribute_name = match.group('attribute_name')
|
||||
value_link = match.group('attribute_value')
|
||||
|
|
@ -82,10 +84,5 @@ class ProjectLineParser:
|
|||
setting = AttributeSetting(attribute_name, attribute_value)
|
||||
return setting
|
||||
|
||||
def __guardMatch(self, match_object, source):
|
||||
if match_object is None:
|
||||
msg = 'Recognition exception: {0}'.format(source)
|
||||
raise Exception(msg)
|
||||
|
||||
def __guardSource(self, source_text):
|
||||
assert source_text is not None and len(source_text) > 0
|
||||
Loading…
Reference in New Issue