l43_rmap 0.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 +7 -0
- data/LiCenSE +235 -0
- data/README.md +141 -0
- data/bin/rmap +12 -0
- data/lib/enumerable.rb +28 -0
- data/lib/l43_rmap/ast.rb +58 -0
- data/lib/l43_rmap/chunk.rb +8 -0
- data/lib/l43_rmap/cli/color.rb +29 -0
- data/lib/l43_rmap/cli/help.rb +89 -0
- data/lib/l43_rmap/cli.rb +108 -0
- data/lib/l43_rmap/compiler.rb +68 -0
- data/lib/l43_rmap/evaluator/evaluations.rb +23 -0
- data/lib/l43_rmap/evaluator.rb +28 -0
- data/lib/l43_rmap/function.rb +20 -0
- data/lib/l43_rmap/functions/predefined/shell.rb +21 -0
- data/lib/l43_rmap/functions/predefined.rb +55 -0
- data/lib/l43_rmap/functions.rb +67 -0
- data/lib/l43_rmap/parsing/chunk_parser.rb +171 -0
- data/lib/l43_rmap/parsing/input.rb +26 -0
- data/lib/l43_rmap/parsing/parse_state.rb +18 -0
- data/lib/l43_rmap/parsing/rgx_parser.rb +51 -0
- data/lib/l43_rmap/parsing/rgx_parsers.rb +71 -0
- data/lib/l43_rmap/predefined_patterns.rb +14 -0
- data/lib/l43_rmap/runtime/line_time.rb +58 -0
- data/lib/l43_rmap/runtime.rb +78 -0
- data/lib/l43_rmap/version.rb +6 -0
- data/lib/l43_rmap.rb +32 -0
- data/lib/peg.backup/all.rb +12 -0
- data/lib/peg.backup/combinators/implementation.rb +144 -0
- data/lib/peg.backup/combinators.rb +82 -0
- data/lib/peg.backup/parser/input.rb +36 -0
- data/lib/peg.backup/parser.rb +46 -0
- data/lib/peg.backup/parsers/advanced_parsers.rb +26 -0
- data/lib/peg.backup/parsers/base_parsers.rb +124 -0
- data/lib/peg.backup/parsers/common_parsers.rb +60 -0
- data/lib/peg.backup/parsers/true_set.rb +10 -0
- data/lib/peg.backup/parsers.rb +14 -0
- data/lib/peg.backup/result.rb +78 -0
- metadata +135 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'true_set'
|
|
4
|
+
module Peg
|
|
5
|
+
module Parsers
|
|
6
|
+
module BaseParsers
|
|
7
|
+
|
|
8
|
+
# Parses a character which is a member of any of the `char_classes`
|
|
9
|
+
def char_class_parser(*char_classes, name: nil)
|
|
10
|
+
case char_classes
|
|
11
|
+
in [char_class]
|
|
12
|
+
_1_char_class_parser(char_class, name:)
|
|
13
|
+
else
|
|
14
|
+
_char_classes_parser(*char_classes, name:)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def char_parser(set=nil, name: nil, negate: false)
|
|
19
|
+
set = mk_set(set)
|
|
20
|
+
name ||= "char_parser(#{set.inspect})"
|
|
21
|
+
Parser.new(name) do |input|
|
|
22
|
+
case input.content
|
|
23
|
+
in []
|
|
24
|
+
Result.nok(error: "unexpected end of input", input:, name:)
|
|
25
|
+
in [h, *]
|
|
26
|
+
if set.member?(h) && !negate || !set.member?(h) && negate
|
|
27
|
+
Result.ok(ast: h, input: input.advance)
|
|
28
|
+
else
|
|
29
|
+
Result.nok(input:, error: "#{h} is not member of the required set #{set}", name:)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def end_parser(name: nil)
|
|
36
|
+
name ||= "end_parser"
|
|
37
|
+
Parser.new(name) do |input|
|
|
38
|
+
case input.content
|
|
39
|
+
in []
|
|
40
|
+
Result.ok(ast: nil, input:)
|
|
41
|
+
in _
|
|
42
|
+
Result.nok(input: input, error: "not at end of input", name:)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def make_parser(parser)
|
|
48
|
+
case parser
|
|
49
|
+
when String
|
|
50
|
+
char_parser(parser)
|
|
51
|
+
else
|
|
52
|
+
parser
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def make_parsers(*parsers)
|
|
57
|
+
parsers
|
|
58
|
+
.flatten
|
|
59
|
+
.map { make_parser it }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
def _1_char_class_parser(char_class, name:)
|
|
65
|
+
rgx = Regexp.compile("[[:#{char_class}:]]")
|
|
66
|
+
name ||= "char_class_parser(:#{char_class})"
|
|
67
|
+
Parser.new(name) do |input|
|
|
68
|
+
case input.content
|
|
69
|
+
in []
|
|
70
|
+
Result.nok(error: "unexpected end of input", input:, name:)
|
|
71
|
+
in [h, *]
|
|
72
|
+
if rgx.match?(h)
|
|
73
|
+
Result.ok(ast: h, input: input.advance)
|
|
74
|
+
else
|
|
75
|
+
Result.nok(input:, name:, error: "#{h} does not match the char class: :#{char_class}")
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def _char_classes_parser(*char_classes, name:)
|
|
82
|
+
rgx = Regexp.compile("[#{_compile_char_classes(char_classes)}]")
|
|
83
|
+
name ||= "char_class_parser(#{char_classes.inspect})"
|
|
84
|
+
Parser.new(name) do |input|
|
|
85
|
+
case input.content
|
|
86
|
+
in []
|
|
87
|
+
Result.nok(error: "unexpected end of input", input:, name:)
|
|
88
|
+
in [h, *]
|
|
89
|
+
if rgx.match?(h)
|
|
90
|
+
Result.ok(ast: h, input: input.advance)
|
|
91
|
+
else
|
|
92
|
+
Result.nok(input:, name:, error: "#{h} does not match the char class: :#{char_classes}")
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def _compile_char_class(char_class)
|
|
99
|
+
case char_class
|
|
100
|
+
when Symbol
|
|
101
|
+
"[:#{char_class}:]"
|
|
102
|
+
when String
|
|
103
|
+
"[#{char_class}]"
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def _compile_char_classes(char_classes)
|
|
108
|
+
"[" +
|
|
109
|
+
char_classes
|
|
110
|
+
.map { _compile_char_class it }
|
|
111
|
+
.join + "]"
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def mk_set(set)
|
|
115
|
+
if set
|
|
116
|
+
Set.new(set.grapheme_clusters)
|
|
117
|
+
else
|
|
118
|
+
TrueSet
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../combinators'
|
|
4
|
+
module Peg
|
|
5
|
+
module Parsers
|
|
6
|
+
module CommonParsers
|
|
7
|
+
include Peg::Combinators
|
|
8
|
+
|
|
9
|
+
def id_parser(name: nil, lead_class: :alpha, inner_class: [:alnum, "_"] )
|
|
10
|
+
sequence(char_class_parser(*Array(lead_class)),
|
|
11
|
+
many(char_class_parser(*Array(inner_class)), name:),
|
|
12
|
+
name:
|
|
13
|
+
).map {
|
|
14
|
+
it.flatten.join.to_sym
|
|
15
|
+
}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Just parses any string starting with either a `+` or `-` sign followed by at least one
|
|
20
|
+
# _decimal digit_.
|
|
21
|
+
#
|
|
22
|
+
# **N.B.** that leading zeroes are parsed (and therefore ignored) and will not parse
|
|
23
|
+
# it as a hexadecimal or octal number
|
|
24
|
+
def int_parser(name=nil)
|
|
25
|
+
parser = sequence(
|
|
26
|
+
maybe(char_parser("+-")),
|
|
27
|
+
many(char_class_parser(:digit), min: 1),
|
|
28
|
+
name: name || "int_parser")
|
|
29
|
+
map_result(parser) { _make_int(it) }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def literal_set(set, name: nil, lead_class: :alpha, inner_class: [:alnum, "_"])
|
|
33
|
+
id_parser(name:, lead_class:, inner_class:)
|
|
34
|
+
.satisfy { set.member? it }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def ws_parser(name=nil)
|
|
38
|
+
map(
|
|
39
|
+
many(
|
|
40
|
+
char_class_parser(:space),
|
|
41
|
+
min: 1,
|
|
42
|
+
name: "ws_parser"
|
|
43
|
+
)
|
|
44
|
+
) {|_| nil}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def _make_int(result)
|
|
50
|
+
case result
|
|
51
|
+
in {ok: true, ast:}
|
|
52
|
+
result.merge(ast: ast.join.to_i)
|
|
53
|
+
in {input:}
|
|
54
|
+
result.merge(error: "Not an integer at #{input.show(10).inspect} in int_parser")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "parsers/base_parsers"
|
|
4
|
+
require_relative "parsers/common_parsers"
|
|
5
|
+
module Peg
|
|
6
|
+
module Parsers
|
|
7
|
+
extend BaseParsers
|
|
8
|
+
include BaseParsers
|
|
9
|
+
|
|
10
|
+
extend CommonParsers
|
|
11
|
+
include CommonParsers
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Peg
|
|
4
|
+
class Result
|
|
5
|
+
class IllegalState < RuntimeError
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
attr_reader :ast, :error, :input, :ok
|
|
9
|
+
|
|
10
|
+
def self.ok(ast:, input:) = new(ok: true, ast:, input:)
|
|
11
|
+
|
|
12
|
+
def self.nok(input:, error:, name: nil)
|
|
13
|
+
error = error + " in parser: #{name}" if name
|
|
14
|
+
new(ok: false, input:, error:)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def deconstruct_keys(*, **) = to_h
|
|
18
|
+
|
|
19
|
+
def map(&blk)
|
|
20
|
+
return self unless ok
|
|
21
|
+
self.class.ok(ast: blk.(ast), input:)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def merge(ast: nil, error: nil, input: nil)
|
|
25
|
+
@ast = ast if ast
|
|
26
|
+
@error = error if error
|
|
27
|
+
@input = input if input
|
|
28
|
+
self
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def or(input:, error:, name: nil) = self.class.nok(input:, error:, name:)
|
|
32
|
+
|
|
33
|
+
def reduce(values, &blk)
|
|
34
|
+
result = self
|
|
35
|
+
values.each do |ele|
|
|
36
|
+
result = blk.(result, ele)
|
|
37
|
+
break result unless result.ok
|
|
38
|
+
end
|
|
39
|
+
result
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def to_h = {ast:, error:, input:, ok:}
|
|
43
|
+
|
|
44
|
+
def to_s = inspect
|
|
45
|
+
|
|
46
|
+
def update(&updater)
|
|
47
|
+
raise IllegalState, "must not update an error result" unless ok
|
|
48
|
+
map(&updater)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def update_or(input:, error:, name: nil, &updater)
|
|
52
|
+
return map(&updater) if ok
|
|
53
|
+
|
|
54
|
+
self.class.nok(input:, error:, name:)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def while(input: nil, error: nil, name: nil, &blk)
|
|
58
|
+
result = self
|
|
59
|
+
count = 0
|
|
60
|
+
loop do
|
|
61
|
+
return input ? self.class.nok(input:, error:, name:) : result unless result.ok
|
|
62
|
+
result = blk.(self, count)
|
|
63
|
+
count += 1
|
|
64
|
+
end
|
|
65
|
+
result
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
def initialize(ok:, input:, ast: nil, error: nil)
|
|
70
|
+
@ast = ast
|
|
71
|
+
@error = error
|
|
72
|
+
@input = input
|
|
73
|
+
@ok = ok
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
metadata
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: l43_rmap
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Robert Dober
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 2026-06-03 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: ostruct
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.6.3
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.6.3
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: l43_open_object
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 0.3.0
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 0.3.0
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: l43_simple_color
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 0.2.3
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 0.2.3
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: l43_peg
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: 0.3.1
|
|
61
|
+
type: :runtime
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 0.3.1
|
|
68
|
+
description: 'A hybrid between awk and grep
|
|
69
|
+
|
|
70
|
+
'
|
|
71
|
+
email: robert.dober@gmail.com
|
|
72
|
+
executables:
|
|
73
|
+
- rmap
|
|
74
|
+
extensions: []
|
|
75
|
+
extra_rdoc_files: []
|
|
76
|
+
files:
|
|
77
|
+
- LiCenSE
|
|
78
|
+
- README.md
|
|
79
|
+
- bin/rmap
|
|
80
|
+
- lib/enumerable.rb
|
|
81
|
+
- lib/l43_rmap.rb
|
|
82
|
+
- lib/l43_rmap/ast.rb
|
|
83
|
+
- lib/l43_rmap/chunk.rb
|
|
84
|
+
- lib/l43_rmap/cli.rb
|
|
85
|
+
- lib/l43_rmap/cli/color.rb
|
|
86
|
+
- lib/l43_rmap/cli/help.rb
|
|
87
|
+
- lib/l43_rmap/compiler.rb
|
|
88
|
+
- lib/l43_rmap/evaluator.rb
|
|
89
|
+
- lib/l43_rmap/evaluator/evaluations.rb
|
|
90
|
+
- lib/l43_rmap/function.rb
|
|
91
|
+
- lib/l43_rmap/functions.rb
|
|
92
|
+
- lib/l43_rmap/functions/predefined.rb
|
|
93
|
+
- lib/l43_rmap/functions/predefined/shell.rb
|
|
94
|
+
- lib/l43_rmap/parsing/chunk_parser.rb
|
|
95
|
+
- lib/l43_rmap/parsing/input.rb
|
|
96
|
+
- lib/l43_rmap/parsing/parse_state.rb
|
|
97
|
+
- lib/l43_rmap/parsing/rgx_parser.rb
|
|
98
|
+
- lib/l43_rmap/parsing/rgx_parsers.rb
|
|
99
|
+
- lib/l43_rmap/predefined_patterns.rb
|
|
100
|
+
- lib/l43_rmap/runtime.rb
|
|
101
|
+
- lib/l43_rmap/runtime/line_time.rb
|
|
102
|
+
- lib/l43_rmap/version.rb
|
|
103
|
+
- lib/peg.backup/all.rb
|
|
104
|
+
- lib/peg.backup/combinators.rb
|
|
105
|
+
- lib/peg.backup/combinators/implementation.rb
|
|
106
|
+
- lib/peg.backup/parser.rb
|
|
107
|
+
- lib/peg.backup/parser/input.rb
|
|
108
|
+
- lib/peg.backup/parsers.rb
|
|
109
|
+
- lib/peg.backup/parsers/advanced_parsers.rb
|
|
110
|
+
- lib/peg.backup/parsers/base_parsers.rb
|
|
111
|
+
- lib/peg.backup/parsers/common_parsers.rb
|
|
112
|
+
- lib/peg.backup/parsers/true_set.rb
|
|
113
|
+
- lib/peg.backup/result.rb
|
|
114
|
+
homepage: https://codeberg.org/lab419/rmap
|
|
115
|
+
licenses:
|
|
116
|
+
- AGPL-3.0-or-later
|
|
117
|
+
metadata: {}
|
|
118
|
+
rdoc_options: []
|
|
119
|
+
require_paths:
|
|
120
|
+
- lib
|
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
|
+
requirements:
|
|
123
|
+
- - ">="
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: 4.0.2
|
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
131
|
+
requirements: []
|
|
132
|
+
rubygems_version: 4.0.10
|
|
133
|
+
specification_version: 4
|
|
134
|
+
summary: A hybrid between awk and grep
|
|
135
|
+
test_files: []
|