tediparse 2.0.0 → 2.1.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -0
- data/README.md +1 -13
- data/doc/Generating-Grammars.md +1 -1
- data/lib/stupidedi/exceptions/rejected_segment_limit_error.rb +23 -0
- data/lib/stupidedi/exceptions.rb +1 -0
- data/lib/stupidedi/parser/generation.rb +25 -3
- data/lib/stupidedi/parser/states/functional_group_state.rb +3 -0
- data/lib/stupidedi/schema/generation/flat_file_reader.rb +5 -3
- data/lib/stupidedi/schema/generation/master_loader_generator.rb +16 -2
- data/lib/stupidedi/schema/generation/module_loader_generator.rb +8 -21
- data/lib/stupidedi/schema/generation/version_modules.rb +2 -1
- data/lib/stupidedi/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7b53ffbf38074d691d1c4d3ef24181fa5396cd82c70d078529d2ca2d0f531daf
|
|
4
|
+
data.tar.gz: 606cb0163b2cad64112108c1f598c16b96f65275810862777cbf80132cf5b26e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4be487879c01e1404ea231785f3048fa6edbb7d8679021821de59f54a63a00e30c3312abb9bb6363481a2419f7fa1d3272cc92fd0113dc908f00c62fa515435
|
|
7
|
+
data.tar.gz: cb6268c8b72f4c4dee364f5e75a32c272e61ca960ac9ac67ed040a791d92c1cc89cc733c78faa9ff8b76902fa10a8a88efb7cfefea118bf38a888fe6420a0e7a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
v 2.1.0 - Nov 5, 2026
|
|
2
|
+
|
|
3
|
+
* Grammar generation supports release `008060` (module `EightySixty`,
|
|
4
|
+
interchange version `00806`). Its ASC X12 Table Data is Windows-1252,
|
|
5
|
+
unlike 008010's UTF-8, and is declared so in
|
|
6
|
+
`FlatFileReader::SOURCE_ENCODINGS`.
|
|
7
|
+
|
|
8
|
+
* The generated per-version module file (e.g. `edi/fifty_ten.rb`) no
|
|
9
|
+
longer declares relative-path `autoload`s for its support files. Under
|
|
10
|
+
Zeitwerk they replaced the autoloads Zeitwerk registers and made
|
|
11
|
+
concurrent first use of a grammar unsafe. The master loader now
|
|
12
|
+
requires the support files itself, so `--master-loader` consumers are
|
|
13
|
+
unaffected. Regenerate, or delete the `autoload` lines from existing
|
|
14
|
+
trees.
|
|
15
|
+
|
|
16
|
+
* `Parser::StateMachine#read` accepts a `max_rejected_segments` option.
|
|
17
|
+
Once more than that many segments have been rejected, it raises
|
|
18
|
+
`Exceptions::RejectedSegmentLimitError` (a `ParseError`) naming the
|
|
19
|
+
count and the first rejected segment. Memory grows with the square of
|
|
20
|
+
the number of rejected segments, so a large document whose envelope
|
|
21
|
+
or transaction set is not registered can otherwise exhaust memory.
|
|
22
|
+
Without the option, nothing changes.
|
|
23
|
+
|
|
24
|
+
* GS08 is stripped of surrounding whitespace before the functional-group
|
|
25
|
+
and transaction-set release lookups. Previously a GS08 sent with a
|
|
26
|
+
leading space (`" 004010"`) named an unregistered release and the
|
|
27
|
+
whole group was rejected, and a trailing space got past the group
|
|
28
|
+
lookup but failed the transaction set's. The GS segment still keeps
|
|
29
|
+
the value as sent.
|
|
30
|
+
|
|
1
31
|
v 2.0.0 - Aug 27, 2026
|
|
2
32
|
|
|
3
33
|
First release of tediparse. The version continues the `stupidedi`
|
data/README.md
CHANGED
|
@@ -85,7 +85,7 @@ This reads the flat files and writes a grammar tree under `<out>/<namespace>/`
|
|
|
85
85
|
interchange envelope under `interchanges/`, and a `stupidedi_registration.rb`
|
|
86
86
|
that wires everything onto a `Config`. Use `--dry-run` to preview without
|
|
87
87
|
writing. Supported releases: `003060`, `004010`, `004060`, `005010`, `006010`,
|
|
88
|
-
`007010`, `008010`.
|
|
88
|
+
`007010`, `008010`, `008060`.
|
|
89
89
|
|
|
90
90
|
You can keep several releases in one output tree. Generating an additional
|
|
91
91
|
release preserves the ones already present: `stupidedi_registration.rb` (and the
|
|
@@ -106,18 +106,6 @@ machine; you bring the material. The committed fixture under
|
|
|
106
106
|
`spec/support/generation/table_data/` is a hand-written synthetic grammar in
|
|
107
107
|
the same flat-file format, not real X12 content.
|
|
108
108
|
|
|
109
|
-
### Conformance suite
|
|
110
|
-
|
|
111
|
-
If you have private grammars and need to keep them tested against tediparse,
|
|
112
|
-
the upstream X12 fixture corpus and grammar tree remain recoverable from the
|
|
113
|
-
pre-removal commit:
|
|
114
|
-
|
|
115
|
-
git fetch --tags
|
|
116
|
-
git worktree add ../conformance pre-x12-removal
|
|
117
|
-
|
|
118
|
-
Build the conformance suite against that worktree's fixtures, layer your
|
|
119
|
-
licensed grammar on top, and run it out-of-tree.
|
|
120
|
-
|
|
121
109
|
## Attribution
|
|
122
110
|
|
|
123
111
|
This product includes software from `stupidedi` by Kyle Putnam, available at
|
data/doc/Generating-Grammars.md
CHANGED
|
@@ -84,7 +84,7 @@ tediparse register --out lib
|
|
|
84
84
|
```
|
|
85
85
|
|
|
86
86
|
Supported releases: `003060`, `004010`, `004060`, `005010`, `006010`,
|
|
87
|
-
`007010`, `008010`. An unsupported release code is rejected before anything
|
|
87
|
+
`007010`, `008010`, `008060`. An unsupported release code is rejected before anything
|
|
88
88
|
is read.
|
|
89
89
|
|
|
90
90
|
From Ruby
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Stupidedi
|
|
3
|
+
module Exceptions
|
|
4
|
+
#
|
|
5
|
+
# Raised by {Parser::Generation#read} when the number of rejected
|
|
6
|
+
# segments exceeds the +:max_rejected_segments+ option.
|
|
7
|
+
#
|
|
8
|
+
class RejectedSegmentLimitError < ParseError
|
|
9
|
+
# @return [Integer]
|
|
10
|
+
attr_reader :count
|
|
11
|
+
|
|
12
|
+
# @return [Values::InvalidSegmentVal]
|
|
13
|
+
attr_reader :first
|
|
14
|
+
|
|
15
|
+
def initialize(count, first)
|
|
16
|
+
@count, @first = count, first
|
|
17
|
+
|
|
18
|
+
super("stopped parsing after #{count} rejected segments; the first " \
|
|
19
|
+
"was #{first.id} at #{first.position.inspect} (#{first.reason})")
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/stupidedi/exceptions.rb
CHANGED
|
@@ -7,6 +7,7 @@ module Stupidedi
|
|
|
7
7
|
autoload :MissingGrammarError, "stupidedi/exceptions/missing_grammar_error"
|
|
8
8
|
autoload :OutputError, "stupidedi/exceptions/output_error"
|
|
9
9
|
autoload :ParseError, "stupidedi/exceptions/parse_error"
|
|
10
|
+
autoload :RejectedSegmentLimitError, "stupidedi/exceptions/rejected_segment_limit_error"
|
|
10
11
|
autoload :TokenizeError, "stupidedi/exceptions/tokenize_error"
|
|
11
12
|
autoload :ZipperError, "stupidedi/exceptions/zipper_error"
|
|
12
13
|
end
|
|
@@ -21,17 +21,39 @@ module Stupidedi
|
|
|
21
21
|
# been consumed. The extra parse trees are returned (in memory)
|
|
22
22
|
# via the {StateMachine} to aide diagnosis.
|
|
23
23
|
#
|
|
24
|
+
# The `max_rejected_segments` option stops the parse by raising
|
|
25
|
+
# {Exceptions::RejectedSegmentLimitError} once more than that many
|
|
26
|
+
# segments have been rejected. Memory grows with the square of the
|
|
27
|
+
# number of rejected segments, so without a limit a large document
|
|
28
|
+
# that is mostly rejected can exhaust memory. The default is no limit.
|
|
29
|
+
#
|
|
24
30
|
# @return [(StateMachine, Reader::Result)]
|
|
25
31
|
def read(reader, options = {})
|
|
26
|
-
limit
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
limit = options.fetch(:nondeterminism, 1)
|
|
33
|
+
max_rejected = options[:max_rejected_segments]
|
|
34
|
+
rejected = 0
|
|
35
|
+
first_rejected = nil
|
|
36
|
+
machine = self
|
|
37
|
+
reader_e = reader.read_segment
|
|
29
38
|
|
|
30
39
|
while reader_e.defined?
|
|
31
40
|
reader_e = reader_e.flatmap do |segment_tok, reader_|
|
|
32
41
|
machine, reader__ =
|
|
33
42
|
machine.insert(segment_tok, false, reader_)
|
|
34
43
|
|
|
44
|
+
unless max_rejected.nil?
|
|
45
|
+
failures = machine.active.select { |m| Values::InvalidSegmentVal === m.node.zipper.node }
|
|
46
|
+
|
|
47
|
+
if failures.any?
|
|
48
|
+
rejected += failures.length
|
|
49
|
+
first_rejected ||= failures.first.node.zipper.node
|
|
50
|
+
|
|
51
|
+
if rejected > max_rejected
|
|
52
|
+
raise Exceptions::RejectedSegmentLimitError.new(rejected, first_rejected)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
35
57
|
if machine.active.length <= limit
|
|
36
58
|
reader__.read_segment
|
|
37
59
|
else
|
|
@@ -52,7 +52,10 @@ module Stupidedi
|
|
|
52
52
|
# @return [Zipper::AbstractCursor]
|
|
53
53
|
def push(zipper, parent, segment_tok, segment_use, config)
|
|
54
54
|
# GS08: Version / Release / Industry Identifier Code
|
|
55
|
+
# Stripped for the release lookups only; the GS segment keeps the
|
|
56
|
+
# value as sent
|
|
55
57
|
gs08 = segment_tok.element_toks.at(7).try(:value)
|
|
58
|
+
gs08 = gs08.strip if gs08.is_a?(String)
|
|
56
59
|
gs08_version = gs08.try(:slice, 0, 6)
|
|
57
60
|
|
|
58
61
|
# GS01: Functional Identifier Code
|
|
@@ -18,8 +18,9 @@ module Stupidedi
|
|
|
18
18
|
#
|
|
19
19
|
# The distribution's encoding varies by release - see SOURCE_ENCODINGS. It
|
|
20
20
|
# is *not* ISO-8859-1 for any release we support, despite that being the
|
|
21
|
-
# obvious guess: releases through 007010 are Windows-1252
|
|
22
|
-
# UTF-8
|
|
21
|
+
# obvious guess: releases through 007010 are Windows-1252, 008010 is
|
|
22
|
+
# UTF-8, and 008060 is Windows-1252 again, so no release's encoding can
|
|
23
|
+
# be inferred from the one before it.
|
|
23
24
|
class FlatFileReader
|
|
24
25
|
# Declared source encoding per ASC X12 release. CP1252 and ISO-8859-1
|
|
25
26
|
# agree everywhere except 0x80-0x9F, which carries smart punctuation in
|
|
@@ -36,7 +37,8 @@ module Stupidedi
|
|
|
36
37
|
"005010" => "Windows-1252",
|
|
37
38
|
"006010" => "Windows-1252",
|
|
38
39
|
"007010" => "Windows-1252",
|
|
39
|
-
"008010" => "UTF-8"
|
|
40
|
+
"008010" => "UTF-8",
|
|
41
|
+
"008060" => "Windows-1252"
|
|
40
42
|
}.freeze
|
|
41
43
|
|
|
42
44
|
# An undeclared release decodes as UTF-8, deliberately. Single-byte
|
|
@@ -17,6 +17,17 @@ module Stupidedi
|
|
|
17
17
|
class MasterLoaderGenerator
|
|
18
18
|
include Support
|
|
19
19
|
|
|
20
|
+
# Per-version support files, in dependency order.
|
|
21
|
+
SUPPORT_FILES = %w[
|
|
22
|
+
element_reqs
|
|
23
|
+
element_types
|
|
24
|
+
segment_reqs
|
|
25
|
+
syntax_notes
|
|
26
|
+
element_defs
|
|
27
|
+
segment_defs
|
|
28
|
+
functional_group_def
|
|
29
|
+
].freeze
|
|
30
|
+
|
|
20
31
|
# @param roots [String, Array<String>] one or more base directories.
|
|
21
32
|
def initialize(roots:, namespace: "Edi")
|
|
22
33
|
@roots = Array(roots)
|
|
@@ -76,10 +87,13 @@ module Stupidedi
|
|
|
76
87
|
def require_lines
|
|
77
88
|
lines = []
|
|
78
89
|
|
|
79
|
-
# Version
|
|
80
|
-
#
|
|
90
|
+
# Version modules and their support files first - the interchange and
|
|
91
|
+
# standards files (and the registration) depend on them.
|
|
81
92
|
version_dirs.each do |dir_name, _|
|
|
82
93
|
lines << require_line("#{namespace_path}/#{dir_name}")
|
|
94
|
+
SUPPORT_FILES.each do |file|
|
|
95
|
+
lines << require_line("#{namespace_path}/#{dir_name}/#{file}")
|
|
96
|
+
end
|
|
83
97
|
end
|
|
84
98
|
|
|
85
99
|
# Interchange envelopes.
|
|
@@ -3,22 +3,17 @@
|
|
|
3
3
|
module Stupidedi
|
|
4
4
|
module Schema
|
|
5
5
|
module Generation
|
|
6
|
-
# Generates the top-level per-version
|
|
7
|
-
#
|
|
6
|
+
# Generates the top-level per-version module file (e.g. forty_ten.rb).
|
|
7
|
+
#
|
|
8
|
+
# It declares the module and nothing else. An explicit relative-path
|
|
9
|
+
# autoload here would replace the absolute one Zeitwerk registers, and
|
|
10
|
+
# Zeitwerk would then attribute the require to whatever file is last in
|
|
11
|
+
# $LOADED_FEATURES, which a concurrent autoload on another thread can
|
|
12
|
+
# change. Consumers without an autoloader get the support files from the
|
|
13
|
+
# master loader instead (see MasterLoaderGenerator::SUPPORT_FILES).
|
|
8
14
|
class ModuleLoaderGenerator
|
|
9
15
|
include Support
|
|
10
16
|
|
|
11
|
-
# Autoload order matters - dependencies must be loaded first
|
|
12
|
-
AUTOLOAD_MODULES = %w[
|
|
13
|
-
ElementReqs
|
|
14
|
-
ElementTypes
|
|
15
|
-
SegmentReqs
|
|
16
|
-
SyntaxNotes
|
|
17
|
-
ElementDefs
|
|
18
|
-
SegmentDefs
|
|
19
|
-
FunctionalGroupDef
|
|
20
|
-
].freeze
|
|
21
|
-
|
|
22
17
|
def initialize(release, namespace: "Edi")
|
|
23
18
|
@release = release
|
|
24
19
|
@namespace = namespace
|
|
@@ -42,18 +37,10 @@ module Stupidedi
|
|
|
42
37
|
end
|
|
43
38
|
|
|
44
39
|
def build_ruby_content
|
|
45
|
-
base_path = "#{namespace_path}/#{underscore(version_module)}"
|
|
46
|
-
autoloads = AUTOLOAD_MODULES.map do |mod|
|
|
47
|
-
file_name = underscore(mod)
|
|
48
|
-
padding = " " * (18 - mod.length)
|
|
49
|
-
" autoload :#{mod},#{padding}\"#{base_path}/#{file_name}\""
|
|
50
|
-
end
|
|
51
|
-
|
|
52
40
|
<<~RUBY
|
|
53
41
|
# frozen_string_literal: true
|
|
54
42
|
module #{namespace}
|
|
55
43
|
module #{version_module}
|
|
56
|
-
#{autoloads.join("\n")}
|
|
57
44
|
end
|
|
58
45
|
end
|
|
59
46
|
RUBY
|
|
@@ -13,7 +13,8 @@ module Stupidedi
|
|
|
13
13
|
"005010" => "FiftyTen",
|
|
14
14
|
"006010" => "SixtyTen",
|
|
15
15
|
"007010" => "SeventyTen",
|
|
16
|
-
"008010" => "EightyTen"
|
|
16
|
+
"008010" => "EightyTen",
|
|
17
|
+
"008060" => "EightySixty"
|
|
17
18
|
}.freeze
|
|
18
19
|
|
|
19
20
|
# Maps X12 requirement designators to Stupidedi ElementReq names.
|
data/lib/stupidedi/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tediparse
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kyle Putnam
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
- Adrian Duyzer
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2026-
|
|
12
|
+
date: 2026-11-05 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: term-ansicolor
|
|
@@ -88,6 +88,7 @@ files:
|
|
|
88
88
|
- lib/stupidedi/exceptions/missing_grammar_error.rb
|
|
89
89
|
- lib/stupidedi/exceptions/output_error.rb
|
|
90
90
|
- lib/stupidedi/exceptions/parse_error.rb
|
|
91
|
+
- lib/stupidedi/exceptions/rejected_segment_limit_error.rb
|
|
91
92
|
- lib/stupidedi/exceptions/stupidedi_error.rb
|
|
92
93
|
- lib/stupidedi/exceptions/tokenize_error.rb
|
|
93
94
|
- lib/stupidedi/exceptions/zipper_error.rb
|