Grammalecte  Check-in [c761d5a874]

Overview
Comment:[build] use named groups in regex
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | build
Files: files | file ages | folders
SHA3-256: c761d5a874dc3f757cd8efca3020063eed2d5107d27687742588ed939ae0d93d
User & Date: olr on 2017-05-03 10:03:21
Other Links: manifest | tags
Context
2017-05-03
14:14
[fr] faux positif, impératif check-in: 8bc6507f80 user: olr tags: fr, trunk
10:03
[build] use named groups in regex check-in: c761d5a874 user: olr tags: build, trunk
08:00
[build] check if rules have same id check-in: 0dba21491a user: olr tags: build, trunk
Changes

Modified compile_rules.py from [2d30706580] to [d1b7f6f58e].

   171    171       sRuleId = sLineId
   172    172       sOption = False         # False or [a-z0-9]+ name
   173    173       nPriority = 4           # Default is 4, value must be between 0 and 9
   174    174       tGroups = None          # code for groups positioning (only useful for JavaScript)
   175    175       cCaseMode = 'i'         # i: case insensitive,  s: case sensitive,  u: uppercasing allowed
   176    176       cWordLimitLeft = '['    # [: word limit, <: no specific limit
   177    177       cWordLimitRight = ']'   # ]: word limit, >: no specific limit
   178         -    m = re.match("^__([[<]\\w[]>])(/[a-zA-Z0-9]+|)(\\(\\w+\\)|)(![0-9]|)__ *", s)
          178  +    m = re.match("^__(?P<borders_and_case>[[<]\\w[]>])(?P<option>/[a-zA-Z0-9]+|)(?P<ruleid>\\(\\w+\\)|)(?P<priority>![0-9]|)__ *", s)
   179    179       if m:
   180         -        cWordLimitLeft = m.group(1)[0]
   181         -        cCaseMode = m.group(1)[1]
   182         -        cWordLimitRight = m.group(1)[2]
   183         -        sOption = m.group(2)[1:]  if m.group(2)  else False
   184         -        if m.group(3):
   185         -            sRuleId =  m.group(3)[1:-1]
          180  +        cWordLimitLeft = m.group('borders_and_case')[0]
          181  +        cCaseMode = m.group('borders_and_case')[1]
          182  +        cWordLimitRight = m.group('borders_and_case')[2]
          183  +        sOption = m.group('option')[1:]  if m.group('option')  else False
          184  +        if m.group('ruleid'):
          185  +            sRuleId =  m.group('ruleid')[1:-1]
   186    186               if sRuleId in RULESET:
   187    187                   print("# Warning. Several rules have the same id: " + sRuleId)
   188    188               RULESET.add(sRuleId)
   189    189           nPriority = dOptPriority.get(sOption, 4)
   190         -        if m.group(4):
   191         -            nPriority = int(m.group(4)[1:])
          190  +        if m.group('priority'):
          191  +            nPriority = int(m.group('priority')[1:])
   192    192           s = s[m.end(0):]
   193    193       else:
   194    194           print("# Warning. No option defined at line: " + sLineId)
   195    195   
   196    196       #### REGEX TRIGGER
   197    197       i = s.find(" <<-")
   198    198       if i == -1: