[vlc-commits] commit: Initial import for the parser ( trying to autogenerate the cpp binding) ( Rémi Duraffort )

git at videolan.org git at videolan.org
Sun Apr 25 15:17:09 CEST 2010


vlc/libvlcpp | branch: master | Rémi Duraffort <ivoire at videolan.org> | Sun Apr 25 12:38:33 2010 +0200| [492d8831ebe04a6d4f5a437e2e6b4229b0d1912c] | committer: Rémi Duraffort 

Initial import for the parser (trying to autogenerate the cpp binding)

> http://git.videolan.org/gitweb.cgi/vlc/libvlcpp.git/?a=commit;h=492d8831ebe04a6d4f5a437e2e6b4229b0d1912c
---

 parser.py |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/parser.py b/parser.py
new file mode 100755
index 0000000..3960b30
--- /dev/null
+++ b/parser.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+import sys
+
+def parse_headers(base_path):
+    parse(base_path + 'libvlc_media.h', 'libvlc_media_t *p_md')
+
+def parse(filename, removed_arg):
+    # Open the file
+    f_header = open(filename, 'r')
+
+    # Usefull informations
+    doxygen = ''
+    declaration = ''
+
+    # Read each line of the file
+    line = f_header.readline()
+    while(line):
+        # Begining of a doxygen comment ?
+        if(line.find('/**') == 0):
+            while(line.find('*/') == -1):
+                line = line + f_header.readline()
+            doxygen = line
+        # Declaration of a function
+        elif(line.find('VLC_PUBLIC_API') == 0):
+            while(line.find(';') == -1):
+                new_line = f_header.readline().lstrip(' ')
+                line = line.rstrip('\n').rstrip(' ')
+                if(line[-1] == '*'):
+                    line = line + new_line
+                else:
+                    line = line + ' ' + new_line
+            declaration = line.lstrip('VLC_PUBLIC_API ').rstrip('\n').rstrip(';')
+
+            # Special case for 'FORWARD_DECLARE_OBJECT'
+            if(declaration.find('FORWARD_DECLARE_OBJECT') == 0):
+                declaration = declaration.lstrip('FORWARD_DECLARE_OBJECT(')
+                declaration = declaration.replace(') ', '', 1)
+            if(declaration.find(',') == -1):
+                declaration = declaration.replace('( ' + removed_arg + ' )', '()')
+            else:
+                declaration = declaration.replace('( ' + removed_arg + ', ', '( ')
+            print declaration
+
+        line = f_header.readline()
+
+# Begining of the script
+if __name__ == "__main__":
+    if(len(sys.argv) != 2):
+        print("Usage: parser.py header_directory")
+        sys.exit(1)
+
+    parse_headers(sys.argv[1])



More information about the vlc-commits mailing list