srl_ruby 0.4.14 → 0.4.15
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 +6 -1
- data/lib/regex/character.rb +9 -9
- data/lib/regex/multiplicity.rb +1 -0
- data/lib/srl_ruby/ast_builder.rb +12 -0
- data/lib/srl_ruby/grammar.rb +1 -1
- data/lib/srl_ruby/tokenizer.rb +30 -3
- data/lib/srl_ruby/version.rb +2 -1
- data/srl_ruby.gemspec +5 -5
- metadata +33 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af00786c71ac6736bb80041630395c02bf7e86a8a15c4601b3010edefadc7d21
|
4
|
+
data.tar.gz: ac70e3dc3bdd7ce80e84e9d2c5c72b3f45d4664fb1d47d4e12e85d57b24c3aa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42229711b0814750b89ed47ff893defbc51ae40463613f85c3c3d82afff577984452eb8039439ebec6813708f892cf657ed338df6170d0ab0acc411a96cc471f
|
7
|
+
data.tar.gz: dd628a6cdd006763a00a5c82950bc5721bf4f9ee6a065b88f29f0dda9a0161bd7e5613dc3379f30479b3866fbca77b454afe2919084a633cc326a5195b3082f4
|
data/CHANGELOG.md
CHANGED
data/lib/regex/character.rb
CHANGED
@@ -41,13 +41,13 @@ module Regex # This module is used as a namespace
|
|
41
41
|
# codepoint value.
|
42
42
|
# Examples:
|
43
43
|
# Initializing with codepoint value...
|
44
|
-
#
|
44
|
+
# Regex::Character.new(0x3a3) # Represents: Σ
|
45
45
|
# (Unicode GREEK CAPITAL LETTER SIGMA)
|
46
|
-
#
|
46
|
+
# Regex::Character.new(931) # Also represents: Σ (931 dec == 3a3 hex)
|
47
47
|
#
|
48
48
|
# Initializing with a single character string
|
49
|
-
#
|
50
|
-
#
|
49
|
+
# Regex::Character.new(?\u03a3) # Also represents: Σ
|
50
|
+
# Regex::Character.new('Σ') # Obviously, represents a Σ
|
51
51
|
#
|
52
52
|
# Initializing with an escape sequence string
|
53
53
|
# Recognized escaped characters are: \a (alarm, 0x07), \n (newline, 0xA),
|
@@ -56,8 +56,8 @@ module Regex # This module is used as a namespace
|
|
56
56
|
# \uXXXX where XXXX is a 4 hex digits integer value, \u{X...}, \ooo (octal)
|
57
57
|
# \xXX (hex)
|
58
58
|
# Any other escaped character will be treated as a literal character
|
59
|
-
#
|
60
|
-
#
|
59
|
+
# Regex::Character.new('\n') # Represents a newline
|
60
|
+
# Regex::Character.new('\u03a3') # Represents a Σ
|
61
61
|
def initialize(aValue)
|
62
62
|
super()
|
63
63
|
case aValue
|
@@ -80,7 +80,7 @@ module Regex # This module is used as a namespace
|
|
80
80
|
|
81
81
|
# Convertion method that returns a character given a codepoint (integer) value.
|
82
82
|
# Example:
|
83
|
-
#
|
83
|
+
# Regex::Character::codepoint2char(0x3a3) # Returns: Σ (
|
84
84
|
# The Unicode GREEK CAPITAL LETTER SIGMA)
|
85
85
|
def self.codepoint2char(aCodepoint)
|
86
86
|
[aCodepoint].pack('U') # Remark: chr() fails with codepoints > 256
|
@@ -88,7 +88,7 @@ module Regex # This module is used as a namespace
|
|
88
88
|
|
89
89
|
# Convertion method that returns the codepoint for the given single character.
|
90
90
|
# Example:
|
91
|
-
#
|
91
|
+
# Regex::Character::char2codepoint('Σ') # Returns: 0x3a3
|
92
92
|
def self.char2codepoint(aChar)
|
93
93
|
aChar.ord
|
94
94
|
end
|
@@ -102,7 +102,7 @@ module Regex # This module is used as a namespace
|
|
102
102
|
# \xXX (hex)
|
103
103
|
# Any other escaped character will be treated as a literal character
|
104
104
|
# Example:
|
105
|
-
#
|
105
|
+
# Regex::Character::esc2codepoint('\n') # Returns: 0xd
|
106
106
|
def self.esc2codepoint(esc_seq)
|
107
107
|
msg = "Escape sequence #{esc_seq} does not begin with a backslash (\\)."
|
108
108
|
raise StandardError, msg unless esc_seq[0] == '\\'
|
data/lib/regex/multiplicity.rb
CHANGED
@@ -70,6 +70,7 @@ module Regex # This module is used as a namespace
|
|
70
70
|
end
|
71
71
|
|
72
72
|
# Validation method. Return the validated lower bound value
|
73
|
+
# @param anUpperBound [Integer, Symbol] integer or :more symbol
|
73
74
|
def valid_upper_bound(anUpperBound)
|
74
75
|
err_msg = "Invalid upper bound of repetition count #{anUpperBound}"
|
75
76
|
unless anUpperBound.kind_of?(Integer) || (anUpperBound == :more)
|
data/lib/srl_ruby/ast_builder.rb
CHANGED
@@ -12,8 +12,10 @@ module SrlRuby
|
|
12
12
|
# (say, a parse tree) from simpler objects (terminal and non-terminal
|
13
13
|
# nodes) and using a step by step approach.
|
14
14
|
class ASTBuilder < Rley::ParseRep::ASTBaseBuilder
|
15
|
+
# @return [Hash]
|
15
16
|
Terminal2NodeClass = {}.freeze
|
16
17
|
|
18
|
+
# @return [Array<Symbol>] Options for the regular expression
|
17
19
|
attr_reader :options
|
18
20
|
|
19
21
|
# Create a new AST builder instance.
|
@@ -24,6 +26,7 @@ module SrlRuby
|
|
24
26
|
end
|
25
27
|
|
26
28
|
# Notification that the parse tree construction is complete.
|
29
|
+
# @return [void]
|
27
30
|
def done!
|
28
31
|
apply_options
|
29
32
|
super
|
@@ -31,10 +34,12 @@ module SrlRuby
|
|
31
34
|
|
32
35
|
protected
|
33
36
|
|
37
|
+
# @return [Hash]
|
34
38
|
def terminal2node
|
35
39
|
Terminal2NodeClass
|
36
40
|
end
|
37
41
|
|
42
|
+
# @return [void]
|
38
43
|
def apply_options
|
39
44
|
tree_root = result.root
|
40
45
|
regexp_opts = []
|
@@ -62,12 +67,17 @@ module SrlRuby
|
|
62
67
|
Rley::PTree::TerminalNode.new(aToken, aTokenPosition)
|
63
68
|
end
|
64
69
|
|
70
|
+
# @param lowerBound [Integer]
|
71
|
+
# @param upperBound [Integer, Symbol]
|
72
|
+
# @return [Regex::Multiplicity]
|
65
73
|
def multiplicity(lowerBound, upperBound)
|
66
74
|
Regex::Multiplicity.new(lowerBound, upperBound, :greedy)
|
67
75
|
end
|
68
76
|
|
69
77
|
# rubocop: disable Style/OptionalBooleanParameter
|
70
78
|
|
79
|
+
# @param aString [String]
|
80
|
+
# @param [Array<Regex::Character>, Regex::Concatenation, Regex::Character]
|
71
81
|
def string_literal(aString, to_escape = true)
|
72
82
|
if aString.size > 1
|
73
83
|
chars = []
|
@@ -90,6 +100,8 @@ module SrlRuby
|
|
90
100
|
end
|
91
101
|
# rubocop: enable Style/OptionalBooleanParameter
|
92
102
|
|
103
|
+
# @param lowerBound [Integer]
|
104
|
+
# @param upperBound [Integer]
|
93
105
|
def char_range(lowerBound, upperBound)
|
94
106
|
lower = Regex::Character.new(lowerBound)
|
95
107
|
upper = Regex::Character.new(upperBound)
|
data/lib/srl_ruby/grammar.rb
CHANGED
data/lib/srl_ruby/tokenizer.rb
CHANGED
@@ -17,14 +17,31 @@ module SrlRuby
|
|
17
17
|
# Delimiters: parentheses '(' and ')'
|
18
18
|
# Separators: comma (optional)
|
19
19
|
class Tokenizer
|
20
|
+
# @return [Regexp] Matches a SRL character class
|
20
21
|
PATT_CHAR_CLASS = /[^,"\s]{2,}/
|
22
|
+
|
23
|
+
# @return [Regexp] Matches single digit
|
21
24
|
PATT_DIGIT_LIT = /[0-9]((?=\s|,|\))|$)/
|
25
|
+
|
26
|
+
# @return [Regexp] Matches a SRL identifier
|
22
27
|
PATT_IDENTIFIER = /[a-zA-Z_][a-zA-Z0-9_]+/
|
23
|
-
|
28
|
+
|
29
|
+
# @return [Regexp] Matches a decimal integer. An integer has 2..* digits
|
30
|
+
PATT_INTEGER = /[0-9]{2,}((?=\s|,|\))|$)/
|
31
|
+
|
32
|
+
# @return [Regexp] Matches a single letter.
|
24
33
|
PATT_LETTER_LIT = /[a-zA-Z]((?=\s|,|\))|$)/
|
34
|
+
|
35
|
+
# @return [Regexp] Matches a new line (cross-platform)
|
25
36
|
PATT_NEWLINE = /(?:\r\n)|\r|\n/
|
26
|
-
|
27
|
-
|
37
|
+
|
38
|
+
# @return [Regexp] Matches a text enclosed in double quotes
|
39
|
+
PATT_STR_DBL_QUOTE = /"(?:\\"|[^"])*"/
|
40
|
+
|
41
|
+
# @return [Regexp] Matches a text enclosed in single quotes
|
42
|
+
PATT_STR_SNGL_QUOTE = /'(?:\\'|[^'])*'/
|
43
|
+
|
44
|
+
# @return [Regexp] Matches SRL blank(s)
|
28
45
|
PATT_WHITESPACE = /[ \t\f]+/
|
29
46
|
|
30
47
|
# @return [StringScanner]
|
@@ -36,6 +53,7 @@ module SrlRuby
|
|
36
53
|
# @return [Integer] offset of start of current line within input
|
37
54
|
attr_reader(:line_start)
|
38
55
|
|
56
|
+
# @return [{String => String}] Mapping special single characters to symbolic names.
|
39
57
|
Lexeme2name = {
|
40
58
|
'(' => 'LPAREN',
|
41
59
|
')' => 'RPAREN',
|
@@ -43,6 +61,7 @@ module SrlRuby
|
|
43
61
|
}.freeze
|
44
62
|
|
45
63
|
# Here are all the SRL keywords (in uppercase)
|
64
|
+
# @return [{String => String}]
|
46
65
|
Keywords = %w[
|
47
66
|
ALL
|
48
67
|
ALREADY
|
@@ -102,6 +121,7 @@ module SrlRuby
|
|
102
121
|
WORD
|
103
122
|
].to_h { |x| [x, x] }
|
104
123
|
|
124
|
+
# Exception class for scanner/tokenizer failures.
|
105
125
|
class ScanError < StandardError; end
|
106
126
|
|
107
127
|
# Constructor. Initialize a tokenizer for SRL.
|
@@ -112,6 +132,8 @@ module SrlRuby
|
|
112
132
|
@line_start = 0
|
113
133
|
end
|
114
134
|
|
135
|
+
# Returns the sequence of tokens recognized from the input text given at initialization.
|
136
|
+
# @return [Array<Rley::Lexical::Token>]
|
115
137
|
def tokens
|
116
138
|
tok_sequence = []
|
117
139
|
until @scanner.eos?
|
@@ -124,6 +146,7 @@ module SrlRuby
|
|
124
146
|
|
125
147
|
private
|
126
148
|
|
149
|
+
# @return [Rley::Lexical::Token]
|
127
150
|
def _next_token
|
128
151
|
token = nil
|
129
152
|
|
@@ -170,6 +193,9 @@ module SrlRuby
|
|
170
193
|
token
|
171
194
|
end
|
172
195
|
|
196
|
+
# @param aSymbolName [String]
|
197
|
+
# @param aLexeme [String]
|
198
|
+
# @return [Rley::Lexical::Token]
|
173
199
|
def build_token(aSymbolName, aLexeme)
|
174
200
|
begin
|
175
201
|
col = scanner.pos - aLexeme.size - @line_start + 1
|
@@ -184,6 +210,7 @@ module SrlRuby
|
|
184
210
|
end
|
185
211
|
|
186
212
|
# Event: next line detected.
|
213
|
+
# @return [Integer] Current scanning position (offset)
|
187
214
|
def next_line_scanned
|
188
215
|
@lineno += 1
|
189
216
|
@line_start = scanner.pos
|
data/lib/srl_ruby/version.rb
CHANGED
data/srl_ruby.gemspec
CHANGED
@@ -68,12 +68,12 @@ SUMMARY
|
|
68
68
|
spec.required_ruby_version = '>= 3.2.0'
|
69
69
|
|
70
70
|
# Runtime dependencies
|
71
|
-
spec.add_dependency 'rley', '~> 0.
|
71
|
+
spec.add_dependency 'rley', '~> 0.9', '>= 0.9.02'
|
72
72
|
|
73
73
|
# Development dependencies
|
74
|
-
spec.add_development_dependency 'bundler', '>= 2.2.0'
|
75
|
-
spec.add_development_dependency 'cucumber', '
|
76
|
-
spec.add_development_dependency 'rake', '
|
77
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
74
|
+
spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.0'
|
75
|
+
spec.add_development_dependency 'cucumber', '~> 9'
|
76
|
+
spec.add_development_dependency 'rake', '~> 13'
|
77
|
+
spec.add_development_dependency 'rspec', '~> 3', '>= 3.10.0'
|
78
78
|
spec.metadata = { 'rubygems_mfa_required' => 'true' }
|
79
79
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: srl_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-03-20 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rley
|
@@ -15,18 +15,27 @@ dependencies:
|
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: 0.
|
18
|
+
version: '0.9'
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.9.02
|
19
22
|
type: :runtime
|
20
23
|
prerelease: false
|
21
24
|
version_requirements: !ruby/object:Gem::Requirement
|
22
25
|
requirements:
|
23
26
|
- - "~>"
|
24
27
|
- !ruby/object:Gem::Version
|
25
|
-
version: 0.
|
28
|
+
version: '0.9'
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 0.9.02
|
26
32
|
- !ruby/object:Gem::Dependency
|
27
33
|
name: bundler
|
28
34
|
requirement: !ruby/object:Gem::Requirement
|
29
35
|
requirements:
|
36
|
+
- - "~>"
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '2.2'
|
30
39
|
- - ">="
|
31
40
|
- !ruby/object:Gem::Version
|
32
41
|
version: 2.2.0
|
@@ -34,6 +43,9 @@ dependencies:
|
|
34
43
|
prerelease: false
|
35
44
|
version_requirements: !ruby/object:Gem::Requirement
|
36
45
|
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '2.2'
|
37
49
|
- - ">="
|
38
50
|
- !ruby/object:Gem::Version
|
39
51
|
version: 2.2.0
|
@@ -41,44 +53,50 @@ dependencies:
|
|
41
53
|
name: cucumber
|
42
54
|
requirement: !ruby/object:Gem::Requirement
|
43
55
|
requirements:
|
44
|
-
- - "
|
56
|
+
- - "~>"
|
45
57
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
58
|
+
version: '9'
|
47
59
|
type: :development
|
48
60
|
prerelease: false
|
49
61
|
version_requirements: !ruby/object:Gem::Requirement
|
50
62
|
requirements:
|
51
|
-
- - "
|
63
|
+
- - "~>"
|
52
64
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
65
|
+
version: '9'
|
54
66
|
- !ruby/object:Gem::Dependency
|
55
67
|
name: rake
|
56
68
|
requirement: !ruby/object:Gem::Requirement
|
57
69
|
requirements:
|
58
|
-
- - "
|
70
|
+
- - "~>"
|
59
71
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
72
|
+
version: '13'
|
61
73
|
type: :development
|
62
74
|
prerelease: false
|
63
75
|
version_requirements: !ruby/object:Gem::Requirement
|
64
76
|
requirements:
|
65
|
-
- - "
|
77
|
+
- - "~>"
|
66
78
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
79
|
+
version: '13'
|
68
80
|
- !ruby/object:Gem::Dependency
|
69
81
|
name: rspec
|
70
82
|
requirement: !ruby/object:Gem::Requirement
|
71
83
|
requirements:
|
72
84
|
- - "~>"
|
73
85
|
- !ruby/object:Gem::Version
|
74
|
-
version: '3
|
86
|
+
version: '3'
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.10.0
|
75
90
|
type: :development
|
76
91
|
prerelease: false
|
77
92
|
version_requirements: !ruby/object:Gem::Requirement
|
78
93
|
requirements:
|
79
94
|
- - "~>"
|
80
95
|
- !ruby/object:Gem::Version
|
81
|
-
version: '3
|
96
|
+
version: '3'
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 3.10.0
|
82
100
|
description: |2
|
83
101
|
A compiler and library that transforms highly readable Simple Regex Language
|
84
102
|
patterns into regular expressions.
|
@@ -205,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
223
|
- !ruby/object:Gem::Version
|
206
224
|
version: '0'
|
207
225
|
requirements: []
|
208
|
-
rubygems_version: 3.6.
|
226
|
+
rubygems_version: 3.6.6
|
209
227
|
specification_version: 4
|
210
228
|
summary: A parser for the [Simple Regex Language](https://simple-regex.com/). It translates
|
211
229
|
patterns expressed in SRL into plain Ruby Regexp objects or in regex literals. Use
|