Skip to content

Commit

Permalink
Merge pull request #2356 from laws-africa/schedule-refs
Browse files Browse the repository at this point in the history
correctly look up plural schedules
  • Loading branch information
longhotsummer authored Feb 11, 2025
2 parents 6b3e32c + 08f0399 commit 8840f5c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions indigo/analysis/refs/provision_refs.peg
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ grammar ProvisionRefs
`sous-reglements` / `sous-reglement` /
`sous-sections` / `sous-section`

# changes or additions to these must also be made in attachment_num_ref in provisions.py
schedule_eng <- `schedules` / `schedule`
schedule_afr <- `bylae` / `bylaag`
schedule_fra <- `annexes` / `annexe`

the_schedule_eng <- `the schedule`
the_schedule_afr <- `die bylaag`
the_schedule_fra <- `l'annexe`
Expand Down
14 changes: 12 additions & 2 deletions indigo/analysis/refs/provisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,27 @@ def root(self, input, start, end, elements):
return ParseResult(refs, target, elements[3].offset)

def attachment_num_ref(self, input, start, end, elements):
headings = {
"schedules": "Schedule",
"schedule": "Schedule",
"bylae": "Bylaag",
"bylaag": "Bylaag",
"annexe": "Annexe",
"annexes": "Annexe",
}

# extend the ref to cover the full thing, not just the number
ref = elements[2]
refs = [MainProvisionRef("attachment", ref)]
# "2" -> "Schedule 2"
heading = headings[elements[0].text.lower()]
ref.start_pos = start
ref.text = input[start:ref.end_pos]
ref.text = f'{heading} {ref.text}'

for el in elements[3].elements or []:
ref = MainProvisionRef("attachment", el.main_num)
# "2" -> "Schedule 2"
ref.ref.text = elements[0].text + elements[1].text + ref.ref.text
ref.ref.text = f'{heading} {ref.ref.text}'
ref.ref.separator = el.elements[0]
refs.append(ref)

Expand Down
11 changes: 9 additions & 2 deletions indigo/tests/test_provision_refs_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def test_schedules_num(self):
], result.references)
self.assertIsNone(result.target)

result = parse_provision_refs("Schedule 2a.")
result = parse_provision_refs("schedule 2a.")
self.assertEqual([
MainProvisionRef(
"attachment",
Expand All @@ -369,13 +369,20 @@ def test_schedules_num(self):
self.assertIsNone(result.target)

def test_schedules_num_range(self):
result = parse_provision_refs("Schedule 2 to 30")
result = parse_provision_refs("schedule 2 to 30")
self.assertEqual([
MainProvisionRef('attachment', ProvisionRef('Schedule 2', 0, 10)),
MainProvisionRef('attachment', ProvisionRef('Schedule 30', 14, 16, separator='range')),
], result.references)
self.assertIsNone(result.target)

result = parse_provision_refs("Schedules 2 and 30")
self.assertEqual([
MainProvisionRef('attachment', ProvisionRef('Schedule 2', 0, 11)),
MainProvisionRef('attachment', ProvisionRef('Schedule 30', 16, 18, separator='and_or')),
], result.references)
self.assertIsNone(result.target)

def test_schedules_the_eng(self):
result = parse_provision_refs("the Schedule")
self.assertEqual([
Expand Down

0 comments on commit 8840f5c

Please sign in to comment.