srl_ruby 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aec2fc57a4a6eadb94d63cbb5b3edaaab988ceff
4
- data.tar.gz: fb2a6b4007134fd657c749e9979610e562b13ff3
3
+ metadata.gz: c6ca8e70f473d53992bd449ed2945cc55ebedcff
4
+ data.tar.gz: 065406740aded7b357712fa67daa4f622627a79c
5
5
  SHA512:
6
- metadata.gz: 2319c820f448ffffc89ed753f39c724fa7c438ebaa5930b5ee2aa9c303f7dedd3f23523a865ddf1a13838ec70e2f10a717cce1c562b4f98f61050a99d77d1437
7
- data.tar.gz: d975c484f19792cae40c23fbfc6294f606ffe49cff29ecf07519447585cf80e332e10e7ec1422846f501ae14dec2f8773c1fe0e04905ea9177214b60193a24ab
6
+ metadata.gz: 174e237267f85e4d0e4d9e714ded189c9a1d46635b8668af469d23c0b5a3709f53e48087486cd5fb8f60861e02de19d44c694224581a9d1071718272574898c6
7
+ data.tar.gz: 92118db7249a6f66dc88ae66e2ca229a6800b91ba7ac53e692bc452ef87f311a3bb4bbc8fe401f0b2c015d960ecd29015465d9908d633b1425ef08aa1575a77b
data/.rspec CHANGED
@@ -1,4 +1,3 @@
1
1
  --backtrace
2
- --format documentation
3
2
  --color
4
3
  --require spec_helper
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
@@ -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 aTerminal [Terminal] Terminal symbol associated with the token
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
@@ -1,7 +1,8 @@
1
1
  # File: srl_tokenizer.rb
2
2
  # Tokenizer for SRL (Simple Regex Language)
3
3
  require 'strscan'
4
- require 'rley' # Load the Rley gem
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
- token = Rley::Lexical::Token.new(aLexeme, aSymbolName)
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.scan(/[ \t\f\n\r]+/)
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
@@ -1,3 +1,3 @@
1
1
  module SrlRuby
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
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 of '#{source}' failed\n"
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
@@ -54,7 +54,7 @@ END_DESCR
54
54
  spec.required_ruby_version = '>= 2.1.0'
55
55
 
56
56
  # Runtime dependencies
57
- spec.add_dependency 'rley', '~> 0.6.00'
57
+ spec.add_dependency 'rley', '~> 0.6.03'
58
58
 
59
59
  # Development dependencies
60
60
  spec.add_development_dependency 'bundler', '~> 1.16'
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.0
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-08 00:00:00.000000000 Z
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.00
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.00
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