edir 1.0.0 → 1.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/Gemfile +0 -9
- data/Gemfile.lock +23 -38
- data/Rakefile +0 -9
- data/lib/edir/{convert.rb → converter.rb} +3 -1
- data/lib/edir/parsing.rb +27 -0
- data/lib/edir/segment.rb +8 -8
- data/lib/edir/version.rb +1 -1
- data/lib/edir.rb +1 -2
- metadata +4 -6
- data/lib/edir/lexer.rb +0 -95
- data/lib/edir/parser.rb +0 -181
- data/lib/edir/parser.y +0 -43
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6edf58c25b7fef2c55e00d2b0f2a7e92b7bd8abf138ceb20dc7f2a22411c1379
|
|
4
|
+
data.tar.gz: 2fe71607b7d9f657180cb44637bad0d92a91aad67615954e41d9716e8ddf8e24
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 596ffc51ec1505d1132bf08fca9b7ce379dcd77a199db41497ec6792efa24f551a134b96ce9944a8518386c77fd844e2edc0a13f97d00e77f7cf44adb0ff2af4
|
|
7
|
+
data.tar.gz: 8fd97a4152917829cdb846757824ebc2b6631ddec6f47f85a7990d6ea7de43d7bba172732c8febe7337b4edd860782dcaf70790dfec267185d22926745d64b81
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,59 +1,48 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
edir (1.
|
|
4
|
+
edir (1.1.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
9
|
ast (2.4.2)
|
|
10
|
-
byebug (11.1.3)
|
|
11
|
-
coderay (1.1.3)
|
|
12
10
|
diff-lcs (1.5.0)
|
|
13
|
-
json (2.6.
|
|
14
|
-
lex (0.1.0)
|
|
15
|
-
method_source (1.0.0)
|
|
11
|
+
json (2.6.3)
|
|
16
12
|
parallel (1.22.1)
|
|
17
|
-
parser (3.
|
|
13
|
+
parser (3.2.2.0)
|
|
18
14
|
ast (~> 2.4.1)
|
|
19
|
-
pry (0.14.1)
|
|
20
|
-
coderay (~> 1.1)
|
|
21
|
-
method_source (~> 1.0)
|
|
22
|
-
pry-byebug (3.8.0)
|
|
23
|
-
byebug (~> 11.0)
|
|
24
|
-
pry (~> 0.10)
|
|
25
|
-
racc (1.6.0)
|
|
26
15
|
rainbow (3.1.1)
|
|
27
16
|
rake (13.0.6)
|
|
28
|
-
regexp_parser (2.
|
|
17
|
+
regexp_parser (2.7.0)
|
|
29
18
|
rexml (3.2.5)
|
|
30
|
-
rspec (3.
|
|
31
|
-
rspec-core (~> 3.
|
|
32
|
-
rspec-expectations (~> 3.
|
|
33
|
-
rspec-mocks (~> 3.
|
|
34
|
-
rspec-core (3.
|
|
35
|
-
rspec-support (~> 3.
|
|
36
|
-
rspec-expectations (3.
|
|
19
|
+
rspec (3.12.0)
|
|
20
|
+
rspec-core (~> 3.12.0)
|
|
21
|
+
rspec-expectations (~> 3.12.0)
|
|
22
|
+
rspec-mocks (~> 3.12.0)
|
|
23
|
+
rspec-core (3.12.1)
|
|
24
|
+
rspec-support (~> 3.12.0)
|
|
25
|
+
rspec-expectations (3.12.2)
|
|
37
26
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
38
|
-
rspec-support (~> 3.
|
|
39
|
-
rspec-mocks (3.
|
|
27
|
+
rspec-support (~> 3.12.0)
|
|
28
|
+
rspec-mocks (3.12.5)
|
|
40
29
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
41
|
-
rspec-support (~> 3.
|
|
42
|
-
rspec-support (3.
|
|
43
|
-
rubocop (1.
|
|
30
|
+
rspec-support (~> 3.12.0)
|
|
31
|
+
rspec-support (3.12.0)
|
|
32
|
+
rubocop (1.50.1)
|
|
44
33
|
json (~> 2.3)
|
|
45
34
|
parallel (~> 1.10)
|
|
46
|
-
parser (>= 3.
|
|
35
|
+
parser (>= 3.2.0.0)
|
|
47
36
|
rainbow (>= 2.2.2, < 4.0)
|
|
48
37
|
regexp_parser (>= 1.8, < 3.0)
|
|
49
38
|
rexml (>= 3.2.5, < 4.0)
|
|
50
|
-
rubocop-ast (>= 1.
|
|
39
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
|
51
40
|
ruby-progressbar (~> 1.7)
|
|
52
|
-
unicode-display_width (>=
|
|
53
|
-
rubocop-ast (1.
|
|
54
|
-
parser (>= 3.
|
|
55
|
-
ruby-progressbar (1.
|
|
56
|
-
unicode-display_width (2.
|
|
41
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
42
|
+
rubocop-ast (1.28.0)
|
|
43
|
+
parser (>= 3.2.1.0)
|
|
44
|
+
ruby-progressbar (1.13.0)
|
|
45
|
+
unicode-display_width (2.4.2)
|
|
57
46
|
|
|
58
47
|
PLATFORMS
|
|
59
48
|
ruby
|
|
@@ -62,10 +51,6 @@ PLATFORMS
|
|
|
62
51
|
|
|
63
52
|
DEPENDENCIES
|
|
64
53
|
edir!
|
|
65
|
-
lex (~> 0.1.0)
|
|
66
|
-
pry
|
|
67
|
-
pry-byebug
|
|
68
|
-
racc (~> 1.6.0)
|
|
69
54
|
rake (~> 13.0)
|
|
70
55
|
rspec (~> 3.0)
|
|
71
56
|
rubocop (~> 1.21)
|
data/Rakefile
CHANGED
|
@@ -10,12 +10,3 @@ require "rubocop/rake_task"
|
|
|
10
10
|
RuboCop::RakeTask.new
|
|
11
11
|
|
|
12
12
|
task default: %i[spec rubocop]
|
|
13
|
-
|
|
14
|
-
desc "Generate Parser"
|
|
15
|
-
task :parser do
|
|
16
|
-
`racc lib/edir/parser.y -o lib/edir/parser.rb`
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
task :parser_debug do
|
|
20
|
-
`racc -g lib/edir/parser.y -o lib/edir/parser.rb`
|
|
21
|
-
end
|
|
@@ -8,7 +8,9 @@ require_relative "segment"
|
|
|
8
8
|
|
|
9
9
|
module Edir
|
|
10
10
|
# Converter methods for parsed EDI
|
|
11
|
-
module
|
|
11
|
+
module Converter
|
|
12
|
+
module_function
|
|
13
|
+
|
|
12
14
|
# For each transaction set start/end, create a unique transaction set object with
|
|
13
15
|
# the corrsponding segments.
|
|
14
16
|
# For each functional group start/end, create a unique functional group object with
|
data/lib/edir/parsing.rb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "converter"
|
|
4
|
+
|
|
5
|
+
module Edir
|
|
6
|
+
# Top level parsing module
|
|
7
|
+
# Edir::Parsing.parse(raw_edi)
|
|
8
|
+
module Parsing
|
|
9
|
+
extend Edir::Converter
|
|
10
|
+
|
|
11
|
+
module_function
|
|
12
|
+
|
|
13
|
+
def parse(raw_edi)
|
|
14
|
+
# TODO: Figure out the segment/element separators dynamically
|
|
15
|
+
segments = raw_edi.gsub("\n", "").gsub("\r", "").split("~")
|
|
16
|
+
segments = segments.map do |segment|
|
|
17
|
+
Edir::Segment.new(segment)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
if segments.length > 1
|
|
21
|
+
convert_document(segments)
|
|
22
|
+
else
|
|
23
|
+
segments
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/edir/segment.rb
CHANGED
|
@@ -7,19 +7,15 @@ module Edir
|
|
|
7
7
|
|
|
8
8
|
def initialize(data)
|
|
9
9
|
@raw_data = data
|
|
10
|
-
@
|
|
10
|
+
@raw_elements = @raw_data.split("*")
|
|
11
|
+
@name = @raw_elements.first
|
|
11
12
|
build_elements
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def build_elements
|
|
15
16
|
@elements = []
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if separator?(element)
|
|
19
|
-
position += 1
|
|
20
|
-
else
|
|
21
|
-
@elements.push([element, position])
|
|
22
|
-
end
|
|
17
|
+
@raw_elements[1..].each_with_index do |element, index|
|
|
18
|
+
@elements.push([element.strip, index + 1])
|
|
23
19
|
end
|
|
24
20
|
end
|
|
25
21
|
|
|
@@ -36,5 +32,9 @@ module Edir
|
|
|
36
32
|
@name => @elements.to_h { |e| ["e#{e.last.to_s.rjust(2, "0")}", e.first] }
|
|
37
33
|
}
|
|
38
34
|
end
|
|
35
|
+
|
|
36
|
+
def to_s
|
|
37
|
+
"#<Edir::Segment #{@name} #{@elements}>"
|
|
38
|
+
end
|
|
39
39
|
end
|
|
40
40
|
end
|
data/lib/edir/version.rb
CHANGED
data/lib/edir.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: edir
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kaleb McKone
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-
|
|
11
|
+
date: 2023-04-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description:
|
|
14
14
|
email:
|
|
@@ -28,13 +28,11 @@ files:
|
|
|
28
28
|
- bin/console
|
|
29
29
|
- bin/setup
|
|
30
30
|
- lib/edir.rb
|
|
31
|
-
- lib/edir/
|
|
31
|
+
- lib/edir/converter.rb
|
|
32
32
|
- lib/edir/document.rb
|
|
33
33
|
- lib/edir/functional_group.rb
|
|
34
34
|
- lib/edir/interchange.rb
|
|
35
|
-
- lib/edir/
|
|
36
|
-
- lib/edir/parser.rb
|
|
37
|
-
- lib/edir/parser.y
|
|
35
|
+
- lib/edir/parsing.rb
|
|
38
36
|
- lib/edir/segment.rb
|
|
39
37
|
- lib/edir/transaction_set.rb
|
|
40
38
|
- lib/edir/version.rb
|
data/lib/edir/lexer.rb
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "lex"
|
|
4
|
-
|
|
5
|
-
module Edir
|
|
6
|
-
# Top level API class for providing EDI lexing
|
|
7
|
-
class Lexer < Lex::Lexer
|
|
8
|
-
tokens(
|
|
9
|
-
:SEGSTART,
|
|
10
|
-
:SEGEND,
|
|
11
|
-
:ELEMSEP,
|
|
12
|
-
:ELEM
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
states(
|
|
16
|
-
insegment: :exclusive,
|
|
17
|
-
inelement: :exclusive
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
rule(:SEGSTART, /\w{2,3}(?=[*|~])/) do |lexer, token|
|
|
21
|
-
lexer.push_state(:insegment)
|
|
22
|
-
token
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# Rule to match when we have started a segment
|
|
26
|
-
# but it has no elements
|
|
27
|
-
rule(:insegment_SEGEND, /~|\n/) do |lexer, token|
|
|
28
|
-
lexer.pop_state
|
|
29
|
-
token
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
rule(:insegment_ELEMSEP, /\*|\|/) do |lexer, token|
|
|
33
|
-
# If we are insegment, when we encounter an element separator it means
|
|
34
|
-
# we should now be inelement. Otherwise, we were inelement and should
|
|
35
|
-
# leave the state, back to insegment.
|
|
36
|
-
if lexer.current_state == :insegment
|
|
37
|
-
lexer.push_state(:inelement)
|
|
38
|
-
else
|
|
39
|
-
lexer.pop_state
|
|
40
|
-
end
|
|
41
|
-
token
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
rule(:inelement_ELEMSEP, /\*|\|/)
|
|
45
|
-
|
|
46
|
-
rule(:inelement_ELEM, /[\w\s\-().,!:@>'^]+/) do |_lexer, token|
|
|
47
|
-
token.value = token.value.strip
|
|
48
|
-
token
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
rule(:inelement_SEGEND, /~|\n/) do |lexer, token|
|
|
52
|
-
lexer.pop_state
|
|
53
|
-
lexer.pop_state
|
|
54
|
-
token
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
ignore "\n"
|
|
58
|
-
ignore :insegment, "\s"
|
|
59
|
-
ignore :inelement, "\s"
|
|
60
|
-
|
|
61
|
-
error :insegment do |lexer, token|
|
|
62
|
-
error_handler(lexer, token)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
error :inelement do |lexer, token|
|
|
66
|
-
error_handler(lexer, token)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def lex_str(str)
|
|
70
|
-
# NOTE: Need to decide if this is really what we want to do here.
|
|
71
|
-
# Do the token objects contain any more useful information we
|
|
72
|
-
# should be passing on?
|
|
73
|
-
with_empty_elements_added = []
|
|
74
|
-
tokens = lex(str).map { |o| [o.name, o.value] }
|
|
75
|
-
# TODO: There's got to be a better way to do this
|
|
76
|
-
# I just want to know if two adjacent tokens are :ELEMSEP so we can
|
|
77
|
-
# add back the empty element that isn't easily handled by the lexer
|
|
78
|
-
tokens.each_with_index.map do |token, i|
|
|
79
|
-
with_empty_elements_added << token
|
|
80
|
-
if token.first == :ELEMSEP && i + 1 < tokens.length && tokens[i + 1].first == :ELEMSEP
|
|
81
|
-
with_empty_elements_added << [:ELEM, ""]
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
with_empty_elements_added
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
class << self
|
|
88
|
-
private
|
|
89
|
-
|
|
90
|
-
def error_handler(_lexer, token)
|
|
91
|
-
puts "Illegal character #{token.value}"
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
data/lib/edir/parser.rb
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# DO NOT MODIFY!!!!
|
|
3
|
-
# This file is automatically generated by Racc 1.6.0
|
|
4
|
-
# from Racc grammar file "".
|
|
5
|
-
#
|
|
6
|
-
|
|
7
|
-
require 'racc/parser.rb'
|
|
8
|
-
|
|
9
|
-
require_relative 'lexer'
|
|
10
|
-
require_relative 'convert'
|
|
11
|
-
|
|
12
|
-
module Edir
|
|
13
|
-
class Parser < Racc::Parser
|
|
14
|
-
|
|
15
|
-
module_eval(<<'...end parser.y/module_eval...', 'parser.y', 24)
|
|
16
|
-
include Edir::Convert
|
|
17
|
-
|
|
18
|
-
def initialize(debug: false)
|
|
19
|
-
@yydebug = debug
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def parse(str)
|
|
23
|
-
@q = Edir::Lexer.new.lex_str(str)
|
|
24
|
-
data = do_parse
|
|
25
|
-
# Implicit segment vs document mode
|
|
26
|
-
if data.length > 1
|
|
27
|
-
convert_document(data)
|
|
28
|
-
else
|
|
29
|
-
data
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def next_token
|
|
34
|
-
@q.shift
|
|
35
|
-
end
|
|
36
|
-
...end parser.y/module_eval...
|
|
37
|
-
##### State transition tables begin ###
|
|
38
|
-
|
|
39
|
-
racc_action_table = [
|
|
40
|
-
7, 8, 9, 8, 9, 8, 9, 3, 4, 3,
|
|
41
|
-
10, 11 ]
|
|
42
|
-
|
|
43
|
-
racc_action_check = [
|
|
44
|
-
3, 3, 3, 8, 8, 9, 9, 0, 1, 2,
|
|
45
|
-
4, 6 ]
|
|
46
|
-
|
|
47
|
-
racc_action_pointer = [
|
|
48
|
-
5, 8, 7, -3, 10, nil, 8, nil, -1, 1,
|
|
49
|
-
nil, nil, nil, nil ]
|
|
50
|
-
|
|
51
|
-
racc_action_default = [
|
|
52
|
-
-8, -8, -2, -8, -8, -1, -8, -4, -8, -7,
|
|
53
|
-
14, -3, -5, -6 ]
|
|
54
|
-
|
|
55
|
-
racc_goto_table = [
|
|
56
|
-
6, 1, nil, 5, nil, 12, 13 ]
|
|
57
|
-
|
|
58
|
-
racc_goto_check = [
|
|
59
|
-
3, 1, nil, 1, nil, 3, 3 ]
|
|
60
|
-
|
|
61
|
-
racc_goto_pointer = [
|
|
62
|
-
nil, 1, nil, -3 ]
|
|
63
|
-
|
|
64
|
-
racc_goto_default = [
|
|
65
|
-
nil, nil, 2, nil ]
|
|
66
|
-
|
|
67
|
-
racc_reduce_table = [
|
|
68
|
-
0, 0, :racc_error,
|
|
69
|
-
2, 7, :_reduce_1,
|
|
70
|
-
1, 7, :_reduce_2,
|
|
71
|
-
3, 8, :_reduce_3,
|
|
72
|
-
2, 8, :_reduce_4,
|
|
73
|
-
2, 9, :_reduce_5,
|
|
74
|
-
2, 9, :_reduce_6,
|
|
75
|
-
1, 9, :_reduce_7 ]
|
|
76
|
-
|
|
77
|
-
racc_reduce_n = 8
|
|
78
|
-
|
|
79
|
-
racc_shift_n = 14
|
|
80
|
-
|
|
81
|
-
racc_token_table = {
|
|
82
|
-
false => 0,
|
|
83
|
-
:error => 1,
|
|
84
|
-
:SEGSTART => 2,
|
|
85
|
-
:SEGEND => 3,
|
|
86
|
-
:ELEMSEP => 4,
|
|
87
|
-
:ELEM => 5 }
|
|
88
|
-
|
|
89
|
-
racc_nt_base = 6
|
|
90
|
-
|
|
91
|
-
racc_use_result_var = true
|
|
92
|
-
|
|
93
|
-
Racc_arg = [
|
|
94
|
-
racc_action_table,
|
|
95
|
-
racc_action_check,
|
|
96
|
-
racc_action_default,
|
|
97
|
-
racc_action_pointer,
|
|
98
|
-
racc_goto_table,
|
|
99
|
-
racc_goto_check,
|
|
100
|
-
racc_goto_default,
|
|
101
|
-
racc_goto_pointer,
|
|
102
|
-
racc_nt_base,
|
|
103
|
-
racc_reduce_table,
|
|
104
|
-
racc_token_table,
|
|
105
|
-
racc_shift_n,
|
|
106
|
-
racc_reduce_n,
|
|
107
|
-
racc_use_result_var ]
|
|
108
|
-
|
|
109
|
-
Racc_token_to_s_table = [
|
|
110
|
-
"$end",
|
|
111
|
-
"error",
|
|
112
|
-
"SEGSTART",
|
|
113
|
-
"SEGEND",
|
|
114
|
-
"ELEMSEP",
|
|
115
|
-
"ELEM",
|
|
116
|
-
"$start",
|
|
117
|
-
"segments",
|
|
118
|
-
"segment",
|
|
119
|
-
"elems" ]
|
|
120
|
-
|
|
121
|
-
Racc_debug_parser = false
|
|
122
|
-
|
|
123
|
-
##### State transition tables end #####
|
|
124
|
-
|
|
125
|
-
# reduce 0 omitted
|
|
126
|
-
|
|
127
|
-
module_eval(<<'.,.,', 'parser.y', 9)
|
|
128
|
-
def _reduce_1(val, _values, result)
|
|
129
|
-
result = [val[0]] + val[1]
|
|
130
|
-
result
|
|
131
|
-
end
|
|
132
|
-
.,.,
|
|
133
|
-
|
|
134
|
-
module_eval(<<'.,.,', 'parser.y', 10)
|
|
135
|
-
def _reduce_2(val, _values, result)
|
|
136
|
-
result = val
|
|
137
|
-
result
|
|
138
|
-
end
|
|
139
|
-
.,.,
|
|
140
|
-
|
|
141
|
-
module_eval(<<'.,.,', 'parser.y', 11)
|
|
142
|
-
def _reduce_3(val, _values, result)
|
|
143
|
-
result = Edir::Segment.new([val[0]] + val[1])
|
|
144
|
-
result
|
|
145
|
-
end
|
|
146
|
-
.,.,
|
|
147
|
-
|
|
148
|
-
module_eval(<<'.,.,', 'parser.y', 12)
|
|
149
|
-
def _reduce_4(val, _values, result)
|
|
150
|
-
result = Edir::Segment.new([val[0]])
|
|
151
|
-
result
|
|
152
|
-
end
|
|
153
|
-
.,.,
|
|
154
|
-
|
|
155
|
-
module_eval(<<'.,.,', 'parser.y', 13)
|
|
156
|
-
def _reduce_5(val, _values, result)
|
|
157
|
-
result = [val[0]] + val[1]
|
|
158
|
-
result
|
|
159
|
-
end
|
|
160
|
-
.,.,
|
|
161
|
-
|
|
162
|
-
module_eval(<<'.,.,', 'parser.y', 14)
|
|
163
|
-
def _reduce_6(val, _values, result)
|
|
164
|
-
result = [val[0]] + val[1]
|
|
165
|
-
result
|
|
166
|
-
end
|
|
167
|
-
.,.,
|
|
168
|
-
|
|
169
|
-
module_eval(<<'.,.,', 'parser.y', 15)
|
|
170
|
-
def _reduce_7(val, _values, result)
|
|
171
|
-
result = val
|
|
172
|
-
result
|
|
173
|
-
end
|
|
174
|
-
.,.,
|
|
175
|
-
|
|
176
|
-
def _reduce_none(val, _values, result)
|
|
177
|
-
val[0]
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
end # class Parser
|
|
181
|
-
end # module Edir
|
data/lib/edir/parser.y
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
class Edir::Parser
|
|
2
|
-
token SEGSTART SEGEND ELEMSEP ELEM
|
|
3
|
-
# local variables that racc provides in the environment of action:
|
|
4
|
-
# * val is the right hand side
|
|
5
|
-
# * result is the left hand side
|
|
6
|
-
# The plural definitions return an array while the singular ones
|
|
7
|
-
# return a single element. In order to build a sensibly flat representation of the
|
|
8
|
-
# document, we concatenate the single elements with the ones that return an array
|
|
9
|
-
rule
|
|
10
|
-
segments : segment segments { result = [val[0]] + val[1] }
|
|
11
|
-
| segment { result = val }
|
|
12
|
-
segment : SEGSTART elems SEGEND { result = Edir::Segment.new([val[0]] + val[1]) }
|
|
13
|
-
| SEGSTART SEGEND { result = Edir::Segment.new([val[0]]) }
|
|
14
|
-
elems : ELEMSEP elems { result = [val[0]] + val[1] }
|
|
15
|
-
| ELEM elems { result = [val[0]] + val[1] }
|
|
16
|
-
| ELEM { result = val }
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
---- header
|
|
20
|
-
require_relative 'lexer'
|
|
21
|
-
require_relative 'convert'
|
|
22
|
-
|
|
23
|
-
---- inner
|
|
24
|
-
include Edir::Convert
|
|
25
|
-
|
|
26
|
-
def initialize(debug: false)
|
|
27
|
-
@yydebug = debug
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def parse(str)
|
|
31
|
-
@q = Edir::Lexer.new.lex_str(str)
|
|
32
|
-
data = do_parse
|
|
33
|
-
# Implicit segment vs document mode
|
|
34
|
-
if data.length > 1
|
|
35
|
-
convert_document(data)
|
|
36
|
-
else
|
|
37
|
-
data
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def next_token
|
|
42
|
-
@q.shift
|
|
43
|
-
end
|