edifact_parser 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/edifact_parser.rb +0 -0
- data/lib/edifact_parser/handler.rb +0 -0
- data/lib/edifact_parser/parser.rb +37 -34
- data/lib/edifact_parser/parser.tab.rb +0 -0
- data/lib/edifact_parser/tokenizer.rb +32 -3
- metadata +2 -2
data/lib/edifact_parser.rb
CHANGED
File without changes
|
File without changes
|
@@ -30,38 +30,38 @@ module EdifactParser
|
|
30
30
|
##### State transition tables begin ###
|
31
31
|
|
32
32
|
racc_action_table = [
|
33
|
-
7,
|
34
|
-
|
33
|
+
7, 28, 27, 4, 20, 18, 19, 20, 18, 19,
|
34
|
+
28, 27, 7, 7, 7, 8, 21 ]
|
35
35
|
|
36
36
|
racc_action_check = [
|
37
|
-
0,
|
38
|
-
|
37
|
+
0, 16, 16, 0, 11, 11, 11, 6, 6, 6,
|
38
|
+
17, 17, 3, 10, 2, 1, 8 ]
|
39
39
|
|
40
40
|
racc_action_pointer = [
|
41
|
-
-2,
|
42
|
-
|
43
|
-
nil, nil, nil, nil, nil, nil, nil, nil, nil ]
|
41
|
+
-2, 15, 12, 10, nil, nil, 1, nil, 16, nil,
|
42
|
+
11, -2, nil, nil, nil, nil, -2, 7, nil, nil,
|
43
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil ]
|
44
44
|
|
45
45
|
racc_action_default = [
|
46
|
-
-
|
47
|
-
-2, -
|
48
|
-
|
46
|
+
-24, -24, -1, -24, -3, -5, -24, -14, -24, -4,
|
47
|
+
-2, -24, -7, -9, -10, -11, -12, -13, -21, -22,
|
48
|
+
-23, 30, -6, -8, -15, -17, -18, -19, -20, -16 ]
|
49
49
|
|
50
50
|
racc_goto_table = [
|
51
|
-
9, 12,
|
52
|
-
3, 1 ]
|
51
|
+
9, 12, 13, 24, 29, 11, 22, 23, 9, 2,
|
52
|
+
3, 1, 10 ]
|
53
53
|
|
54
54
|
racc_goto_check = [
|
55
|
-
4,
|
56
|
-
3, 1 ]
|
55
|
+
4, 7, 8, 13, 13, 6, 7, 8, 4, 2,
|
56
|
+
3, 1, 2 ]
|
57
57
|
|
58
58
|
racc_goto_pointer = [
|
59
|
-
nil, 11,
|
60
|
-
nil, nil, nil, -
|
59
|
+
nil, 11, 9, 10, -2, nil, -1, -5, -4, nil,
|
60
|
+
nil, nil, nil, -13, nil, nil ]
|
61
61
|
|
62
62
|
racc_goto_default = [
|
63
|
-
nil, nil, nil, nil, 5, 6, nil, nil, nil,
|
64
|
-
|
63
|
+
nil, nil, nil, nil, 5, 6, nil, nil, nil, 14,
|
64
|
+
15, 16, 17, nil, 25, 26 ]
|
65
65
|
|
66
66
|
racc_reduce_table = [
|
67
67
|
0, 0, :racc_error,
|
@@ -71,26 +71,27 @@ racc_reduce_table = [
|
|
71
71
|
2, 11, :_reduce_none,
|
72
72
|
1, 11, :_reduce_none,
|
73
73
|
3, 13, :_reduce_none,
|
74
|
+
2, 13, :_reduce_none,
|
74
75
|
2, 15, :_reduce_none,
|
75
76
|
1, 15, :_reduce_none,
|
76
77
|
1, 17, :_reduce_none,
|
77
78
|
1, 17, :_reduce_none,
|
78
79
|
1, 17, :_reduce_none,
|
79
80
|
1, 17, :_reduce_none,
|
80
|
-
1, 14, :
|
81
|
+
1, 14, :_reduce_14,
|
81
82
|
2, 18, :_reduce_none,
|
82
83
|
2, 19, :_reduce_none,
|
83
84
|
1, 22, :_reduce_none,
|
84
85
|
1, 22, :_reduce_none,
|
85
|
-
1, 24, :
|
86
|
-
1, 23, :
|
87
|
-
1, 20, :
|
88
|
-
1, 21, :
|
89
|
-
1, 16, :
|
86
|
+
1, 24, :_reduce_19,
|
87
|
+
1, 23, :_reduce_20,
|
88
|
+
1, 20, :_reduce_21,
|
89
|
+
1, 21, :_reduce_22,
|
90
|
+
1, 16, :_reduce_23 ]
|
90
91
|
|
91
|
-
racc_reduce_n =
|
92
|
+
racc_reduce_n = 24
|
92
93
|
|
93
|
-
racc_shift_n =
|
94
|
+
racc_shift_n = 30
|
94
95
|
|
95
96
|
racc_token_table = {
|
96
97
|
false => 0,
|
@@ -180,40 +181,42 @@ Racc_debug_parser = true
|
|
180
181
|
|
181
182
|
# reduce 12 omitted
|
182
183
|
|
183
|
-
|
184
|
+
# reduce 13 omitted
|
185
|
+
|
186
|
+
def _reduce_14(val, _values, result)
|
184
187
|
@handler.start_segment; @handler.qualifier val[0]
|
185
188
|
result
|
186
189
|
end
|
187
190
|
|
188
|
-
# reduce 14 omitted
|
189
|
-
|
190
191
|
# reduce 15 omitted
|
191
192
|
|
192
193
|
# reduce 16 omitted
|
193
194
|
|
194
195
|
# reduce 17 omitted
|
195
196
|
|
196
|
-
|
197
|
+
# reduce 18 omitted
|
198
|
+
|
199
|
+
def _reduce_19(val, _values, result)
|
197
200
|
@handler.scalar val[0]
|
198
201
|
result
|
199
202
|
end
|
200
203
|
|
201
|
-
def
|
204
|
+
def _reduce_20(val, _values, result)
|
202
205
|
@handler.scalar val[0].gsub("?", "")
|
203
206
|
result
|
204
207
|
end
|
205
208
|
|
206
|
-
def
|
209
|
+
def _reduce_21(val, _values, result)
|
207
210
|
@handler.end_element; @handler.start_element
|
208
211
|
result
|
209
212
|
end
|
210
213
|
|
211
|
-
def
|
214
|
+
def _reduce_22(val, _values, result)
|
212
215
|
@handler.colon
|
213
216
|
result
|
214
217
|
end
|
215
218
|
|
216
|
-
def
|
219
|
+
def _reduce_23(val, _values, result)
|
217
220
|
@handler.end_element; @handler.end_segment
|
218
221
|
result
|
219
222
|
end
|
File without changes
|
@@ -2,8 +2,23 @@ require 'strscan'
|
|
2
2
|
|
3
3
|
module EdifactParser
|
4
4
|
class Tokenizer
|
5
|
+
QUALIFIERS = [
|
6
|
+
'UNB', 'UNH', 'UNZ', 'UNT', 'UNS', 'IFI', 'IFT', 'ODI', 'TVL', 'APD',
|
7
|
+
'ADR', 'AGR', 'AJT', 'ALC', 'ALI', 'APP', 'APR', 'ARD', 'ARR', 'ASI', 'ATT', 'AUT',
|
8
|
+
'BAS', 'BGM', 'BII', 'BUS', 'CAV', 'CCD', 'CCI', 'CDI', 'CDS', 'CDV', 'CED', 'CIN',
|
9
|
+
'CLA', 'CLI', 'CMP', 'CNI', 'CNT', 'COD', 'COM', 'COT', 'CPI', 'CPS', 'CPT', 'CST',
|
10
|
+
'CTA', 'CUX', 'DAM', 'DFN', 'DGS', 'DII', 'DIM', 'DLI', 'DLM', 'DMS', 'DOC', 'DRD',
|
11
|
+
'DSG', 'DSI', 'DTM', 'EDT', 'EFI', 'ELM', 'ELU', 'ELV', 'EMP', 'EQA', 'EQD', 'EQN',
|
12
|
+
'ERC', 'ERP', 'EVE', 'FCA', 'FII', 'FNS', 'FNT', 'FOR', 'FSQ', 'FTX', 'GDS', 'GEI',
|
13
|
+
'GID', 'GIN', 'GIR', 'GOR', 'GRU', 'HAN', 'HYN', 'ICD', 'IDE', 'IFD', 'IHC', 'IMD',
|
14
|
+
'IND', 'INP', 'INV', 'IRQ', 'LAN', 'LIN', 'LOC', 'MEA', 'MEM', 'MKS', 'MOA', 'MSG',
|
15
|
+
'MTD', 'NAD', 'NAT', 'PAC', 'PAI', 'PAS', 'PCC', 'PCD', 'PCI', 'PDI', 'PER', 'PGI',
|
16
|
+
'PIA', 'PNA', 'POC', 'PRC', 'PRI', 'PRV', 'PSD', 'PTY', 'PYT', 'QRS', 'QTY', 'QUA',
|
17
|
+
'QVR', 'RCS', 'REL', 'RFF', 'RJL', 'RNG', 'ROD', 'RSL', 'RTE', 'SAL', 'SCC', 'SCD',
|
18
|
+
'SEG', 'SEL', 'SEQ', 'SFI', 'SGP', 'SGU', 'SPR', 'SPS', 'STA', 'STC', 'STG', 'STS',
|
19
|
+
'TAX', 'TCC', 'TDT', 'TEM', 'TMD', 'TMP', 'TOD', 'TPL', 'TRU', 'TSR', 'VLI' ]
|
20
|
+
|
5
21
|
OPTIONAL_BEGIN = /^UNA:\+\.\?\s'/
|
6
|
-
QUALIFIER = /(^|(?<='))(UNB|UNH|BGM|DTM|PAI|ALI|IMD|FTX|LOC|GIS|DGS|GIR|RFF|MEA|QTY|MOA|RTE|NAD|DOC|CTA|COM|TAX|PCD|CUX|TDT|TSR|PII|TOD|PAC|EQD|SEL|ALC|RNG|INP|LIN|PRI|UNS|UNT|UNZ|CNT)/
|
7
22
|
STRING = /[A-Za-z0-9\s\.]*(\?')*[A-Za-z0-9\s\.]*(\?\+)*[A-Za-z0-9\s\.]*(\?:)*[A-Za-z0-9\s\.]*/
|
8
23
|
SPACE = /\s+/
|
9
24
|
NUMBER = /[0-9]+(?=[\+:'])/
|
@@ -14,6 +29,7 @@ module EdifactParser
|
|
14
29
|
|
15
30
|
def initialize(io)
|
16
31
|
@ss = StringScanner.new io.read
|
32
|
+
@qualifiers = qualifier_regex
|
17
33
|
end
|
18
34
|
|
19
35
|
def next_token
|
@@ -27,7 +43,7 @@ module EdifactParser
|
|
27
43
|
|
28
44
|
case
|
29
45
|
when text = @ss.scan(OPTIONAL_BEGIN) then [:OPTIONAL_BEGIN, text]
|
30
|
-
when text = @ss.scan(
|
46
|
+
when text = @ss.scan(@qualifiers) then [:QUALIFIER, text]
|
31
47
|
when text = @ss.scan(SEGMENT_END) then [:SEGMENT_END, text]
|
32
48
|
when text = @ss.scan(PLUS) then [:PLUS, text]
|
33
49
|
when text = @ss.scan(COLON) then [:COLON, text]
|
@@ -38,5 +54,18 @@ module EdifactParser
|
|
38
54
|
[x, x]
|
39
55
|
end
|
40
56
|
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def qualifier_regex
|
61
|
+
reg_ex_string = ""
|
62
|
+
|
63
|
+
QUALIFIERS.each do |qual|
|
64
|
+
reg_ex_string += "#{qual}|"
|
65
|
+
end
|
66
|
+
|
67
|
+
/(^|(?<='))(#{reg_ex_string[0, reg_ex_string.length-1]})/
|
68
|
+
end
|
69
|
+
|
41
70
|
end
|
42
|
-
end
|
71
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: edifact_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: racc
|