srl_ruby 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/CHANGELOG.md +5 -0
- data/README.md +8 -5
- data/lib/srl_ruby/ast_builder.rb +3 -2
- data/lib/srl_ruby/srl_token.rb +23 -0
- data/lib/srl_ruby/tokenizer.rb +35 -3
- data/lib/srl_ruby/version.rb +1 -1
- data/lib/srl_ruby.rb +1 -1
- data/srl_ruby.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6ca8e70f473d53992bd449ed2945cc55ebedcff
|
4
|
+
data.tar.gz: 065406740aded7b357712fa67daa4f622627a79c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 174e237267f85e4d0e4d9e714ded189c9a1d46635b8668af469d23c0b5a3709f53e48087486cd5fb8f60861e02de19d44c694224581a9d1071718272574898c6
|
7
|
+
data.tar.gz: 92118db7249a6f66dc88ae66e2ca229a6800b91ba7ac53e692bc452ef87f311a3bb4bbc8fe401f0b2c015d960ecd29015465d9908d633b1425ef08aa1575a77b
|
data/.rspec
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@
|
|
6
6
|
### Fixed
|
7
7
|
### Security
|
8
8
|
|
9
|
+
## [0.1.1] - 2018-03-10
|
10
|
+
### Changed
|
11
|
+
- Parse error location is now given in line number, column number position.
|
12
|
+
- Updated dependencies upon Rley parser.
|
13
|
+
|
9
14
|
## [0.1.0] - 2018-03-08
|
10
15
|
### Added
|
11
16
|
- Version bump. Added new API methods `SrlRuby#load_file` and `SrlRuby#parse`
|
data/README.md
CHANGED
@@ -23,6 +23,12 @@ literally " ",
|
|
23
23
|
one of "AP", literally "M"
|
24
24
|
```
|
25
25
|
|
26
|
+
### Learn more about Simple Regex Language
|
27
|
+
Here are a couple of hyperlinks of interest:
|
28
|
+
[Main SRL website](https://simple-regex.com)
|
29
|
+
[SRL libraries](https://github.com/SimpleRegex)
|
30
|
+
|
31
|
+
|
26
32
|
## Why SRL?
|
27
33
|
Even without knowing SRL, a reader can easily grasp the details of the above SRL expression.
|
28
34
|
This is where SRL shines over the traditional regular expressions: high readability.
|
@@ -57,12 +63,9 @@ one of "AP", literally "M"
|
|
57
63
|
```
|
58
64
|
|
59
65
|
And there is the equivalent regex found by `srl_ruby`:
|
66
|
+
```
|
60
67
|
/(?:(?:0?\d)|(?:1[01])):[0-5]\d [AP]M/
|
61
|
-
|
62
|
-
### More about Simple Regex Language syntax and examples
|
63
|
-
Here are a couple of hyperlinks of interest:
|
64
|
-
[Main SRL website](https://simple-regex.com)
|
65
|
-
[SRL libraries](https://github.com/SimpleRegex)
|
68
|
+
```
|
66
69
|
|
67
70
|
|
68
71
|
## Usage
|
data/lib/srl_ruby/ast_builder.rb
CHANGED
@@ -23,9 +23,10 @@ module SrlRuby
|
|
23
23
|
# Overriding method.
|
24
24
|
# Factory method for creating a node object for the given
|
25
25
|
# input token.
|
26
|
-
# @param
|
26
|
+
# @param _production [Rley::Syntax::Production]
|
27
|
+
# @param _terminal [Rley::Syntax::Terminal] Terminal symbol associated with the token
|
27
28
|
# @param aTokenPosition [Integer] Position of token in the input stream
|
28
|
-
# @param aToken [Token] The input token
|
29
|
+
# @param aToken [Rley::Lexical::Token] The input token
|
29
30
|
def new_leaf_node(_production, _terminal, aTokenPosition, aToken)
|
30
31
|
node = Rley::PTree::TerminalNode.new(aToken, aTokenPosition)
|
31
32
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rley' # Load the Rley gem
|
2
|
+
|
3
|
+
|
4
|
+
module SrlRuby
|
5
|
+
Position = Struct.new(:line, :column) do
|
6
|
+
def to_s()
|
7
|
+
"line #{line}, column #{column}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Specialization of Token class.
|
12
|
+
# It stores the position in (line, row) of the token
|
13
|
+
class SrlToken < Rley::Lexical::Token
|
14
|
+
attr_reader(:position)
|
15
|
+
|
16
|
+
def initialize(theLexeme, aTerminal, aPosition)
|
17
|
+
super(theLexeme, aTerminal)
|
18
|
+
@position = aPosition
|
19
|
+
end
|
20
|
+
end # class
|
21
|
+
end # module
|
22
|
+
|
23
|
+
# End of file
|
data/lib/srl_ruby/tokenizer.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# File: srl_tokenizer.rb
|
2
2
|
# Tokenizer for SRL (Simple Regex Language)
|
3
3
|
require 'strscan'
|
4
|
-
|
4
|
+
require_relative 'srl_token'
|
5
|
+
|
5
6
|
|
6
7
|
module SrlRuby
|
7
8
|
# The tokenizer should recognize:
|
@@ -15,6 +16,7 @@ module SrlRuby
|
|
15
16
|
attr_reader(:scanner)
|
16
17
|
attr_reader(:lineno)
|
17
18
|
attr_reader(:line_start)
|
19
|
+
attr_reader(:column)
|
18
20
|
|
19
21
|
@@lexeme2name = {
|
20
22
|
'(' => 'LPAREN',
|
@@ -80,6 +82,7 @@ module SrlRuby
|
|
80
82
|
def initialize(source)
|
81
83
|
@scanner = StringScanner.new(source)
|
82
84
|
@lineno = 1
|
85
|
+
@line_start = 0
|
83
86
|
end
|
84
87
|
|
85
88
|
def tokens()
|
@@ -131,7 +134,9 @@ module SrlRuby
|
|
131
134
|
|
132
135
|
def build_token(aSymbolName, aLexeme)
|
133
136
|
begin
|
134
|
-
|
137
|
+
col = scanner.pos - aLexeme.size - @line_start + 1
|
138
|
+
pos = Position.new(@lineno, col)
|
139
|
+
token = SrlToken.new(aLexeme, aSymbolName, pos)
|
135
140
|
rescue StandardError
|
136
141
|
puts "Failing with '#{aSymbolName}' and '#{aLexeme}'"
|
137
142
|
raise ex
|
@@ -141,7 +146,34 @@ module SrlRuby
|
|
141
146
|
end
|
142
147
|
|
143
148
|
def skip_whitespaces()
|
144
|
-
scanner.
|
149
|
+
pre_pos = scanner.pos
|
150
|
+
|
151
|
+
begin
|
152
|
+
ws_found = false
|
153
|
+
found = scanner.skip(/[ \t\f]+/)
|
154
|
+
ws_found = true if found
|
155
|
+
found = scanner.skip(/(?:\r\n)|\r|\n/)
|
156
|
+
if found
|
157
|
+
ws_found = true
|
158
|
+
@lineno += 1
|
159
|
+
@line_start = scanner.pos
|
160
|
+
end
|
161
|
+
end while ws_found
|
162
|
+
|
163
|
+
curr_pos = scanner.pos
|
164
|
+
return if curr_pos == pre_pos
|
165
|
+
# skipped = scanner.string.slice(Range.new(pre_pos, curr_pos))
|
166
|
+
# triplet = skipped.rpartition(/\n|\r/)
|
167
|
+
# @column = 1 unless triplet[1].empty?
|
168
|
+
|
169
|
+
# Correction for the tabs
|
170
|
+
# tab_count = triplet[2].chars.count { |ch| ch =~ /\t/ }
|
171
|
+
# @column += triplet[2].size + tab_count * (tab_size - 1) - 1
|
145
172
|
end
|
173
|
+
|
174
|
+
def tab_size()
|
175
|
+
2
|
176
|
+
end
|
177
|
+
|
146
178
|
end # class
|
147
179
|
end # module
|
data/lib/srl_ruby/version.rb
CHANGED
data/lib/srl_ruby.rb
CHANGED
@@ -30,7 +30,7 @@ module SrlRuby # This module is used as a namespace
|
|
30
30
|
|
31
31
|
unless result.success?
|
32
32
|
# Stop if the parse failed...
|
33
|
-
line1 = "Parsing
|
33
|
+
line1 = "Parsing failed\n"
|
34
34
|
line2 = "Reason: #{result.failure_reason.message}"
|
35
35
|
raise StandardError, line1 + line2
|
36
36
|
end
|
data/srl_ruby.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: srl_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rley
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.6.
|
19
|
+
version: 0.6.03
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.6.
|
26
|
+
version: 0.6.03
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/srl_ruby/ast_builder.rb
|
111
111
|
- lib/srl_ruby/grammar.rb
|
112
112
|
- lib/srl_ruby/regex_repr.rb
|
113
|
+
- lib/srl_ruby/srl_token.rb
|
113
114
|
- lib/srl_ruby/tokenizer.rb
|
114
115
|
- lib/srl_ruby/version.rb
|
115
116
|
- spec/integration_spec.rb
|