Comments are converted. Yay!
This commit is contained in:
parent
053cc2e5f8
commit
c8184965c4
|
@ -35,7 +35,7 @@ class Lexer:
|
||||||
# Need to be sorted longest to shortest.
|
# Need to be sorted longest to shortest.
|
||||||
('ignore', re.compile(r'[ \t]')),
|
('ignore', re.compile(r'[ \t]')),
|
||||||
('string', re.compile(r'"([^\\]|(\\.))*?"', re.M)),
|
('string', re.compile(r'"([^\\]|(\\.))*?"', re.M)),
|
||||||
('id', re.compile('''[,-=+_0-9a-z/A-Z@.*]+''')),
|
('id', re.compile('''[,-><${}=+_0-9a-z/A-Z@.*]+''')),
|
||||||
('eol', re.compile(r'\n')),
|
('eol', re.compile(r'\n')),
|
||||||
('comment', re.compile(r'\#.*')),
|
('comment', re.compile(r'\#.*')),
|
||||||
('lparen', re.compile(r'\(')),
|
('lparen', re.compile(r'\(')),
|
||||||
|
@ -106,12 +106,14 @@ class Parser():
|
||||||
raise RuntimeError('Expecting %s got %s.' % (s, self.current.tid), self.current.lineno, self.current.colno)
|
raise RuntimeError('Expecting %s got %s.' % (s, self.current.tid), self.current.lineno, self.current.colno)
|
||||||
|
|
||||||
def statement(self):
|
def statement(self):
|
||||||
name = self.current.value
|
cur = self.current
|
||||||
|
if self.accept('comment'):
|
||||||
|
return Statement('_', [cur.value])
|
||||||
self.accept('id')
|
self.accept('id')
|
||||||
self.expect('lparen')
|
self.expect('lparen')
|
||||||
args = self.arguments()
|
args = self.arguments()
|
||||||
self.expect('rparen')
|
self.expect('rparen')
|
||||||
return Statement(name, args)
|
return Statement(cur.value, args)
|
||||||
|
|
||||||
def arguments(self):
|
def arguments(self):
|
||||||
args = []
|
args = []
|
||||||
|
@ -133,6 +135,18 @@ class Parser():
|
||||||
class Converter:
|
class Converter:
|
||||||
def __init__(self, cmake_root):
|
def __init__(self, cmake_root):
|
||||||
self.cmake_root = cmake_root
|
self.cmake_root = cmake_root
|
||||||
|
self.indent_unit = ' '
|
||||||
|
|
||||||
|
def write_entry(self, outfile, indent, t):
|
||||||
|
if t.name == '_':
|
||||||
|
outfile.writelines([indent, t.args[0], '\n'])
|
||||||
|
elif t.name == 'subdir':
|
||||||
|
outfile.writelines([indent, t.args[0], '\n'])
|
||||||
|
else:
|
||||||
|
self.unknown_command(outfile, indent, t)
|
||||||
|
|
||||||
|
def unknown_command(self, outfile, indent, t):
|
||||||
|
outfile.writelines([indent, '# ', t.name, '\n'])
|
||||||
|
|
||||||
def convert(self, subdir=''):
|
def convert(self, subdir=''):
|
||||||
if subdir == '':
|
if subdir == '':
|
||||||
|
@ -144,13 +158,15 @@ class Converter:
|
||||||
print('\nWarning: No CMakeLists.txt in', subdir, '\n')
|
print('\nWarning: No CMakeLists.txt in', subdir, '\n')
|
||||||
return
|
return
|
||||||
p = Parser(cmakecode)
|
p = Parser(cmakecode)
|
||||||
|
outfile = open(os.path.join(subdir, 'meson.build'), 'w')
|
||||||
|
indent_depth = 0
|
||||||
for t in p.parse():
|
for t in p.parse():
|
||||||
|
indent = self.indent_unit*indent_depth
|
||||||
if t.name == 'add_subdirectory':
|
if t.name == 'add_subdirectory':
|
||||||
print('\nRecursing to subdir', os.path.join(self.cmake_root, t.args[0].value), '\n')
|
#print('\nRecursing to subdir', os.path.join(self.cmake_root, t.args[0].value), '\n')
|
||||||
self.convert(os.path.join(subdir, t.args[0].value))
|
self.convert(os.path.join(subdir, t.args[0].value))
|
||||||
print('\nReturning to', self.cmake_root, '\n')
|
#print('\nReturning to', self.cmake_root, '\n')
|
||||||
else:
|
self.write_entry(outfile, indent, t)
|
||||||
print(t.name, t.args)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
|
|
Loading…
Reference in New Issue