regexador 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ require_relative '../lib/regexador'
2
+ require 'pp'
3
+
4
+ require 'parslet/convenience'
5
+ require 'parslet/rig/rspec'
6
+
7
+ class Program
8
+ attr_accessor :description, :program, :regex, :good, :bad, :examples
9
+
10
+ def initialize(code)
11
+ @code = code
12
+ @parser = Regexador::Parser.new
13
+ end
14
+
15
+ def parseable?
16
+ result = @parser.parse(@code) rescue nil # != nil
17
+ !! result
18
+ end
19
+
20
+ def parse_pattern # FIXME no longer used?
21
+ tree = @parser.pattern.parse(@code)
22
+ tree = tree[:alternation] if tree.size == 1 && tree.keys.first == :alternation
23
+ tree = tree[:sequence].first if tree.size == 1 && tree.keys.first == :sequence
24
+ tree
25
+ end
26
+
27
+ def parse
28
+ tree = @parser.parse(@code)
29
+ end
30
+
31
+ def regexp
32
+ Regexador.new(@code).to_regex
33
+ end
34
+ end
35
+
@@ -0,0 +1,39 @@
1
+ $LOAD_PATH << "." << "./lib"
2
+
3
+ require 'regexador'
4
+
5
+ require "minitest/autorun"
6
+
7
+
8
+ class TestRegexador < Minitest::Test
9
+
10
+ def test_001_special_chars
11
+ @parser = Regexador::Parser.new
12
+ assert @parser.cSQUOTE.parse("'")
13
+ assert @parser.cHASH.parse('#')
14
+ assert @parser.cNEWLINE.parse("\n")
15
+ assert @parser.cEQUAL.parse('=')
16
+ end
17
+
18
+ def test_002_intl_chars
19
+ @parser = Regexador::Parser.new
20
+ assert @parser.char.parse_with_debug("`æ")
21
+ assert @parser.char.parse("`ß")
22
+ assert @parser.char.parse("`ç")
23
+ assert @parser.char.parse("`ö")
24
+ assert @parser.char.parse("`ñ")
25
+ end
26
+
27
+ def test_003_codepoints
28
+ @parser = Regexador::Parser.new
29
+ assert @parser.codepoint.parse_with_debug("&1234")
30
+ assert @parser.codepoint.parse('&beef')
31
+ end
32
+
33
+ def test_004_predef_tokens
34
+ @parser = Regexador::Parser.new
35
+ %w(BOS EOS START END).each do |token|
36
+ assert @parser.pattern.parse_with_debug(token)
37
+ end
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: regexador
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.5
5
+ platform: ruby
6
+ authors:
7
+ - Hal Fulton
8
+ - Kaspar Schiess
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2019-11-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: parslet
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.5.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 2.5.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: "This is implemented as an \"external DSL\" in Ruby; that is (like SQL
57
+ for example), \na \"program\" in a Ruby string is passed into some kind of parser/interpreter
58
+ method.\nIn this case, it is possible to use the result \"as is\" or to convert
59
+ to an ordinary \nRuby regular expression.\n\nThough this mini-language was conceived
60
+ and implemented \"for Ruby, using Ruby,\" \nin principle there is no reason it might
61
+ not also be implemented in other languages\nsuch as Python or Perl.\n\nDevelopment
62
+ on this project began in mid-July 2013. As such, it is still an immature\nproject.
63
+ Syntax and semantics may change. Feel free to offer comments or suggestions.\n"
64
+ email:
65
+ - rubyhacker@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - README.md
71
+ - lib/chars.rb
72
+ - lib/keywords.rb
73
+ - lib/predefs.rb
74
+ - lib/regexador.rb
75
+ - lib/regexador_parser.rb
76
+ - lib/regexador_xform.rb
77
+ - spec/parsing_spec.rb
78
+ - spec/programs_spec.rb
79
+ - spec/testing.rb
80
+ - test/test.rb
81
+ homepage: http://github.com/hal9000/regexador
82
+ licenses:
83
+ - The Ruby License
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.2.2
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: A mini-language to make regular expressions more readable.
105
+ test_files:
106
+ - test/test.rb
107
+ - spec/testing.rb
108
+ - spec/parsing_spec.rb
109
+ - spec/programs_spec.rb