Skip to content

Commit

Permalink
Update export_c() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen van der Heijden committed Oct 25, 2018
1 parent f17de02 commit ddaa4e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2018.10.25, Version 1.3.1 (Stable)

* Fixed exporting `Repeat` element to C. (issue #9)
* Added header file name option to `export_c()` method.

2018.10.15, Version 1.3.0 (Stable)

* Added element properties:
Expand Down
11 changes: 7 additions & 4 deletions pyleri/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class {name}(Grammar):
* Created at: {datetime}
*/
#include "{target}.h"
#include {header_file}
#include <stdio.h>
#define CLERI_CASE_SENSITIVE 0
Expand All @@ -233,7 +233,7 @@ class {name}(Grammar):
#define CLERI_FIRST_MATCH 0
#define CLERI_MOST_GREEDY 1
cleri_grammar_t * compile_grammar(void)
cleri_grammar_t * compile_{target}(void)
{{
{language}
Expand All @@ -258,7 +258,7 @@ class {name}(Grammar):
#include <cleri/cleri.h>
cleri_grammar_t * compile_grammar(void);
cleri_grammar_t * compile_{target}(void);
enum cleri_grammar_ids {{
CLERI_NONE, // used for objects with no name
Expand Down Expand Up @@ -449,7 +449,7 @@ def export_py(
' '.join(['from', py_module_name, 'import', n])
for n in classes if n != 'Rule'])))

def export_c(self, target=C_TARGET, c_indent=C_INDENTATION):
def export_c(self, target=C_TARGET, c_indent=C_INDENTATION, headerf=None):
'''Export the grammar to a c (source and header) file which can be
used with the libcleri module.'''
language = []
Expand Down Expand Up @@ -487,9 +487,12 @@ def export_c(self, target=C_TARGET, c_indent=C_INDENTATION):
'{}{}'.format(c_indent, gid)
for gid in sorted(enums)]) + ','

header_file = '"{}.h"'.format(target) if headerf is None else headerf

return (self.__class__.C_TEMPLATE_C.format(
name=self.__class__.__name__,
target=target,
header_file=header_file,
indent=c_indent,
datetime=time.strftime(
'%Y-%m-%d %H:%M:%S',
Expand Down

0 comments on commit ddaa4e1

Please sign in to comment.