# Changeset 3928 for proto

Ignore:
Timestamp:
Jul 25, 2014, 11:36:50 AM (5 years ago)
Message:

Implements the new algorithm to reduce the number of character class equations.

File:
1 edited

Unmodified
Added
Removed
• ## proto/charsetcompiler/charset_compiler.py

 r3413 def charset_expr(chardef): if chardef.items == []: return FalseLiteral() if len(chardef.items) > 1: combine = True #If all of the charset items are single codepoints #such that X0 == Y0, X1 == Y1 etc. for i in range(1, len(chardef.items)): if len(chardef.items[i]) == 3: combine = False break if combine == True: #If charset items are all of the form X1 = X0 + 2. for i in range(1 , len(chardef.items) - 1): curr_item = chardef.items[i] next_item = chardef.items[i+1] if ord(curr_item) != ord(next_item) - 2: combine = False break if combine == True: first_item = ord(chardef.items[0]) last_item = ord(chardef.items[len(chardef.items)-1]) utf_temp = UTF_encoding.Encoding.mask - 1 first_item &= utf_temp last_item |= (UTF_encoding.Encoding.mask ^ utf_temp) return char_or_range_expr(chr(first_item) + '-' + chr(last_item)) e1 = char_or_range_expr(chardef.items[0]) for i in range(1, len(chardef.items)): print '\tprint_register("%s",%s);\n' % (d.name, d.name) print "\ndef main():\n\tDo_defs(%s)\n" % params else: print stmts else: print stmts #fo = open("icgrep_dev/Z_equations.txt", "wb") #fo.write(stmts); # Close opend file #fo.close() else: option_parser.print_usage()
Note: See TracChangeset for help on using the changeset viewer.