Created
June 1, 2015 18:17
-
-
Save oprypin/136d5d5fc9f3f531d663 to your computer and use it in GitHub Desktop.
crystalize.py PCRE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/crystalize.py b/crystalize.py | |
index 8f85408..d53a4ac 100755 | |
--- a/crystalize.py | |
+++ b/crystalize.py | |
@@ -76,7 +76,7 @@ code = [] | |
keywords = 'alias and begin break case class def defined do else elsif end ensure false for if in module next nil not or redo rescue retry return self super then true undef unless until when while yield BEGIN END'.split() | |
-lib_name = 'Lib' | |
+lib_name = 'PCRE' | |
def rename_identifier(name): | |
name = re.sub('[A-Z](?![A-Z0-9_]|$)', lambda m: '_' + m.group(0).lower(), name) | |
@@ -87,10 +87,10 @@ def rename_identifier(name): | |
return name | |
def rename_const(name): | |
- return rename_identifier(name).upper() | |
+ return re.sub(r'PCRE_(.+)', r'\1', name) | |
def rename_func(name): | |
- return rename_identifier(name) | |
+ return re.sub(r'pcre(|16|32)_(.+)', r'\2_\1', name).strip('_') | |
def native_type(type): | |
for match, repl in { | |
@@ -292,11 +292,16 @@ for top in ast.ext: | |
output.append('alias {} = {}'.format(rename_type(top.name), make_type(top.type))) | |
elif isinstance(top, Decl) and top.quals == ['const']: | |
+ if not top.name.startswith('PCRE_'): | |
+ continue | |
+ name = rename_const(top.name) | |
+ if name in 'DATE UCHAR16 SPTR16 UCHAR32 SPTR32 SPTR'.split(): | |
+ continue | |
val = generate_c(top.init) | |
if top.init: | |
- output.append('{} = {}'.format(rename_const(top.name), val.strip('"'))) | |
+ output.append('{} = {}'.format(name, val.strip('"'))) | |
else: | |
- output.append('#{} ='.format(rename_const(top.name))) | |
+ output.append('#{} ='.format(name)) | |
elif isinstance(top, Decl): | |
output.append('${} : {}'.format(rename_identifier(top.name), make_type(top.type))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lib PCRE | |
MAJOR = 8 | |
MINOR = 36 | |
EXP_DECL = extern | |
CASELESS = 0x00000001 | |
MULTILINE = 0x00000002 | |
DOTALL = 0x00000004 | |
EXTENDED = 0x00000008 | |
ANCHORED = 0x00000010 | |
DOLLAR_ENDONLY = 0x00000020 | |
EXTRA = 0x00000040 | |
NOTBOL = 0x00000080 | |
NOTEOL = 0x00000100 | |
UNGREEDY = 0x00000200 | |
NOTEMPTY = 0x00000400 | |
UTF8 = 0x00000800 | |
UTF16 = 0x00000800 | |
UTF32 = 0x00000800 | |
NO_AUTO_CAPTURE = 0x00001000 | |
NO_UTF8_CHECK = 0x00002000 | |
NO_UTF16_CHECK = 0x00002000 | |
NO_UTF32_CHECK = 0x00002000 | |
AUTO_CALLOUT = 0x00004000 | |
PARTIAL_SOFT = 0x00008000 | |
PARTIAL = 0x00008000 | |
NEVER_UTF = 0x00010000 | |
DFA_SHORTEST = 0x00010000 | |
NO_AUTO_POSSESS = 0x00020000 | |
DFA_RESTART = 0x00020000 | |
FIRSTLINE = 0x00040000 | |
DUPNAMES = 0x00080000 | |
NEWLINE_CR = 0x00100000 | |
NEWLINE_LF = 0x00200000 | |
NEWLINE_CRLF = 0x00300000 | |
NEWLINE_ANY = 0x00400000 | |
NEWLINE_ANYCRLF = 0x00500000 | |
BSR_ANYCRLF = 0x00800000 | |
BSR_UNICODE = 0x01000000 | |
JAVASCRIPT_COMPAT = 0x02000000 | |
NO_START_OPTIMIZE = 0x04000000 | |
NO_START_OPTIMISE = 0x04000000 | |
PARTIAL_HARD = 0x08000000 | |
NOTEMPTY_ATSTART = 0x10000000 | |
UCP = 0x20000000 | |
ERROR_NOMATCH = (-1) | |
ERROR_NULL = (-2) | |
ERROR_BADOPTION = (-3) | |
ERROR_BADMAGIC = (-4) | |
ERROR_UNKNOWN_OPCODE = (-5) | |
ERROR_UNKNOWN_NODE = (-5) | |
ERROR_NOMEMORY = (-6) | |
ERROR_NOSUBSTRING = (-7) | |
ERROR_MATCHLIMIT = (-8) | |
ERROR_CALLOUT = (-9) | |
ERROR_BADUTF8 = (-10) | |
ERROR_BADUTF16 = (-10) | |
ERROR_BADUTF32 = (-10) | |
ERROR_BADUTF8_OFFSET = (-11) | |
ERROR_BADUTF16_OFFSET = (-11) | |
ERROR_PARTIAL = (-12) | |
ERROR_BADPARTIAL = (-13) | |
ERROR_INTERNAL = (-14) | |
ERROR_BADCOUNT = (-15) | |
ERROR_DFA_UITEM = (-16) | |
ERROR_DFA_UCOND = (-17) | |
ERROR_DFA_UMLIMIT = (-18) | |
ERROR_DFA_WSSIZE = (-19) | |
ERROR_DFA_RECURSE = (-20) | |
ERROR_RECURSIONLIMIT = (-21) | |
ERROR_NULLWSLIMIT = (-22) | |
ERROR_BADNEWLINE = (-23) | |
ERROR_BADOFFSET = (-24) | |
ERROR_SHORTUTF8 = (-25) | |
ERROR_SHORTUTF16 = (-25) | |
ERROR_RECURSELOOP = (-26) | |
ERROR_JIT_STACKLIMIT = (-27) | |
ERROR_BADMODE = (-28) | |
ERROR_BADENDIANNESS = (-29) | |
ERROR_DFA_BADRESTART = (-30) | |
ERROR_JIT_BADOPTION = (-31) | |
ERROR_BADLENGTH = (-32) | |
ERROR_UNSET = (-33) | |
UTF8_ERR0 = 0 | |
UTF8_ERR1 = 1 | |
UTF8_ERR2 = 2 | |
UTF8_ERR3 = 3 | |
UTF8_ERR4 = 4 | |
UTF8_ERR5 = 5 | |
UTF8_ERR6 = 6 | |
UTF8_ERR7 = 7 | |
UTF8_ERR8 = 8 | |
UTF8_ERR9 = 9 | |
UTF8_ERR10 = 10 | |
UTF8_ERR11 = 11 | |
UTF8_ERR12 = 12 | |
UTF8_ERR13 = 13 | |
UTF8_ERR14 = 14 | |
UTF8_ERR15 = 15 | |
UTF8_ERR16 = 16 | |
UTF8_ERR17 = 17 | |
UTF8_ERR18 = 18 | |
UTF8_ERR19 = 19 | |
UTF8_ERR20 = 20 | |
UTF8_ERR21 = 21 | |
UTF8_ERR22 = 22 | |
UTF16_ERR0 = 0 | |
UTF16_ERR1 = 1 | |
UTF16_ERR2 = 2 | |
UTF16_ERR3 = 3 | |
UTF16_ERR4 = 4 | |
UTF32_ERR0 = 0 | |
UTF32_ERR1 = 1 | |
UTF32_ERR2 = 2 | |
UTF32_ERR3 = 3 | |
INFO_OPTIONS = 0 | |
INFO_SIZE = 1 | |
INFO_CAPTURECOUNT = 2 | |
INFO_BACKREFMAX = 3 | |
INFO_FIRSTBYTE = 4 | |
INFO_FIRSTCHAR = 4 | |
INFO_FIRSTTABLE = 5 | |
INFO_LASTLITERAL = 6 | |
INFO_NAMEENTRYSIZE = 7 | |
INFO_NAMECOUNT = 8 | |
INFO_NAMETABLE = 9 | |
INFO_STUDYSIZE = 10 | |
INFO_DEFAULT_TABLES = 11 | |
INFO_OKPARTIAL = 12 | |
INFO_JCHANGED = 13 | |
INFO_HASCRORLF = 14 | |
INFO_MINLENGTH = 15 | |
INFO_JIT = 16 | |
INFO_JITSIZE = 17 | |
INFO_MAXLOOKBEHIND = 18 | |
INFO_FIRSTCHARACTER = 19 | |
INFO_FIRSTCHARACTERFLAGS = 20 | |
INFO_REQUIREDCHAR = 21 | |
INFO_REQUIREDCHARFLAGS = 22 | |
INFO_MATCHLIMIT = 23 | |
INFO_RECURSIONLIMIT = 24 | |
INFO_MATCH_EMPTY = 25 | |
CONFIG_UTF8 = 0 | |
CONFIG_NEWLINE = 1 | |
CONFIG_LINK_SIZE = 2 | |
CONFIG_POSIX_MALLOC_THRESHOLD = 3 | |
CONFIG_MATCH_LIMIT = 4 | |
CONFIG_STACKRECURSE = 5 | |
CONFIG_UNICODE_PROPERTIES = 6 | |
CONFIG_MATCH_LIMIT_RECURSION = 7 | |
CONFIG_BSR = 8 | |
CONFIG_JIT = 9 | |
CONFIG_UTF16 = 10 | |
CONFIG_JITTARGET = 11 | |
CONFIG_UTF32 = 12 | |
CONFIG_PARENS_LIMIT = 13 | |
STUDY_JIT_COMPILE = 0x0001 | |
STUDY_JIT_PARTIAL_SOFT_COMPILE = 0x0002 | |
STUDY_JIT_PARTIAL_HARD_COMPILE = 0x0004 | |
STUDY_EXTRA_NEEDED = 0x0008 | |
EXTRA_STUDY_DATA = 0x0001 | |
EXTRA_MATCH_LIMIT = 0x0002 | |
EXTRA_CALLOUT_DATA = 0x0004 | |
EXTRA_TABLES = 0x0008 | |
EXTRA_MATCH_LIMIT_RECURSION = 0x0010 | |
EXTRA_MARK = 0x0020 | |
EXTRA_EXECUTABLE_JIT = 0x0040 | |
type RealPcre = Void* | |
type Pcre = Void* | |
type RealPcre16 = Void* | |
type Pcre16 = Void* | |
type RealPcre32 = Void* | |
type Pcre32 = Void* | |
type RealPcreJitStack = Void* | |
type PcreJitStack = Void* | |
type RealPcre16JitStack = Void* | |
type Pcre16JitStack = Void* | |
type RealPcre32JitStack = Void* | |
type Pcre32JitStack = Void* | |
struct PcreExtra | |
flags : LibC::LongT | |
study_data : Void* | |
match_limit : LibC::LongT | |
callout_data : Void* | |
tables : UInt8* | |
match_limit_recursion : LibC::LongT | |
mark : UInt8** | |
executable_jit : Void* | |
end | |
struct Pcre16Extra | |
flags : LibC::LongT | |
study_data : Void* | |
match_limit : LibC::LongT | |
callout_data : Void* | |
tables : UInt8* | |
match_limit_recursion : LibC::LongT | |
mark : UInt16** | |
executable_jit : Void* | |
end | |
struct Pcre32Extra | |
flags : LibC::LongT | |
study_data : Void* | |
match_limit : LibC::LongT | |
callout_data : Void* | |
tables : UInt8* | |
match_limit_recursion : LibC::LongT | |
mark : UInt32** | |
executable_jit : Void* | |
end | |
struct PcreCalloutBlock | |
version : Int32 | |
callout_number : Int32 | |
offset_vector : Int32* | |
subject : UInt8* | |
subject_length : Int32 | |
start_match : Int32 | |
current_position : Int32 | |
capture_top : Int32 | |
capture_last : Int32 | |
callout_data : Void* | |
pattern_position : Int32 | |
next_item_length : Int32 | |
mark : UInt8* | |
end | |
struct Pcre16CalloutBlock | |
version : Int32 | |
callout_number : Int32 | |
offset_vector : Int32* | |
subject : UInt16* | |
subject_length : Int32 | |
start_match : Int32 | |
current_position : Int32 | |
capture_top : Int32 | |
capture_last : Int32 | |
callout_data : Void* | |
pattern_position : Int32 | |
next_item_length : Int32 | |
mark : UInt16* | |
end | |
struct Pcre32CalloutBlock | |
version : Int32 | |
callout_number : Int32 | |
offset_vector : Int32* | |
subject : UInt32* | |
subject_length : Int32 | |
start_match : Int32 | |
current_position : Int32 | |
capture_top : Int32 | |
capture_last : Int32 | |
callout_data : Void* | |
pattern_position : Int32 | |
next_item_length : Int32 | |
mark : UInt32* | |
end | |
$pcre_malloc : (LibC::SizeT) -> Void* | |
$pcre_free : (Void*) -> Void | |
$pcre_stack_malloc : (LibC::SizeT) -> Void* | |
$pcre_stack_free : (Void*) -> Void | |
$pcre_callout : (PcreCalloutBlock*) -> Int32 | |
$pcre_stack_guard : -> Int32 | |
$pcre16_malloc : (LibC::SizeT) -> Void* | |
$pcre16_free : (Void*) -> Void | |
$pcre16_stack_malloc : (LibC::SizeT) -> Void* | |
$pcre16_stack_free : (Void*) -> Void | |
$pcre16_callout : (Pcre16CalloutBlock*) -> Int32 | |
$pcre16_stack_guard : -> Int32 | |
$pcre32_malloc : (LibC::SizeT) -> Void* | |
$pcre32_free : (Void*) -> Void | |
$pcre32_stack_malloc : (LibC::SizeT) -> Void* | |
$pcre32_stack_free : (Void*) -> Void | |
$pcre32_callout : (Pcre32CalloutBlock*) -> Int32 | |
$pcre32_stack_guard : -> Int32 | |
alias PcreJitCallback = (Void*) -> PcreJitStack | |
alias Pcre16JitCallback = (Void*) -> Pcre16JitStack | |
alias Pcre32JitCallback = (Void*) -> Pcre32JitStack | |
fun compile = "pcre_compile"(UInt8*, Int32, UInt8**, Int32*, UInt8*) : Pcre | |
fun compile_16 = "pcre16_compile"(UInt16*, Int32, UInt8**, Int32*, UInt8*) : Pcre16 | |
fun compile_32 = "pcre32_compile"(UInt32*, Int32, UInt8**, Int32*, UInt8*) : Pcre32 | |
fun compile2 = "pcre_compile2"(UInt8*, Int32, Int32*, UInt8**, Int32*, UInt8*) : Pcre | |
fun compile2_16 = "pcre16_compile2"(UInt16*, Int32, Int32*, UInt8**, Int32*, UInt8*) : Pcre16 | |
fun compile2_32 = "pcre32_compile2"(UInt32*, Int32, Int32*, UInt8**, Int32*, UInt8*) : Pcre32 | |
fun config = "pcre_config"(Int32, Void*) : Int32 | |
fun config_16 = "pcre16_config"(Int32, Void*) : Int32 | |
fun config_32 = "pcre32_config"(Int32, Void*) : Int32 | |
fun copy_named_substring = "pcre_copy_named_substring"(Pcre, UInt8*, Int32*, Int32, UInt8*, UInt8*, Int32) : Int32 | |
fun copy_named_substring_16 = "pcre16_copy_named_substring"(Pcre16, UInt16*, Int32*, Int32, UInt16*, UInt16*, Int32) : Int32 | |
fun copy_named_substring_32 = "pcre32_copy_named_substring"(Pcre32, UInt32*, Int32*, Int32, UInt32*, UInt32*, Int32) : Int32 | |
fun copy_substring = "pcre_copy_substring"(UInt8*, Int32*, Int32, Int32, UInt8*, Int32) : Int32 | |
fun copy_substring_16 = "pcre16_copy_substring"(UInt16*, Int32*, Int32, Int32, UInt16*, Int32) : Int32 | |
fun copy_substring_32 = "pcre32_copy_substring"(UInt32*, Int32*, Int32, Int32, UInt32*, Int32) : Int32 | |
fun dfa_exec = "pcre_dfa_exec"(Pcre, PcreExtra*, UInt8*, Int32, Int32, Int32, Int32*, Int32, Int32*, Int32) : Int32 | |
fun dfa_exec_16 = "pcre16_dfa_exec"(Pcre16, Pcre16Extra*, UInt16*, Int32, Int32, Int32, Int32*, Int32, Int32*, Int32) : Int32 | |
fun dfa_exec_32 = "pcre32_dfa_exec"(Pcre32, Pcre32Extra*, UInt32*, Int32, Int32, Int32, Int32*, Int32, Int32*, Int32) : Int32 | |
fun exec = "pcre_exec"(Pcre, PcreExtra*, UInt8*, Int32, Int32, Int32, Int32*, Int32) : Int32 | |
fun exec_16 = "pcre16_exec"(Pcre16, Pcre16Extra*, UInt16*, Int32, Int32, Int32, Int32*, Int32) : Int32 | |
fun exec_32 = "pcre32_exec"(Pcre32, Pcre32Extra*, UInt32*, Int32, Int32, Int32, Int32*, Int32) : Int32 | |
fun jit_exec = "pcre_jit_exec"(Pcre, PcreExtra*, UInt8*, Int32, Int32, Int32, Int32*, Int32, PcreJitStack) : Int32 | |
fun jit_exec_16 = "pcre16_jit_exec"(Pcre16, Pcre16Extra*, UInt16*, Int32, Int32, Int32, Int32*, Int32, Pcre16JitStack) : Int32 | |
fun jit_exec_32 = "pcre32_jit_exec"(Pcre32, Pcre32Extra*, UInt32*, Int32, Int32, Int32, Int32*, Int32, Pcre32JitStack) : Int32 | |
fun free_substring = "pcre_free_substring"(UInt8*) : Void | |
fun free_substring_16 = "pcre16_free_substring"(UInt16*) : Void | |
fun free_substring_32 = "pcre32_free_substring"(UInt32*) : Void | |
fun free_substring_list = "pcre_free_substring_list"(UInt8**) : Void | |
fun free_substring_list_16 = "pcre16_free_substring_list"(UInt16**) : Void | |
fun free_substring_list_32 = "pcre32_free_substring_list"(UInt32**) : Void | |
fun fullinfo = "pcre_fullinfo"(Pcre, PcreExtra*, Int32, Void*) : Int32 | |
fun fullinfo_16 = "pcre16_fullinfo"(Pcre16, Pcre16Extra*, Int32, Void*) : Int32 | |
fun fullinfo_32 = "pcre32_fullinfo"(Pcre32, Pcre32Extra*, Int32, Void*) : Int32 | |
fun get_named_substring = "pcre_get_named_substring"(Pcre, UInt8*, Int32*, Int32, UInt8*, UInt8**) : Int32 | |
fun get_named_substring_16 = "pcre16_get_named_substring"(Pcre16, UInt16*, Int32*, Int32, UInt16*, UInt16**) : Int32 | |
fun get_named_substring_32 = "pcre32_get_named_substring"(Pcre32, UInt32*, Int32*, Int32, UInt32*, UInt32**) : Int32 | |
fun get_stringnumber = "pcre_get_stringnumber"(Pcre, UInt8*) : Int32 | |
fun get_stringnumber_16 = "pcre16_get_stringnumber"(Pcre16, UInt16*) : Int32 | |
fun get_stringnumber_32 = "pcre32_get_stringnumber"(Pcre32, UInt32*) : Int32 | |
fun get_stringtable_entries = "pcre_get_stringtable_entries"(Pcre, UInt8*, UInt8**, UInt8**) : Int32 | |
fun get_stringtable_entries_16 = "pcre16_get_stringtable_entries"(Pcre16, UInt16*, UInt16**, UInt16**) : Int32 | |
fun get_stringtable_entries_32 = "pcre32_get_stringtable_entries"(Pcre32, UInt32*, UInt32**, UInt32**) : Int32 | |
fun get_substring = "pcre_get_substring"(UInt8*, Int32*, Int32, Int32, UInt8**) : Int32 | |
fun get_substring_16 = "pcre16_get_substring"(UInt16*, Int32*, Int32, Int32, UInt16**) : Int32 | |
fun get_substring_32 = "pcre32_get_substring"(UInt32*, Int32*, Int32, Int32, UInt32**) : Int32 | |
fun get_substring_list = "pcre_get_substring_list"(UInt8*, Int32*, Int32, UInt8***) : Int32 | |
fun get_substring_list_16 = "pcre16_get_substring_list"(UInt16*, Int32*, Int32, UInt16***) : Int32 | |
fun get_substring_list_32 = "pcre32_get_substring_list"(UInt32*, Int32*, Int32, UInt32***) : Int32 | |
fun maketables = "pcre_maketables"() : UInt8* | |
fun maketables_16 = "pcre16_maketables"() : UInt8* | |
fun maketables_32 = "pcre32_maketables"() : UInt8* | |
fun refcount = "pcre_refcount"(Pcre, Int32) : Int32 | |
fun refcount_16 = "pcre16_refcount"(Pcre16, Int32) : Int32 | |
fun refcount_32 = "pcre32_refcount"(Pcre32, Int32) : Int32 | |
fun study = "pcre_study"(Pcre, Int32, UInt8**) : PcreExtra* | |
fun study_16 = "pcre16_study"(Pcre16, Int32, UInt8**) : Pcre16Extra* | |
fun study_32 = "pcre32_study"(Pcre32, Int32, UInt8**) : Pcre32Extra* | |
fun free_study = "pcre_free_study"(PcreExtra*) : Void | |
fun free_study_16 = "pcre16_free_study"(Pcre16Extra*) : Void | |
fun free_study_32 = "pcre32_free_study"(Pcre32Extra*) : Void | |
fun version = "pcre_version"() : UInt8* | |
fun version_16 = "pcre16_version"() : UInt8* | |
fun version_32 = "pcre32_version"() : UInt8* | |
fun pattern_to_host_byte_order = "pcre_pattern_to_host_byte_order"(Pcre, PcreExtra*, UInt8*) : Int32 | |
fun pattern_to_host_byte_order_16 = "pcre16_pattern_to_host_byte_order"(Pcre16, Pcre16Extra*, UInt8*) : Int32 | |
fun pattern_to_host_byte_order_32 = "pcre32_pattern_to_host_byte_order"(Pcre32, Pcre32Extra*, UInt8*) : Int32 | |
fun utf16_to_host_byte_order_16 = "pcre16_utf16_to_host_byte_order"(UInt16*, UInt16*, Int32, Int32*, Int32) : Int32 | |
fun utf32_to_host_byte_order_32 = "pcre32_utf32_to_host_byte_order"(UInt32*, UInt32*, Int32, Int32*, Int32) : Int32 | |
fun jit_stack_alloc = "pcre_jit_stack_alloc"(Int32, Int32) : PcreJitStack | |
fun jit_stack_alloc_16 = "pcre16_jit_stack_alloc"(Int32, Int32) : Pcre16JitStack | |
fun jit_stack_alloc_32 = "pcre32_jit_stack_alloc"(Int32, Int32) : Pcre32JitStack | |
fun jit_stack_free = "pcre_jit_stack_free"(PcreJitStack) : Void | |
fun jit_stack_free_16 = "pcre16_jit_stack_free"(Pcre16JitStack) : Void | |
fun jit_stack_free_32 = "pcre32_jit_stack_free"(Pcre32JitStack) : Void | |
fun assign_jit_stack = "pcre_assign_jit_stack"(PcreExtra*, PcreJitCallback, Void*) : Void | |
fun assign_jit_stack_16 = "pcre16_assign_jit_stack"(Pcre16Extra*, Pcre16JitCallback, Void*) : Void | |
fun assign_jit_stack_32 = "pcre32_assign_jit_stack"(Pcre32Extra*, Pcre32JitCallback, Void*) : Void | |
fun jit_free_unused_memory = "pcre_jit_free_unused_memory"() : Void | |
fun jit_free_unused_memory_16 = "pcre16_jit_free_unused_memory"() : Void | |
fun jit_free_unused_memory_32 = "pcre32_jit_free_unused_memory"() : Void | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment