iregexp 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/iregexp.gemspec +2 -2
- data/lib/iregexp.rb +1 -1
- data/test-data/simple.irl +49 -0
- data/test-data/simple.out +114 -0
- metadata +3 -3
- data/bin/iregexp~ +0 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d81cf113289db245c63cf861b70653dee63e7379e397047db95fe2dc0ecc598
|
4
|
+
data.tar.gz: 29849bd9536dcdceaf05a9f37876666accbf3bad7ff4ff8acb46ec0a9ed9ebff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fee297ccae388370273ee44db8922581d331d258fb8578a0b01f054966733d6ac343ddd2ccc39afeda6b232a2ae67270d42fef64244bd5081b9472933432ea38
|
7
|
+
data.tar.gz: c5587fe22929d89dbfedcec1dbee00939aabe0b3401435d7f76d23b7d29d0055f79df6be5af28cb265bdd52d74adde2c902d21c207526790e38851c2ef1693a5
|
data/iregexp.gemspec
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "iregexp"
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.2"
|
4
4
|
s.summary = "I-Regexp Tools"
|
5
5
|
s.description = %q{iregexp implements converters and miscellaneous tools for I-Regexp}
|
6
6
|
s.author = "Carsten Bormann"
|
7
7
|
s.email = "cabo@tzi.org"
|
8
8
|
s.license = "MIT"
|
9
9
|
s.homepage = "http://github.com/cabo/iregexp"
|
10
|
-
s.files = Dir['lib/**/*.rb'] + %w(iregexp.gemspec) + Dir['data/*'] + Dir['bin/**/*.rb']
|
10
|
+
s.files = Dir['lib/**/*.rb'] + %w(iregexp.gemspec) + Dir['data/*'] + Dir['test-data/*'] + Dir['bin/**/*.rb']
|
11
11
|
s.executables = Dir['bin/*'].map {|x| File.basename(x)}
|
12
12
|
s.required_ruby_version = '>= 3.0'
|
13
13
|
|
data/lib/iregexp.rb
CHANGED
@@ -16,7 +16,7 @@ class IREGEXP
|
|
16
16
|
reason << line
|
17
17
|
reason << "#{'~' * (parser.failure_column - 1)}^"
|
18
18
|
end
|
19
|
-
reason.join("\n").gsub(/[\u0000-\u0009\u000b
|
19
|
+
reason.join("\n").gsub(/[\u0000-\u0009\u000b-\u001f\u007f]/) {|c| "\\u%04x" % c.ord}
|
20
20
|
end
|
21
21
|
|
22
22
|
SAFE_FN = /\A[-._a-zA-Z0-9]+\z/
|
@@ -0,0 +1,49 @@
|
|
1
|
+
=
|
2
|
+
=.
|
3
|
+
=a
|
4
|
+
=🤔
|
5
|
+
-\
|
6
|
+
-\v
|
7
|
+
-\\\
|
8
|
+
-\\\v
|
9
|
+
-\\\z
|
10
|
+
-\ca
|
11
|
+
=\(\)\*\+\.\?\[\\
|
12
|
+
=\]\{\|\}\t\r\n
|
13
|
+
=a*
|
14
|
+
=🤔*
|
15
|
+
-a**
|
16
|
+
=a|b
|
17
|
+
=aa|bb
|
18
|
+
=aa|
|
19
|
+
=|bb
|
20
|
+
=aa|bb*
|
21
|
+
=aa|bb+
|
22
|
+
=aa|bb?
|
23
|
+
=aa|bb{6}
|
24
|
+
=aa|bb{6,}
|
25
|
+
=aa|bb{6,8}
|
26
|
+
=(aa)
|
27
|
+
-aa)
|
28
|
+
-(aa
|
29
|
+
=aa(bb|cc)dd
|
30
|
+
-aabb|cc)dd
|
31
|
+
-aa(bb|ccdd
|
32
|
+
=[abc]
|
33
|
+
-[a
|
34
|
+
-a]
|
35
|
+
=[a🤔b]
|
36
|
+
=[^abc]
|
37
|
+
=[ab-f]
|
38
|
+
=[^ab-f]
|
39
|
+
=[^-ab-f]
|
40
|
+
=[-ab-f]
|
41
|
+
=[ab-f-]
|
42
|
+
=[a\n-\r-]
|
43
|
+
=\p{Nd}
|
44
|
+
=\P{Ll}
|
45
|
+
=\P{L}
|
46
|
+
=\p{Co}
|
47
|
+
*[\p{Nd}]
|
48
|
+
*[\P{Nd}]
|
49
|
+
*[^\p{Nd}\p{Ll}]
|
@@ -0,0 +1,114 @@
|
|
1
|
+
= ["seq"]
|
2
|
+
""
|
3
|
+
=. ["dot"]
|
4
|
+
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t"
|
5
|
+
=a "a"
|
6
|
+
"a"
|
7
|
+
=🤔 "🤔"
|
8
|
+
"🤔"
|
9
|
+
-\ Expected one of [\(-\+], [\--\.], "?", [\[-\^], "n", "r", "t", [\{-\}] at line 1, column 2 (byte 2):
|
10
|
+
\
|
11
|
+
~^
|
12
|
+
-\v Expected one of [\(-\+], [\--\.], "?", [\[-\^], "n", "r", "t", [\{-\}] at line 1, column 2 (byte 2):
|
13
|
+
\v
|
14
|
+
~^
|
15
|
+
-\\\ Expected one of [\(-\+], [\--\.], "?", [\[-\^], "n", "r", "t", [\{-\}] at line 1, column 4 (byte 4):
|
16
|
+
\\\
|
17
|
+
~~~^
|
18
|
+
-\\\v Expected one of [\(-\+], [\--\.], "?", [\[-\^], "n", "r", "t", [\{-\}] at line 1, column 4 (byte 4):
|
19
|
+
\\\v
|
20
|
+
~~~^
|
21
|
+
-\\\z Expected one of [\(-\+], [\--\.], "?", [\[-\^], "n", "r", "t", [\{-\}] at line 1, column 4 (byte 4):
|
22
|
+
\\\z
|
23
|
+
~~~^
|
24
|
+
-\ca Expected one of [\(-\+], [\--\.], "?", [\[-\^], "n", "r", "t", [\{-\}] at line 1, column 2 (byte 2):
|
25
|
+
\ca
|
26
|
+
~^
|
27
|
+
=\(\)\*\+\.\?\[\\ ["seq", "(", ")", "*", "+", ".", "?", "[", "\\"]
|
28
|
+
"()*+.?[\\"
|
29
|
+
=\]\{\|\}\t\r\n ["seq", "]", "{", "|", "}", "\t", "\r", "\n"]
|
30
|
+
"]{|}\t\r\n"
|
31
|
+
=a* ["rep", 0, false, "a"]
|
32
|
+
"", "a", "aa", "aaa", "aaaa"
|
33
|
+
=🤔* ["rep", 0, false, "🤔"]
|
34
|
+
"", "🤔", "🤔🤔", "🤔🤔🤔", "🤔🤔🤔🤔"
|
35
|
+
-a** Expected one of [\u0000-'], [,-\-], [/->], [@-Z], [\^-z], [~-], ".", "\\", "\\p{", "\\P{", "[", "(", "|" at line 1, column 3 (byte 3):
|
36
|
+
a**
|
37
|
+
~~^
|
38
|
+
=a|b ["alt", "a", "b"]
|
39
|
+
"a", "b"
|
40
|
+
=aa|bb ["alt", ["seq", "a", "a"], ["seq", "b", "b"]]
|
41
|
+
"aa", "bb"
|
42
|
+
=aa| ["alt", ["seq", "a", "a"], ["seq"]]
|
43
|
+
"aa", ""
|
44
|
+
=|bb ["alt", ["seq"], ["seq", "b", "b"]]
|
45
|
+
"", "bb"
|
46
|
+
=aa|bb* ["alt", ["seq", "a", "a"], ["seq", "b", ["rep", 0, false, "b"]]]
|
47
|
+
"aa", "b", "bb", "bbb", "bbbb", "bbbbb"
|
48
|
+
=aa|bb+ ["alt", ["seq", "a", "a"], ["seq", "b", ["rep", 1, false, "b"]]]
|
49
|
+
"aa", "bb", "bbb", "bbbb", "bbbbb", "bbbbbb"
|
50
|
+
=aa|bb? ["alt", ["seq", "a", "a"], ["seq", "b", ["rep", 0, 1, "b"]]]
|
51
|
+
"aa", "b", "bb"
|
52
|
+
=aa|bb{6} ["alt", ["seq", "a", "a"], ["seq", "b", ["rep", 6, 6, "b"]]]
|
53
|
+
"aa", "bbbbbbb"
|
54
|
+
=aa|bb{6,} ["alt", ["seq", "a", "a"], ["seq", "b", ["rep", 6, false, "b"]]]
|
55
|
+
"aa", "bbbbbbb", "bbbbbbbb", "bbbbbbbbb", "bbbbbbbbbb", "bbbbbbbbbbb"
|
56
|
+
=aa|bb{6,8} ["alt", ["seq", "a", "a"], ["seq", "b", ["rep", 6, 8, "b"]]]
|
57
|
+
"aa", "bbbbbbb", "bbbbbbbb", "bbbbbbbbb"
|
58
|
+
=(aa) ["seq", "a", "a"]
|
59
|
+
"aa"
|
60
|
+
-aa) Expected one of [\*-\+], "?", "{", [\u0000-'], [,-\-], [/->], [@-Z], [\^-z], [~-], ".", "\\", "\\p{", "\\P{", "[", "(", "|" at line 1, column 3 (byte 3):
|
61
|
+
aa)
|
62
|
+
~~^
|
63
|
+
-(aa Expected one of [\*-\+], "?", "{", [\u0000-'], [,-\-], [/->], [@-Z], [\^-z], [~-], ".", "\\", "\\p{", "\\P{", "[", "(", "|", ")" at line 1, column 4 (byte 4):
|
64
|
+
(aa
|
65
|
+
~~~^
|
66
|
+
=aa(bb|cc)dd ["seq", "a", "a", ["alt", ["seq", "b", "b"], ["seq", "c", "c"]], "d", "d"]
|
67
|
+
"aabbdd", "aaccdd"
|
68
|
+
-aabb|cc)dd Expected one of [\*-\+], "?", "{", [\u0000-'], [,-\-], [/->], [@-Z], [\^-z], [~-], ".", "\\", "\\p{", "\\P{", "[", "(", "|" at line 1, column 8 (byte 8):
|
69
|
+
aabb|cc)dd
|
70
|
+
~~~~~~~^
|
71
|
+
-aa(bb|ccdd Expected one of [\*-\+], "?", "{", [\u0000-'], [,-\-], [/->], [@-Z], [\^-z], [~-], ".", "\\", "\\p{", "\\P{", "[", "(", "|", ")" at line 1, column 11 (byte 11):
|
72
|
+
aa(bb|ccdd
|
73
|
+
~~~~~~~~~~^
|
74
|
+
=[abc] ["pos", "a", "b", "c"]
|
75
|
+
"a", "b", "c"
|
76
|
+
-[a Expected one of "-", [\u0000-,], [\.-Z], [\^-], "\\", "\\p{", "\\P{", "]" at line 1, column 3 (byte 3):
|
77
|
+
[a
|
78
|
+
~~^
|
79
|
+
-a] Expected one of [\*-\+], "?", "{", [\u0000-'], [,-\-], [/->], [@-Z], [\^-z], [~-], ".", "\\", "\\p{", "\\P{", "[", "(", "|" at line 1, column 2 (byte 2):
|
80
|
+
a]
|
81
|
+
~^
|
82
|
+
=[a🤔b] ["pos", "a", "🤔", "b"]
|
83
|
+
"a", "🤔", "b"
|
84
|
+
=[^abc] ["neg", "a", "b", "c"]
|
85
|
+
"\n", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v"
|
86
|
+
=[ab-f] ["pos", "a", ["-", "b", "f"]]
|
87
|
+
"a", "b", "c", "d", "e", "f"
|
88
|
+
=[^ab-f] ["neg", "a", ["-", "b", "f"]]
|
89
|
+
"\n", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y"
|
90
|
+
=[^-ab-f] ["neg", "-", "a", ["-", "b", "f"]]
|
91
|
+
"\n", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y"
|
92
|
+
=[-ab-f] ["pos", "-", "a", ["-", "b", "f"]]
|
93
|
+
"-", "a", "b", "c", "d", "e", "f"
|
94
|
+
=[ab-f-] ["pos", "a", ["-", "b", "f"], "-"]
|
95
|
+
"a", "b", "c", "d", "e", "f", "-"
|
96
|
+
=[a\n-\r-] ["pos", "a", ["-", "\n", "\r"], "-"]
|
97
|
+
"a", "\n", "\u000b", "\f", "\r", "-"
|
98
|
+
=\p{Nd} ["p", "Nd"]
|
99
|
+
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"
|
100
|
+
=\P{Ll} ["P", "Ll"]
|
101
|
+
"\n", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S"
|
102
|
+
=\P{L} ["P", "L"]
|
103
|
+
"\n", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "!", "\"", "#", "%", "&", "'", "(", ")", "*"
|
104
|
+
=\p{Co} ["p", "Co"]
|
105
|
+
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
|
106
|
+
*[\p{Nd}] ["pos", ["p", "Nd"]]
|
107
|
+
bug in regexp example generator:
|
108
|
+
"p", "{", "N", "d", "}"
|
109
|
+
*[\P{Nd}] ["pos", ["P", "Nd"]]
|
110
|
+
bug in regexp example generator:
|
111
|
+
"P", "{", "N", "d", "}"
|
112
|
+
*[^\p{Nd}\p{Ll}] ["neg", ["p", "Nd"], ["p", "Ll"]]
|
113
|
+
bug in regexp example generator:
|
114
|
+
"\n", "a", "b", "c", "e", "f", "g", "h", "i", "j", "k", "m", "n", "o", "q", "r", "s", "t", "u", "v"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iregexp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
@@ -70,17 +70,17 @@ description: iregexp implements converters and miscellaneous tools for I-Regexp
|
|
70
70
|
email: cabo@tzi.org
|
71
71
|
executables:
|
72
72
|
- iregexp
|
73
|
-
- iregexp~
|
74
73
|
extensions: []
|
75
74
|
extra_rdoc_files: []
|
76
75
|
files:
|
77
76
|
- bin/iregexp
|
78
|
-
- bin/iregexp~
|
79
77
|
- iregexp.gemspec
|
80
78
|
- lib/iregexp.rb
|
81
79
|
- lib/parser/iregexp-util.rb
|
82
80
|
- lib/parser/iregexpgrammar.rb
|
83
81
|
- lib/writer/iregexp-writer.rb
|
82
|
+
- test-data/simple.irl
|
83
|
+
- test-data/simple.out
|
84
84
|
homepage: http://github.com/cabo/iregexp
|
85
85
|
licenses:
|
86
86
|
- MIT
|
data/bin/iregexp~
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'pp'
|
3
|
-
require 'yaml'
|
4
|
-
require 'treetop'
|
5
|
-
require 'json'
|
6
|
-
|
7
|
-
require_relative '../lib/jpt'
|
8
|
-
|
9
|
-
Encoding.default_external = Encoding::UTF_8
|
10
|
-
require 'optparse'
|
11
|
-
require 'ostruct'
|
12
|
-
|
13
|
-
FUNCSIG_CHARS = {"l" => :logical, "n" => :nodes, "v" => :value}
|
14
|
-
|
15
|
-
$options = OpenStruct.new
|
16
|
-
begin
|
17
|
-
op = OptionParser.new do |opts|
|
18
|
-
opts.banner = "Usage: jpt.rb [options] file.jp"
|
19
|
-
|
20
|
-
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
21
|
-
$options.verbose = v
|
22
|
-
end
|
23
|
-
opts.on("-l", "--[no-]lines", "multi-line mode") do |v|
|
24
|
-
$options.lines = v
|
25
|
-
end
|
26
|
-
opts.on("-q", "--[no-]test", "test-file mode") do |v|
|
27
|
-
$options.test = v
|
28
|
-
end
|
29
|
-
opts.on("-fFUNCSIG", "--[no-]f=FUNCSIG", "add function signature name=rppp") do |v|
|
30
|
-
fail "funcsig format must be name=rppp" unless v =~ /\A([a-z][_a-z0-9]*)-([lnv]+)\z/
|
31
|
-
|
32
|
-
JPTType.add_funcsig($1, $2)
|
33
|
-
end
|
34
|
-
opts.on("-tFMT", "--to=FMT", [:basic, :neat, :json, :yaml, :enum, :jp], "Target format") do |v|
|
35
|
-
$options.target = v
|
36
|
-
end
|
37
|
-
end
|
38
|
-
op.parse!
|
39
|
-
rescue Exception => e
|
40
|
-
warn e
|
41
|
-
exit 1
|
42
|
-
end
|
43
|
-
|
44
|
-
if ARGV == []
|
45
|
-
puts op
|
46
|
-
exit 1
|
47
|
-
end
|
48
|
-
jp_file = ARGF.read
|
49
|
-
|
50
|
-
if $options.test
|
51
|
-
argument = query = output = nil
|
52
|
-
jp_file.scan(/((?:^(?:$|[^$=].*)\n)+)|([$].*)|=(.*)|#.*/) do |arg,qy,out|
|
53
|
-
begin
|
54
|
-
if arg
|
55
|
-
argument = JSON.parse(arg)
|
56
|
-
puts
|
57
|
-
puts JSON.dump(argument)
|
58
|
-
elsif qy
|
59
|
-
jpt = JPT.from_jp(qy)
|
60
|
-
output = jpt.apply(argument)
|
61
|
-
print jpt.tree.inspect << " "
|
62
|
-
puts "➔ #{JSON.dump(output)}"
|
63
|
-
elsif out
|
64
|
-
suggested = JSON.parse(out)
|
65
|
-
if output != suggested
|
66
|
-
p [:SUGGESTED, suggested]
|
67
|
-
end
|
68
|
-
end
|
69
|
-
rescue => e
|
70
|
-
warn "*** #{e.detailed_message} #{e.backtrace}"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
elsif $options.lines
|
74
|
-
lines = jp_file.lines(chomp: true)
|
75
|
-
col = lines.map(&:length).max
|
76
|
-
form = "%-#{col}s %s"
|
77
|
-
lines.each do |line|
|
78
|
-
jpt = JPT.from_jp(line)
|
79
|
-
result = jpt.tree.inspect
|
80
|
-
puts form % [line, result]
|
81
|
-
end
|
82
|
-
else
|
83
|
-
|
84
|
-
jpt = JPT.from_jp(jp_file)
|
85
|
-
result = jpt.tree
|
86
|
-
|
87
|
-
case $options.target
|
88
|
-
when :basic, nil
|
89
|
-
pp result
|
90
|
-
when :neat, :json
|
91
|
-
require 'neatjson'
|
92
|
-
puts JSON.neat_generate(result, after_comma: 1, after_colon: 1)
|
93
|
-
when :yaml
|
94
|
-
puts result.to_yaml
|
95
|
-
when :jp
|
96
|
-
require_relative '../lib/writer/jp-writer.rb'
|
97
|
-
puts jpt.to_s
|
98
|
-
else
|
99
|
-
warn ["Unknown target format: ", $options.target].inspect
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|