northpost-parser 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- northpost_parser/__init__.py +23 -0
- northpost_parser/generated/CanadianAddressLexer.py +91 -0
- northpost_parser/generated/CanadianAddressParser.py +531 -0
- northpost_parser/generated/CanadianAddressVisitor.py +43 -0
- northpost_parser/generated/__init__.py +1 -0
- northpost_parser/models.py +158 -0
- northpost_parser/normalizer.py +107 -0
- northpost_parser/service.py +162 -0
- northpost_parser/visitor.py +566 -0
- northpost_parser-1.1.0.dist-info/METADATA +120 -0
- northpost_parser-1.1.0.dist-info/RECORD +13 -0
- northpost_parser-1.1.0.dist-info/WHEEL +4 -0
- northpost_parser-1.1.0.dist-info/licenses/LICENSE +200 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Canadian postal address parsing."""
|
|
2
|
+
|
|
3
|
+
from .models import (
|
|
4
|
+
AddressComponents,
|
|
5
|
+
AddressType,
|
|
6
|
+
NormalizationStrategy,
|
|
7
|
+
ParsingMode,
|
|
8
|
+
ParsingStrategy,
|
|
9
|
+
)
|
|
10
|
+
from .normalizer import AddressNormalizer
|
|
11
|
+
from .service import AddressParserService, BatchStatistics, ParsingResult
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"AddressComponents",
|
|
15
|
+
"AddressNormalizer",
|
|
16
|
+
"AddressParserService",
|
|
17
|
+
"AddressType",
|
|
18
|
+
"BatchStatistics",
|
|
19
|
+
"NormalizationStrategy",
|
|
20
|
+
"ParsingMode",
|
|
21
|
+
"ParsingResult",
|
|
22
|
+
"ParsingStrategy",
|
|
23
|
+
]
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Generated from CanadianAddress.g4 by ANTLR 4.13.2
|
|
2
|
+
from antlr4 import *
|
|
3
|
+
from io import StringIO
|
|
4
|
+
import sys
|
|
5
|
+
if sys.version_info[1] > 5:
|
|
6
|
+
from typing import TextIO
|
|
7
|
+
else:
|
|
8
|
+
from typing.io import TextIO
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def serializedATN():
|
|
12
|
+
return [
|
|
13
|
+
4,0,14,87,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,
|
|
14
|
+
6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,
|
|
15
|
+
7,13,2,14,7,14,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,4,1,40,8,1,11,1,12,
|
|
16
|
+
1,41,1,2,1,2,1,2,5,2,47,8,2,10,2,12,2,50,9,2,1,3,1,3,4,3,54,8,3,
|
|
17
|
+
11,3,12,3,55,1,4,1,4,1,5,1,5,1,6,1,6,1,7,1,7,1,8,1,8,1,9,1,9,1,10,
|
|
18
|
+
1,10,1,11,1,11,1,12,1,12,1,12,3,12,77,8,12,1,13,4,13,80,8,13,11,
|
|
19
|
+
13,12,13,81,1,14,1,14,1,14,1,14,0,0,15,1,1,3,2,5,3,7,4,9,0,11,5,
|
|
20
|
+
13,6,15,7,17,8,19,9,21,10,23,11,25,12,27,13,29,14,1,0,6,2,0,65,90,
|
|
21
|
+
97,122,1,0,48,57,4,0,39,39,45,46,48,57,8217,8217,3,0,65,90,97,122,
|
|
22
|
+
192,383,2,0,10,10,13,13,2,0,9,9,32,32,92,0,1,1,0,0,0,0,3,1,0,0,0,
|
|
23
|
+
0,5,1,0,0,0,0,7,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,
|
|
24
|
+
17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,
|
|
25
|
+
27,1,0,0,0,0,29,1,0,0,0,1,31,1,0,0,0,3,39,1,0,0,0,5,43,1,0,0,0,7,
|
|
26
|
+
53,1,0,0,0,9,57,1,0,0,0,11,59,1,0,0,0,13,61,1,0,0,0,15,63,1,0,0,
|
|
27
|
+
0,17,65,1,0,0,0,19,67,1,0,0,0,21,69,1,0,0,0,23,71,1,0,0,0,25,76,
|
|
28
|
+
1,0,0,0,27,79,1,0,0,0,29,83,1,0,0,0,31,32,7,0,0,0,32,33,7,1,0,0,
|
|
29
|
+
33,34,7,0,0,0,34,35,7,1,0,0,35,36,7,0,0,0,36,37,7,1,0,0,37,2,1,0,
|
|
30
|
+
0,0,38,40,7,1,0,0,39,38,1,0,0,0,40,41,1,0,0,0,41,39,1,0,0,0,41,42,
|
|
31
|
+
1,0,0,0,42,4,1,0,0,0,43,48,3,9,4,0,44,47,3,9,4,0,45,47,7,2,0,0,46,
|
|
32
|
+
44,1,0,0,0,46,45,1,0,0,0,47,50,1,0,0,0,48,46,1,0,0,0,48,49,1,0,0,
|
|
33
|
+
0,49,6,1,0,0,0,50,48,1,0,0,0,51,54,3,9,4,0,52,54,7,1,0,0,53,51,1,
|
|
34
|
+
0,0,0,53,52,1,0,0,0,54,55,1,0,0,0,55,53,1,0,0,0,55,56,1,0,0,0,56,
|
|
35
|
+
8,1,0,0,0,57,58,7,3,0,0,58,10,1,0,0,0,59,60,5,47,0,0,60,12,1,0,0,
|
|
36
|
+
0,61,62,5,45,0,0,62,14,1,0,0,0,63,64,5,46,0,0,64,16,1,0,0,0,65,66,
|
|
37
|
+
5,44,0,0,66,18,1,0,0,0,67,68,5,38,0,0,68,20,1,0,0,0,69,70,5,40,0,
|
|
38
|
+
0,70,22,1,0,0,0,71,72,5,41,0,0,72,24,1,0,0,0,73,74,5,13,0,0,74,77,
|
|
39
|
+
5,10,0,0,75,77,7,4,0,0,76,73,1,0,0,0,76,75,1,0,0,0,77,26,1,0,0,0,
|
|
40
|
+
78,80,7,5,0,0,79,78,1,0,0,0,80,81,1,0,0,0,81,79,1,0,0,0,81,82,1,
|
|
41
|
+
0,0,0,82,28,1,0,0,0,83,84,9,0,0,0,84,85,1,0,0,0,85,86,6,14,0,0,86,
|
|
42
|
+
30,1,0,0,0,8,0,41,46,48,53,55,76,81,1,6,0,0
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
class CanadianAddressLexer(Lexer):
|
|
46
|
+
|
|
47
|
+
atn = ATNDeserializer().deserialize(serializedATN())
|
|
48
|
+
|
|
49
|
+
decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]
|
|
50
|
+
|
|
51
|
+
POSTAL_CODE = 1
|
|
52
|
+
NUMBER = 2
|
|
53
|
+
WORD = 3
|
|
54
|
+
ALPHANUMERIC = 4
|
|
55
|
+
SLASH = 5
|
|
56
|
+
HYPHEN = 6
|
|
57
|
+
DOT = 7
|
|
58
|
+
COMMA = 8
|
|
59
|
+
AMPERSAND = 9
|
|
60
|
+
LPAREN = 10
|
|
61
|
+
RPAREN = 11
|
|
62
|
+
NL = 12
|
|
63
|
+
WS = 13
|
|
64
|
+
CATCHALL = 14
|
|
65
|
+
|
|
66
|
+
channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ]
|
|
67
|
+
|
|
68
|
+
modeNames = [ "DEFAULT_MODE" ]
|
|
69
|
+
|
|
70
|
+
literalNames = [ "<INVALID>",
|
|
71
|
+
"'/'", "'-'", "'.'", "','", "'&'", "'('", "')'" ]
|
|
72
|
+
|
|
73
|
+
symbolicNames = [ "<INVALID>",
|
|
74
|
+
"POSTAL_CODE", "NUMBER", "WORD", "ALPHANUMERIC", "SLASH", "HYPHEN",
|
|
75
|
+
"DOT", "COMMA", "AMPERSAND", "LPAREN", "RPAREN", "NL", "WS",
|
|
76
|
+
"CATCHALL" ]
|
|
77
|
+
|
|
78
|
+
ruleNames = [ "POSTAL_CODE", "NUMBER", "WORD", "ALPHANUMERIC", "LETTER",
|
|
79
|
+
"SLASH", "HYPHEN", "DOT", "COMMA", "AMPERSAND", "LPAREN",
|
|
80
|
+
"RPAREN", "NL", "WS", "CATCHALL" ]
|
|
81
|
+
|
|
82
|
+
grammarFileName = "CanadianAddress.g4"
|
|
83
|
+
|
|
84
|
+
def __init__(self, input=None, output:TextIO = sys.stdout):
|
|
85
|
+
super().__init__(input, output)
|
|
86
|
+
self.checkVersion("4.13.2")
|
|
87
|
+
self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache())
|
|
88
|
+
self._actions = None
|
|
89
|
+
self._predicates = None
|
|
90
|
+
|
|
91
|
+
|
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
# Generated from CanadianAddress.g4 by ANTLR 4.13.2
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
from antlr4 import *
|
|
4
|
+
from io import StringIO
|
|
5
|
+
import sys
|
|
6
|
+
if sys.version_info[1] > 5:
|
|
7
|
+
from typing import TextIO
|
|
8
|
+
else:
|
|
9
|
+
from typing.io import TextIO
|
|
10
|
+
|
|
11
|
+
def serializedATN():
|
|
12
|
+
return [
|
|
13
|
+
4,1,14,78,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,1,0,5,
|
|
14
|
+
0,14,8,0,10,0,12,0,17,9,0,1,0,1,0,5,0,21,8,0,10,0,12,0,24,9,0,1,
|
|
15
|
+
0,1,0,1,1,1,1,1,1,1,1,5,1,32,8,1,10,1,12,1,35,9,1,1,2,1,2,5,2,39,
|
|
16
|
+
8,2,10,2,12,2,42,9,2,1,2,5,2,45,8,2,10,2,12,2,48,9,2,1,3,5,3,51,
|
|
17
|
+
8,3,10,3,12,3,54,9,3,1,3,1,3,5,3,58,8,3,10,3,12,3,61,9,3,1,4,1,4,
|
|
18
|
+
5,4,65,8,4,10,4,12,4,68,9,4,1,4,5,4,71,8,4,10,4,12,4,74,9,4,1,5,
|
|
19
|
+
1,5,1,5,0,0,6,0,2,4,6,8,10,0,2,1,0,12,13,1,0,1,11,80,0,15,1,0,0,
|
|
20
|
+
0,2,27,1,0,0,0,4,36,1,0,0,0,6,52,1,0,0,0,8,62,1,0,0,0,10,75,1,0,
|
|
21
|
+
0,0,12,14,7,0,0,0,13,12,1,0,0,0,14,17,1,0,0,0,15,13,1,0,0,0,15,16,
|
|
22
|
+
1,0,0,0,16,18,1,0,0,0,17,15,1,0,0,0,18,22,3,2,1,0,19,21,7,0,0,0,
|
|
23
|
+
20,19,1,0,0,0,21,24,1,0,0,0,22,20,1,0,0,0,22,23,1,0,0,0,23,25,1,
|
|
24
|
+
0,0,0,24,22,1,0,0,0,25,26,5,0,0,1,26,1,1,0,0,0,27,33,3,6,3,0,28,
|
|
25
|
+
29,3,4,2,0,29,30,3,6,3,0,30,32,1,0,0,0,31,28,1,0,0,0,32,35,1,0,0,
|
|
26
|
+
0,33,31,1,0,0,0,33,34,1,0,0,0,34,3,1,0,0,0,35,33,1,0,0,0,36,46,5,
|
|
27
|
+
12,0,0,37,39,5,13,0,0,38,37,1,0,0,0,39,42,1,0,0,0,40,38,1,0,0,0,
|
|
28
|
+
40,41,1,0,0,0,41,43,1,0,0,0,42,40,1,0,0,0,43,45,5,12,0,0,44,40,1,
|
|
29
|
+
0,0,0,45,48,1,0,0,0,46,44,1,0,0,0,46,47,1,0,0,0,47,5,1,0,0,0,48,
|
|
30
|
+
46,1,0,0,0,49,51,5,13,0,0,50,49,1,0,0,0,51,54,1,0,0,0,52,50,1,0,
|
|
31
|
+
0,0,52,53,1,0,0,0,53,55,1,0,0,0,54,52,1,0,0,0,55,59,3,8,4,0,56,58,
|
|
32
|
+
5,13,0,0,57,56,1,0,0,0,58,61,1,0,0,0,59,57,1,0,0,0,59,60,1,0,0,0,
|
|
33
|
+
60,7,1,0,0,0,61,59,1,0,0,0,62,72,3,10,5,0,63,65,5,13,0,0,64,63,1,
|
|
34
|
+
0,0,0,65,68,1,0,0,0,66,64,1,0,0,0,66,67,1,0,0,0,67,69,1,0,0,0,68,
|
|
35
|
+
66,1,0,0,0,69,71,3,10,5,0,70,66,1,0,0,0,71,74,1,0,0,0,72,70,1,0,
|
|
36
|
+
0,0,72,73,1,0,0,0,73,9,1,0,0,0,74,72,1,0,0,0,75,76,7,1,0,0,76,11,
|
|
37
|
+
1,0,0,0,9,15,22,33,40,46,52,59,66,72
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
class CanadianAddressParser ( Parser ):
|
|
41
|
+
|
|
42
|
+
grammarFileName = "CanadianAddress.g4"
|
|
43
|
+
|
|
44
|
+
atn = ATNDeserializer().deserialize(serializedATN())
|
|
45
|
+
|
|
46
|
+
decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]
|
|
47
|
+
|
|
48
|
+
sharedContextCache = PredictionContextCache()
|
|
49
|
+
|
|
50
|
+
literalNames = [ "<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>",
|
|
51
|
+
"<INVALID>", "'/'", "'-'", "'.'", "','", "'&'", "'('",
|
|
52
|
+
"')'" ]
|
|
53
|
+
|
|
54
|
+
symbolicNames = [ "<INVALID>", "POSTAL_CODE", "NUMBER", "WORD", "ALPHANUMERIC",
|
|
55
|
+
"SLASH", "HYPHEN", "DOT", "COMMA", "AMPERSAND", "LPAREN",
|
|
56
|
+
"RPAREN", "NL", "WS", "CATCHALL" ]
|
|
57
|
+
|
|
58
|
+
RULE_address = 0
|
|
59
|
+
RULE_addressBody = 1
|
|
60
|
+
RULE_lineSep = 2
|
|
61
|
+
RULE_addressLine = 3
|
|
62
|
+
RULE_lineContent = 4
|
|
63
|
+
RULE_lineToken = 5
|
|
64
|
+
|
|
65
|
+
ruleNames = [ "address", "addressBody", "lineSep", "addressLine", "lineContent",
|
|
66
|
+
"lineToken" ]
|
|
67
|
+
|
|
68
|
+
EOF = Token.EOF
|
|
69
|
+
POSTAL_CODE=1
|
|
70
|
+
NUMBER=2
|
|
71
|
+
WORD=3
|
|
72
|
+
ALPHANUMERIC=4
|
|
73
|
+
SLASH=5
|
|
74
|
+
HYPHEN=6
|
|
75
|
+
DOT=7
|
|
76
|
+
COMMA=8
|
|
77
|
+
AMPERSAND=9
|
|
78
|
+
LPAREN=10
|
|
79
|
+
RPAREN=11
|
|
80
|
+
NL=12
|
|
81
|
+
WS=13
|
|
82
|
+
CATCHALL=14
|
|
83
|
+
|
|
84
|
+
def __init__(self, input:TokenStream, output:TextIO = sys.stdout):
|
|
85
|
+
super().__init__(input, output)
|
|
86
|
+
self.checkVersion("4.13.2")
|
|
87
|
+
self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache)
|
|
88
|
+
self._predicates = None
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class AddressContext(ParserRuleContext):
|
|
94
|
+
__slots__ = 'parser'
|
|
95
|
+
|
|
96
|
+
def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
|
|
97
|
+
super().__init__(parent, invokingState)
|
|
98
|
+
self.parser = parser
|
|
99
|
+
|
|
100
|
+
def addressBody(self):
|
|
101
|
+
return self.getTypedRuleContext(CanadianAddressParser.AddressBodyContext,0)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def EOF(self):
|
|
105
|
+
return self.getToken(CanadianAddressParser.EOF, 0)
|
|
106
|
+
|
|
107
|
+
def WS(self, i:int=None):
|
|
108
|
+
if i is None:
|
|
109
|
+
return self.getTokens(CanadianAddressParser.WS)
|
|
110
|
+
else:
|
|
111
|
+
return self.getToken(CanadianAddressParser.WS, i)
|
|
112
|
+
|
|
113
|
+
def NL(self, i:int=None):
|
|
114
|
+
if i is None:
|
|
115
|
+
return self.getTokens(CanadianAddressParser.NL)
|
|
116
|
+
else:
|
|
117
|
+
return self.getToken(CanadianAddressParser.NL, i)
|
|
118
|
+
|
|
119
|
+
def getRuleIndex(self):
|
|
120
|
+
return CanadianAddressParser.RULE_address
|
|
121
|
+
|
|
122
|
+
def accept(self, visitor:ParseTreeVisitor):
|
|
123
|
+
if hasattr( visitor, "visitAddress" ):
|
|
124
|
+
return visitor.visitAddress(self)
|
|
125
|
+
else:
|
|
126
|
+
return visitor.visitChildren(self)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def address(self):
|
|
132
|
+
|
|
133
|
+
localctx = CanadianAddressParser.AddressContext(self, self._ctx, self.state)
|
|
134
|
+
self.enterRule(localctx, 0, self.RULE_address)
|
|
135
|
+
self._la = 0 # Token type
|
|
136
|
+
try:
|
|
137
|
+
self.enterOuterAlt(localctx, 1)
|
|
138
|
+
self.state = 15
|
|
139
|
+
self._errHandler.sync(self)
|
|
140
|
+
_alt = self._interp.adaptivePredict(self._input,0,self._ctx)
|
|
141
|
+
while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
|
|
142
|
+
if _alt==1:
|
|
143
|
+
self.state = 12
|
|
144
|
+
_la = self._input.LA(1)
|
|
145
|
+
if not(_la==12 or _la==13):
|
|
146
|
+
self._errHandler.recoverInline(self)
|
|
147
|
+
else:
|
|
148
|
+
self._errHandler.reportMatch(self)
|
|
149
|
+
self.consume()
|
|
150
|
+
self.state = 17
|
|
151
|
+
self._errHandler.sync(self)
|
|
152
|
+
_alt = self._interp.adaptivePredict(self._input,0,self._ctx)
|
|
153
|
+
|
|
154
|
+
self.state = 18
|
|
155
|
+
self.addressBody()
|
|
156
|
+
self.state = 22
|
|
157
|
+
self._errHandler.sync(self)
|
|
158
|
+
_la = self._input.LA(1)
|
|
159
|
+
while _la==12 or _la==13:
|
|
160
|
+
self.state = 19
|
|
161
|
+
_la = self._input.LA(1)
|
|
162
|
+
if not(_la==12 or _la==13):
|
|
163
|
+
self._errHandler.recoverInline(self)
|
|
164
|
+
else:
|
|
165
|
+
self._errHandler.reportMatch(self)
|
|
166
|
+
self.consume()
|
|
167
|
+
self.state = 24
|
|
168
|
+
self._errHandler.sync(self)
|
|
169
|
+
_la = self._input.LA(1)
|
|
170
|
+
|
|
171
|
+
self.state = 25
|
|
172
|
+
self.match(CanadianAddressParser.EOF)
|
|
173
|
+
except RecognitionException as re:
|
|
174
|
+
localctx.exception = re
|
|
175
|
+
self._errHandler.reportError(self, re)
|
|
176
|
+
self._errHandler.recover(self, re)
|
|
177
|
+
finally:
|
|
178
|
+
self.exitRule()
|
|
179
|
+
return localctx
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
class AddressBodyContext(ParserRuleContext):
|
|
183
|
+
__slots__ = 'parser'
|
|
184
|
+
|
|
185
|
+
def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
|
|
186
|
+
super().__init__(parent, invokingState)
|
|
187
|
+
self.parser = parser
|
|
188
|
+
|
|
189
|
+
def addressLine(self, i:int=None):
|
|
190
|
+
if i is None:
|
|
191
|
+
return self.getTypedRuleContexts(CanadianAddressParser.AddressLineContext)
|
|
192
|
+
else:
|
|
193
|
+
return self.getTypedRuleContext(CanadianAddressParser.AddressLineContext,i)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def lineSep(self, i:int=None):
|
|
197
|
+
if i is None:
|
|
198
|
+
return self.getTypedRuleContexts(CanadianAddressParser.LineSepContext)
|
|
199
|
+
else:
|
|
200
|
+
return self.getTypedRuleContext(CanadianAddressParser.LineSepContext,i)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def getRuleIndex(self):
|
|
204
|
+
return CanadianAddressParser.RULE_addressBody
|
|
205
|
+
|
|
206
|
+
def accept(self, visitor:ParseTreeVisitor):
|
|
207
|
+
if hasattr( visitor, "visitAddressBody" ):
|
|
208
|
+
return visitor.visitAddressBody(self)
|
|
209
|
+
else:
|
|
210
|
+
return visitor.visitChildren(self)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def addressBody(self):
|
|
216
|
+
|
|
217
|
+
localctx = CanadianAddressParser.AddressBodyContext(self, self._ctx, self.state)
|
|
218
|
+
self.enterRule(localctx, 2, self.RULE_addressBody)
|
|
219
|
+
try:
|
|
220
|
+
self.enterOuterAlt(localctx, 1)
|
|
221
|
+
self.state = 27
|
|
222
|
+
self.addressLine()
|
|
223
|
+
self.state = 33
|
|
224
|
+
self._errHandler.sync(self)
|
|
225
|
+
_alt = self._interp.adaptivePredict(self._input,2,self._ctx)
|
|
226
|
+
while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
|
|
227
|
+
if _alt==1:
|
|
228
|
+
self.state = 28
|
|
229
|
+
self.lineSep()
|
|
230
|
+
self.state = 29
|
|
231
|
+
self.addressLine()
|
|
232
|
+
self.state = 35
|
|
233
|
+
self._errHandler.sync(self)
|
|
234
|
+
_alt = self._interp.adaptivePredict(self._input,2,self._ctx)
|
|
235
|
+
|
|
236
|
+
except RecognitionException as re:
|
|
237
|
+
localctx.exception = re
|
|
238
|
+
self._errHandler.reportError(self, re)
|
|
239
|
+
self._errHandler.recover(self, re)
|
|
240
|
+
finally:
|
|
241
|
+
self.exitRule()
|
|
242
|
+
return localctx
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
class LineSepContext(ParserRuleContext):
|
|
246
|
+
__slots__ = 'parser'
|
|
247
|
+
|
|
248
|
+
def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
|
|
249
|
+
super().__init__(parent, invokingState)
|
|
250
|
+
self.parser = parser
|
|
251
|
+
|
|
252
|
+
def NL(self, i:int=None):
|
|
253
|
+
if i is None:
|
|
254
|
+
return self.getTokens(CanadianAddressParser.NL)
|
|
255
|
+
else:
|
|
256
|
+
return self.getToken(CanadianAddressParser.NL, i)
|
|
257
|
+
|
|
258
|
+
def WS(self, i:int=None):
|
|
259
|
+
if i is None:
|
|
260
|
+
return self.getTokens(CanadianAddressParser.WS)
|
|
261
|
+
else:
|
|
262
|
+
return self.getToken(CanadianAddressParser.WS, i)
|
|
263
|
+
|
|
264
|
+
def getRuleIndex(self):
|
|
265
|
+
return CanadianAddressParser.RULE_lineSep
|
|
266
|
+
|
|
267
|
+
def accept(self, visitor:ParseTreeVisitor):
|
|
268
|
+
if hasattr( visitor, "visitLineSep" ):
|
|
269
|
+
return visitor.visitLineSep(self)
|
|
270
|
+
else:
|
|
271
|
+
return visitor.visitChildren(self)
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def lineSep(self):
|
|
277
|
+
|
|
278
|
+
localctx = CanadianAddressParser.LineSepContext(self, self._ctx, self.state)
|
|
279
|
+
self.enterRule(localctx, 4, self.RULE_lineSep)
|
|
280
|
+
self._la = 0 # Token type
|
|
281
|
+
try:
|
|
282
|
+
self.enterOuterAlt(localctx, 1)
|
|
283
|
+
self.state = 36
|
|
284
|
+
self.match(CanadianAddressParser.NL)
|
|
285
|
+
self.state = 46
|
|
286
|
+
self._errHandler.sync(self)
|
|
287
|
+
_alt = self._interp.adaptivePredict(self._input,4,self._ctx)
|
|
288
|
+
while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
|
|
289
|
+
if _alt==1:
|
|
290
|
+
self.state = 40
|
|
291
|
+
self._errHandler.sync(self)
|
|
292
|
+
_la = self._input.LA(1)
|
|
293
|
+
while _la==13:
|
|
294
|
+
self.state = 37
|
|
295
|
+
self.match(CanadianAddressParser.WS)
|
|
296
|
+
self.state = 42
|
|
297
|
+
self._errHandler.sync(self)
|
|
298
|
+
_la = self._input.LA(1)
|
|
299
|
+
|
|
300
|
+
self.state = 43
|
|
301
|
+
self.match(CanadianAddressParser.NL)
|
|
302
|
+
self.state = 48
|
|
303
|
+
self._errHandler.sync(self)
|
|
304
|
+
_alt = self._interp.adaptivePredict(self._input,4,self._ctx)
|
|
305
|
+
|
|
306
|
+
except RecognitionException as re:
|
|
307
|
+
localctx.exception = re
|
|
308
|
+
self._errHandler.reportError(self, re)
|
|
309
|
+
self._errHandler.recover(self, re)
|
|
310
|
+
finally:
|
|
311
|
+
self.exitRule()
|
|
312
|
+
return localctx
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
class AddressLineContext(ParserRuleContext):
|
|
316
|
+
__slots__ = 'parser'
|
|
317
|
+
|
|
318
|
+
def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
|
|
319
|
+
super().__init__(parent, invokingState)
|
|
320
|
+
self.parser = parser
|
|
321
|
+
|
|
322
|
+
def lineContent(self):
|
|
323
|
+
return self.getTypedRuleContext(CanadianAddressParser.LineContentContext,0)
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def WS(self, i:int=None):
|
|
327
|
+
if i is None:
|
|
328
|
+
return self.getTokens(CanadianAddressParser.WS)
|
|
329
|
+
else:
|
|
330
|
+
return self.getToken(CanadianAddressParser.WS, i)
|
|
331
|
+
|
|
332
|
+
def getRuleIndex(self):
|
|
333
|
+
return CanadianAddressParser.RULE_addressLine
|
|
334
|
+
|
|
335
|
+
def accept(self, visitor:ParseTreeVisitor):
|
|
336
|
+
if hasattr( visitor, "visitAddressLine" ):
|
|
337
|
+
return visitor.visitAddressLine(self)
|
|
338
|
+
else:
|
|
339
|
+
return visitor.visitChildren(self)
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def addressLine(self):
|
|
345
|
+
|
|
346
|
+
localctx = CanadianAddressParser.AddressLineContext(self, self._ctx, self.state)
|
|
347
|
+
self.enterRule(localctx, 6, self.RULE_addressLine)
|
|
348
|
+
self._la = 0 # Token type
|
|
349
|
+
try:
|
|
350
|
+
self.enterOuterAlt(localctx, 1)
|
|
351
|
+
self.state = 52
|
|
352
|
+
self._errHandler.sync(self)
|
|
353
|
+
_la = self._input.LA(1)
|
|
354
|
+
while _la==13:
|
|
355
|
+
self.state = 49
|
|
356
|
+
self.match(CanadianAddressParser.WS)
|
|
357
|
+
self.state = 54
|
|
358
|
+
self._errHandler.sync(self)
|
|
359
|
+
_la = self._input.LA(1)
|
|
360
|
+
|
|
361
|
+
self.state = 55
|
|
362
|
+
self.lineContent()
|
|
363
|
+
self.state = 59
|
|
364
|
+
self._errHandler.sync(self)
|
|
365
|
+
_alt = self._interp.adaptivePredict(self._input,6,self._ctx)
|
|
366
|
+
while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
|
|
367
|
+
if _alt==1:
|
|
368
|
+
self.state = 56
|
|
369
|
+
self.match(CanadianAddressParser.WS)
|
|
370
|
+
self.state = 61
|
|
371
|
+
self._errHandler.sync(self)
|
|
372
|
+
_alt = self._interp.adaptivePredict(self._input,6,self._ctx)
|
|
373
|
+
|
|
374
|
+
except RecognitionException as re:
|
|
375
|
+
localctx.exception = re
|
|
376
|
+
self._errHandler.reportError(self, re)
|
|
377
|
+
self._errHandler.recover(self, re)
|
|
378
|
+
finally:
|
|
379
|
+
self.exitRule()
|
|
380
|
+
return localctx
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
class LineContentContext(ParserRuleContext):
|
|
384
|
+
__slots__ = 'parser'
|
|
385
|
+
|
|
386
|
+
def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
|
|
387
|
+
super().__init__(parent, invokingState)
|
|
388
|
+
self.parser = parser
|
|
389
|
+
|
|
390
|
+
def lineToken(self, i:int=None):
|
|
391
|
+
if i is None:
|
|
392
|
+
return self.getTypedRuleContexts(CanadianAddressParser.LineTokenContext)
|
|
393
|
+
else:
|
|
394
|
+
return self.getTypedRuleContext(CanadianAddressParser.LineTokenContext,i)
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def WS(self, i:int=None):
|
|
398
|
+
if i is None:
|
|
399
|
+
return self.getTokens(CanadianAddressParser.WS)
|
|
400
|
+
else:
|
|
401
|
+
return self.getToken(CanadianAddressParser.WS, i)
|
|
402
|
+
|
|
403
|
+
def getRuleIndex(self):
|
|
404
|
+
return CanadianAddressParser.RULE_lineContent
|
|
405
|
+
|
|
406
|
+
def accept(self, visitor:ParseTreeVisitor):
|
|
407
|
+
if hasattr( visitor, "visitLineContent" ):
|
|
408
|
+
return visitor.visitLineContent(self)
|
|
409
|
+
else:
|
|
410
|
+
return visitor.visitChildren(self)
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
def lineContent(self):
|
|
416
|
+
|
|
417
|
+
localctx = CanadianAddressParser.LineContentContext(self, self._ctx, self.state)
|
|
418
|
+
self.enterRule(localctx, 8, self.RULE_lineContent)
|
|
419
|
+
self._la = 0 # Token type
|
|
420
|
+
try:
|
|
421
|
+
self.enterOuterAlt(localctx, 1)
|
|
422
|
+
self.state = 62
|
|
423
|
+
self.lineToken()
|
|
424
|
+
self.state = 72
|
|
425
|
+
self._errHandler.sync(self)
|
|
426
|
+
_alt = self._interp.adaptivePredict(self._input,8,self._ctx)
|
|
427
|
+
while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
|
|
428
|
+
if _alt==1:
|
|
429
|
+
self.state = 66
|
|
430
|
+
self._errHandler.sync(self)
|
|
431
|
+
_la = self._input.LA(1)
|
|
432
|
+
while _la==13:
|
|
433
|
+
self.state = 63
|
|
434
|
+
self.match(CanadianAddressParser.WS)
|
|
435
|
+
self.state = 68
|
|
436
|
+
self._errHandler.sync(self)
|
|
437
|
+
_la = self._input.LA(1)
|
|
438
|
+
|
|
439
|
+
self.state = 69
|
|
440
|
+
self.lineToken()
|
|
441
|
+
self.state = 74
|
|
442
|
+
self._errHandler.sync(self)
|
|
443
|
+
_alt = self._interp.adaptivePredict(self._input,8,self._ctx)
|
|
444
|
+
|
|
445
|
+
except RecognitionException as re:
|
|
446
|
+
localctx.exception = re
|
|
447
|
+
self._errHandler.reportError(self, re)
|
|
448
|
+
self._errHandler.recover(self, re)
|
|
449
|
+
finally:
|
|
450
|
+
self.exitRule()
|
|
451
|
+
return localctx
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
class LineTokenContext(ParserRuleContext):
|
|
455
|
+
__slots__ = 'parser'
|
|
456
|
+
|
|
457
|
+
def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
|
|
458
|
+
super().__init__(parent, invokingState)
|
|
459
|
+
self.parser = parser
|
|
460
|
+
|
|
461
|
+
def WORD(self):
|
|
462
|
+
return self.getToken(CanadianAddressParser.WORD, 0)
|
|
463
|
+
|
|
464
|
+
def NUMBER(self):
|
|
465
|
+
return self.getToken(CanadianAddressParser.NUMBER, 0)
|
|
466
|
+
|
|
467
|
+
def POSTAL_CODE(self):
|
|
468
|
+
return self.getToken(CanadianAddressParser.POSTAL_CODE, 0)
|
|
469
|
+
|
|
470
|
+
def ALPHANUMERIC(self):
|
|
471
|
+
return self.getToken(CanadianAddressParser.ALPHANUMERIC, 0)
|
|
472
|
+
|
|
473
|
+
def HYPHEN(self):
|
|
474
|
+
return self.getToken(CanadianAddressParser.HYPHEN, 0)
|
|
475
|
+
|
|
476
|
+
def SLASH(self):
|
|
477
|
+
return self.getToken(CanadianAddressParser.SLASH, 0)
|
|
478
|
+
|
|
479
|
+
def DOT(self):
|
|
480
|
+
return self.getToken(CanadianAddressParser.DOT, 0)
|
|
481
|
+
|
|
482
|
+
def COMMA(self):
|
|
483
|
+
return self.getToken(CanadianAddressParser.COMMA, 0)
|
|
484
|
+
|
|
485
|
+
def AMPERSAND(self):
|
|
486
|
+
return self.getToken(CanadianAddressParser.AMPERSAND, 0)
|
|
487
|
+
|
|
488
|
+
def LPAREN(self):
|
|
489
|
+
return self.getToken(CanadianAddressParser.LPAREN, 0)
|
|
490
|
+
|
|
491
|
+
def RPAREN(self):
|
|
492
|
+
return self.getToken(CanadianAddressParser.RPAREN, 0)
|
|
493
|
+
|
|
494
|
+
def getRuleIndex(self):
|
|
495
|
+
return CanadianAddressParser.RULE_lineToken
|
|
496
|
+
|
|
497
|
+
def accept(self, visitor:ParseTreeVisitor):
|
|
498
|
+
if hasattr( visitor, "visitLineToken" ):
|
|
499
|
+
return visitor.visitLineToken(self)
|
|
500
|
+
else:
|
|
501
|
+
return visitor.visitChildren(self)
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
def lineToken(self):
|
|
507
|
+
|
|
508
|
+
localctx = CanadianAddressParser.LineTokenContext(self, self._ctx, self.state)
|
|
509
|
+
self.enterRule(localctx, 10, self.RULE_lineToken)
|
|
510
|
+
self._la = 0 # Token type
|
|
511
|
+
try:
|
|
512
|
+
self.enterOuterAlt(localctx, 1)
|
|
513
|
+
self.state = 75
|
|
514
|
+
_la = self._input.LA(1)
|
|
515
|
+
if not((((_la) & ~0x3f) == 0 and ((1 << _la) & 4094) != 0)):
|
|
516
|
+
self._errHandler.recoverInline(self)
|
|
517
|
+
else:
|
|
518
|
+
self._errHandler.reportMatch(self)
|
|
519
|
+
self.consume()
|
|
520
|
+
except RecognitionException as re:
|
|
521
|
+
localctx.exception = re
|
|
522
|
+
self._errHandler.reportError(self, re)
|
|
523
|
+
self._errHandler.recover(self, re)
|
|
524
|
+
finally:
|
|
525
|
+
self.exitRule()
|
|
526
|
+
return localctx
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Generated from CanadianAddress.g4 by ANTLR 4.13.2
|
|
2
|
+
from antlr4 import *
|
|
3
|
+
if "." in __name__:
|
|
4
|
+
from .CanadianAddressParser import CanadianAddressParser
|
|
5
|
+
else:
|
|
6
|
+
from CanadianAddressParser import CanadianAddressParser
|
|
7
|
+
|
|
8
|
+
# This class defines a complete generic visitor for a parse tree produced by CanadianAddressParser.
|
|
9
|
+
|
|
10
|
+
class CanadianAddressVisitor(ParseTreeVisitor):
|
|
11
|
+
|
|
12
|
+
# Visit a parse tree produced by CanadianAddressParser#address.
|
|
13
|
+
def visitAddress(self, ctx:CanadianAddressParser.AddressContext):
|
|
14
|
+
return self.visitChildren(ctx)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Visit a parse tree produced by CanadianAddressParser#addressBody.
|
|
18
|
+
def visitAddressBody(self, ctx:CanadianAddressParser.AddressBodyContext):
|
|
19
|
+
return self.visitChildren(ctx)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# Visit a parse tree produced by CanadianAddressParser#lineSep.
|
|
23
|
+
def visitLineSep(self, ctx:CanadianAddressParser.LineSepContext):
|
|
24
|
+
return self.visitChildren(ctx)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# Visit a parse tree produced by CanadianAddressParser#addressLine.
|
|
28
|
+
def visitAddressLine(self, ctx:CanadianAddressParser.AddressLineContext):
|
|
29
|
+
return self.visitChildren(ctx)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# Visit a parse tree produced by CanadianAddressParser#lineContent.
|
|
33
|
+
def visitLineContent(self, ctx:CanadianAddressParser.LineContentContext):
|
|
34
|
+
return self.visitChildren(ctx)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# Visit a parse tree produced by CanadianAddressParser#lineToken.
|
|
38
|
+
def visitLineToken(self, ctx:CanadianAddressParser.LineTokenContext):
|
|
39
|
+
return self.visitChildren(ctx)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
del CanadianAddressParser
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""ANTLR4-generated Python lexer, parser, and visitor."""
|