Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: net/tools/dafsa/make_dafsa.py

Issue 1756733003: Support all possible bitflags when computing the PSL DAFSA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/tools/dafsa/make_dafsa_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ 6 """
7 A Deterministic acyclic finite state automaton (DAFSA) is a compact 7 A Deterministic acyclic finite state automaton (DAFSA) is a compact
8 representation of an unordered word list (dictionary). 8 representation of an unordered word list (dictionary).
9 9
10 http://en.wikipedia.org/wiki/Deterministic_acyclic_finite_state_automaton 10 http://en.wikipedia.org/wiki/Deterministic_acyclic_finite_state_automaton
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 def parse_gperf(infile): 441 def parse_gperf(infile):
442 """Parses gperf file and extract strings and return code""" 442 """Parses gperf file and extract strings and return code"""
443 lines = [line.strip() for line in infile] 443 lines = [line.strip() for line in infile]
444 # Extract strings after the first '%%' and before the second '%%'. 444 # Extract strings after the first '%%' and before the second '%%'.
445 begin = lines.index('%%') + 1 445 begin = lines.index('%%') + 1
446 end = lines.index('%%', begin) 446 end = lines.index('%%', begin)
447 lines = lines[begin:end] 447 lines = lines[begin:end]
448 for line in lines: 448 for line in lines:
449 if line[-3:-1] != ', ': 449 if line[-3:-1] != ', ':
450 raise InputError('Expected "domainname, <digit>", found "%s"' % line) 450 raise InputError('Expected "domainname, <digit>", found "%s"' % line)
451 # Technically the DAFSA format could support return values in range [0-31], 451 # Technically the DAFSA format can support return values in the range
452 # but the values below are the only with a defined meaning. 452 # [0-31], but only the first three bits have any defined meaning.
453 if line[-1] not in '0124': 453 if line[-1] not in map(str, range(0, 7)):
M-A Ruel 2016/03/03 22:19:43 That's an relatively expensive call to do at every
454 raise InputError('Expected value to be one of {0,1,2,4}, found "%s"' % 454 raise InputError('Expected value to be in the range of 0-7, found "%s"' %
455 line[-1]) 455 line[-1])
456 return [line[:-3] + line[-1] for line in lines] 456 return [line[:-3] + line[-1] for line in lines]
457 457
458 458
459 def main(): 459 def main():
460 if len(sys.argv) != 3: 460 if len(sys.argv) != 3:
461 print('usage: %s infile outfile' % sys.argv[0]) 461 print('usage: %s infile outfile' % sys.argv[0])
462 return 1 462 return 1
463 with open(sys.argv[1], 'r') as infile, open(sys.argv[2], 'w') as outfile: 463 with open(sys.argv[1], 'r') as infile, open(sys.argv[2], 'w') as outfile:
464 outfile.write(words_to_cxx(parse_gperf(infile))) 464 outfile.write(words_to_cxx(parse_gperf(infile)))
465 return 0 465 return 0
466 466
467 467
468 if __name__ == '__main__': 468 if __name__ == '__main__':
469 sys.exit(main()) 469 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | net/tools/dafsa/make_dafsa_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698