aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2014-06-01 23:08:37 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2014-06-01 23:08:37 +0300
commit4652088c187b7de0aba8f1afff02c70200443d94 (patch)
treea315dc122b6e4f712e8a0bdc36ca3a0f4dba8151
parent951e6d1f82f3814b0de95f1eaaba129005cb5cbb (diff)
downloadmeson-4652088c187b7de0aba8f1afff02c70200443d94.zip
meson-4652088c187b7de0aba8f1afff02c70200443d94.tar.gz
meson-4652088c187b7de0aba8f1afff02c70200443d94.tar.bz2
Work further into LLVM parsing.
-rwxr-xr-xtools/cmake2meson.py32
1 files changed, 23 insertions, 9 deletions
diff --git a/tools/cmake2meson.py b/tools/cmake2meson.py
index e7956fd..359c6ee 100755
--- a/tools/cmake2meson.py
+++ b/tools/cmake2meson.py
@@ -34,8 +34,8 @@ class Lexer:
self.token_specification = [
# Need to be sorted longest to shortest.
('ignore', re.compile(r'[ \t]')),
- ('string', re.compile('"[^"]*?"')),
- ('id', re.compile('''[-+_0-9a-z/A-Z@.]+''')),
+ ('string', re.compile(r'"([^\\]|(\\.))*?"', re.M)),
+ ('id', re.compile('''[-=+_0-9a-z/A-Z@.*]+''')),
('eol', re.compile(r'\n')),
('comment', re.compile(r'\#.*')),
('lparen', re.compile(r'\(')),
@@ -106,15 +106,24 @@ class Parser():
def statement(self):
name = self.current.value
self.accept('id')
- args = []
self.expect('lparen')
+ args = self.arguments()
+ self.expect('rparen')
+ return Statement(name, args)
+
+ def arguments(self):
+ args = []
arg = self.current.value
- while self.accept('string') or self.accept('varexp') or\
+ if self.accept('lparen'):
+ args.append(self.arguments())
+ self.expect('rparen')
+ if self.accept('string') or self.accept('varexp') or\
self.accept('id'):
args.append(arg)
- arg = self.current.value
- self.expect('rparen')
- return Statement(name, args)
+ rest = self.arguments()
+ if len(rest) > 0:
+ args.append(rest)
+ return args
def parse(self):
while not self.accept('eof'):
@@ -122,12 +131,17 @@ class Parser():
def convert(cmake_root):
cfile = os.path.join(cmake_root, 'CMakeLists.txt')
- cmakecode = open(cfile).read()
+ try:
+ cmakecode = open(cfile).read()
+ except FileNotFoundError:
+ print('\nWarning: No CMakeLists.txt in', cmake_root, '\n')
+ return
p = Parser(cmakecode)
for t in p.parse():
if t.name == 'add_subdirectory':
- print('\nRecursing to subdir', t.args[0], '\n')
+ print('\nRecursing to subdir', os.path.join(cmake_root, t.args[0]), '\n')
convert(os.path.join(cmake_root, t.args[0]))
+ print('\nReturning to', cmake_root, '\n')
else:
print(t.name, t.args)