regexp_parser 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/ChangeLog +4 -0
  2. data/LICENSE +22 -0
  3. data/README.rdoc +307 -0
  4. data/Rakefile +91 -0
  5. data/lib/regexp_parser/ctype.rb +48 -0
  6. data/lib/regexp_parser/expression/property.rb +108 -0
  7. data/lib/regexp_parser/expression/set.rb +59 -0
  8. data/lib/regexp_parser/expression.rb +287 -0
  9. data/lib/regexp_parser/lexer.rb +105 -0
  10. data/lib/regexp_parser/parser.rb +417 -0
  11. data/lib/regexp_parser/scanner/property.rl +534 -0
  12. data/lib/regexp_parser/scanner/scanner.rl +712 -0
  13. data/lib/regexp_parser/scanner.rb +3325 -0
  14. data/lib/regexp_parser/syntax/ruby/1.8.6.rb +14 -0
  15. data/lib/regexp_parser/syntax/ruby/1.8.7.rb +14 -0
  16. data/lib/regexp_parser/syntax/ruby/1.8.rb +39 -0
  17. data/lib/regexp_parser/syntax/ruby/1.9.1.rb +39 -0
  18. data/lib/regexp_parser/syntax/ruby/1.9.2.rb +10 -0
  19. data/lib/regexp_parser/syntax/ruby/1.9.3.rb +24 -0
  20. data/lib/regexp_parser/syntax/ruby/1.9.rb +8 -0
  21. data/lib/regexp_parser/syntax/tokens.rb +332 -0
  22. data/lib/regexp_parser/syntax.rb +172 -0
  23. data/lib/regexp_parser.rb +45 -0
  24. data/test/helpers.rb +8 -0
  25. data/test/lexer/test_all.rb +26 -0
  26. data/test/lexer/test_literals.rb +120 -0
  27. data/test/lexer/test_nesting.rb +107 -0
  28. data/test/lexer/test_refcalls.rb +45 -0
  29. data/test/parser/test_all.rb +44 -0
  30. data/test/parser/test_alternation.rb +46 -0
  31. data/test/parser/test_anchors.rb +35 -0
  32. data/test/parser/test_errors.rb +59 -0
  33. data/test/parser/test_escapes.rb +48 -0
  34. data/test/parser/test_expression.rb +51 -0
  35. data/test/parser/test_groups.rb +69 -0
  36. data/test/parser/test_properties.rb +346 -0
  37. data/test/parser/test_quantifiers.rb +236 -0
  38. data/test/parser/test_refcalls.rb +101 -0
  39. data/test/parser/test_sets.rb +99 -0
  40. data/test/scanner/test_all.rb +30 -0
  41. data/test/scanner/test_anchors.rb +35 -0
  42. data/test/scanner/test_errors.rb +36 -0
  43. data/test/scanner/test_escapes.rb +49 -0
  44. data/test/scanner/test_groups.rb +41 -0
  45. data/test/scanner/test_literals.rb +85 -0
  46. data/test/scanner/test_meta.rb +36 -0
  47. data/test/scanner/test_properties.rb +315 -0
  48. data/test/scanner/test_quantifiers.rb +38 -0
  49. data/test/scanner/test_refcalls.rb +45 -0
  50. data/test/scanner/test_scripts.rb +314 -0
  51. data/test/scanner/test_sets.rb +80 -0
  52. data/test/scanner/test_types.rb +30 -0
  53. data/test/syntax/ruby/test_1.8.rb +57 -0
  54. data/test/syntax/ruby/test_1.9.1.rb +39 -0
  55. data/test/syntax/ruby/test_1.9.3.rb +38 -0
  56. data/test/syntax/ruby/test_all.rb +12 -0
  57. data/test/syntax/test_all.rb +19 -0
  58. data/test/test_all.rb +4 -0
  59. metadata +160 -0
@@ -0,0 +1,30 @@
1
+ require File.expand_path("../../helpers", __FILE__)
2
+
3
+ class ScannerTypes < Test::Unit::TestCase
4
+
5
+ tests = {
6
+ 'a\dc' => [:type, :digit, '\d', 1],
7
+ 'a\Dc' => [:type, :nondigit, '\D', 1],
8
+
9
+ 'a\hc' => [:type, :hex, '\h', 1],
10
+ 'a\Hc' => [:type, :nonhex, '\H', 1],
11
+
12
+ 'a\sc' => [:type, :space, '\s', 1],
13
+ 'a\Sc' => [:type, :nonspace, '\S', 1],
14
+
15
+ 'a\wc' => [:type, :word, '\w', 1],
16
+ 'a\Wc' => [:type, :nonword, '\W', 1],
17
+ }
18
+
19
+ tests.each do |pattern, test|
20
+ [:type, :token, :text].each_with_index do |member, i|
21
+ define_method "test_scan_#{test[0]}_#{test[1]}_#{member}" do
22
+
23
+ token = RS.scan(pattern)[test[3]]
24
+ assert_equal( test[i], token[i] )
25
+
26
+ end
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,57 @@
1
+ require File.expand_path("../../../helpers", __FILE__)
2
+
3
+ class TestSyntaxRuby_V18 < Test::Unit::TestCase
4
+ include Regexp::Syntax::Token
5
+
6
+ def setup
7
+ @syntax = Regexp::Syntax.new 'ruby/1.8'
8
+ end
9
+
10
+ tests = {
11
+ :implements => {
12
+ :backref => [:number],
13
+ :escape => [Escape::All].flatten,
14
+ :group => [Group::All].flatten,
15
+ :assertion => [Group::Assertion::All].flatten,
16
+ :quantifier => [
17
+ Quantifier::Greedy + Quantifier::Reluctant +
18
+ Quantifier::Interval + Quantifier::IntervalReluctant
19
+ ].flatten,
20
+ },
21
+
22
+ :excludes => {
23
+ :backref => [
24
+ Group::Backreference::All + Group::SubexpressionCall::All
25
+ ].flatten,
26
+
27
+ :quantifier => [
28
+ Quantifier::Possessive
29
+ ].flatten,
30
+
31
+ :subset => nil
32
+ },
33
+ }
34
+
35
+ tests.each do |method, types|
36
+ types.each do |type, tokens|
37
+ if tokens.nil? or tokens.empty?
38
+ define_method "test_syntax_ruby_v18_#{method}_#{type}" do
39
+ assert_equal(
40
+ method == :excludes ? false : true,
41
+ @syntax.implements?(type, nil)
42
+ )
43
+ end
44
+ else
45
+ tokens.each do |token|
46
+ define_method "test_syntax_ruby_v18_#{method}_#{type}_#{token}" do
47
+ assert_equal(
48
+ method == :excludes ? false : true,
49
+ @syntax.implements?(type, token)
50
+ )
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path("../../../helpers", __FILE__)
2
+
3
+ class TestSyntaxRuby_V191 < Test::Unit::TestCase
4
+ include Regexp::Syntax::Token
5
+
6
+ def setup
7
+ @syntax = Regexp::Syntax.new 'ruby/1.9.1'
8
+ end
9
+
10
+ tests = {
11
+ :implements => {
12
+ :escape => [
13
+ Escape::Backreference + Escape::ASCII + Escape::Meta
14
+ ].flatten,
15
+
16
+ :quantifier => [
17
+ Quantifier::Greedy + Quantifier::Reluctant +
18
+ Quantifier::Possessive
19
+ ].flatten,
20
+ },
21
+
22
+ :excludes => {
23
+ },
24
+ }
25
+
26
+ tests.each do |method, types|
27
+ types.each do |type, tokens|
28
+ tokens.each do |token|
29
+ define_method "test_syntax_ruby_v191_#{method}_#{type}_#{token}" do
30
+ assert_equal(
31
+ method == :excludes ? false : true,
32
+ @syntax.implements?(type, token)
33
+ )
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,38 @@
1
+ require File.expand_path("../../../helpers", __FILE__)
2
+
3
+ class TestSyntaxRuby_V193 < Test::Unit::TestCase
4
+ include Regexp::Syntax::Token
5
+
6
+ def setup
7
+ @syntax = Regexp::Syntax.new 'ruby/1.9.3'
8
+ end
9
+
10
+ tests = {
11
+ :implements => {
12
+ :property => [
13
+ UnicodeProperty::Script_6_0 + UnicodeProperty::Age
14
+ ].flatten,
15
+
16
+ :nonproperty => [
17
+ UnicodeProperty::Script_6_0 + UnicodeProperty::Age
18
+ ].flatten,
19
+ },
20
+
21
+ :excludes => {
22
+ },
23
+ }
24
+
25
+ tests.each do |method, types|
26
+ types.each do |type, tokens|
27
+ tokens.each do |token|
28
+ define_method "test_syntax_ruby_v193_#{method}_#{type}_#{token}" do
29
+ assert_equal(
30
+ method == :excludes ? false : true,
31
+ @syntax.implements?(type, token)
32
+ )
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path("../../../helpers", __FILE__)
2
+
3
+ %w{1.8 1.9.1 1.9.3}.each do|tc|
4
+ require File.expand_path("../test_#{tc}", __FILE__)
5
+ end
6
+
7
+ class TestSyntaxRuby < Test::Unit::TestCase
8
+
9
+ def test_lexer_ruby_syntax
10
+ end
11
+
12
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path("../../helpers", __FILE__)
2
+
3
+ require File.expand_path("../ruby/test_all", __FILE__)
4
+
5
+ class TestSyntax < Test::Unit::TestCase
6
+
7
+ def test_syntax_unknown_name
8
+ assert_raise( Regexp::Syntax::MissingSyntaxSpecError ) {
9
+ RL.scan('abc', 'ruby/1.6')
10
+ }
11
+ end
12
+
13
+ def test_syntax_not_implemented
14
+ assert_raise( Regexp::Syntax::NotImplementedError ) {
15
+ RP.parse('\p{alpha}', 'ruby/1.8')
16
+ }
17
+ end
18
+
19
+ end
data/test/test_all.rb ADDED
@@ -0,0 +1,4 @@
1
+ require File.expand_path("../helpers", __FILE__)
2
+ %w{ scanner syntax lexer parser }.each do |subject|
3
+ require File.expand_path("../#{subject}/test_all", __FILE__)
4
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: regexp_parser
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Ammar Ali
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-01 00:00:00 +03:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: A library for tokenizing, lexing, and parsing Ruby regular expressions.
22
+ email: ammarabuali@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - ChangeLog
29
+ - LICENSE
30
+ - README.rdoc
31
+ files:
32
+ - lib/regexp_parser/ctype.rb
33
+ - lib/regexp_parser/expression/property.rb
34
+ - lib/regexp_parser/expression/set.rb
35
+ - lib/regexp_parser/expression.rb
36
+ - lib/regexp_parser/lexer.rb
37
+ - lib/regexp_parser/parser.rb
38
+ - lib/regexp_parser/scanner.rb
39
+ - lib/regexp_parser/syntax/ruby/1.8.6.rb
40
+ - lib/regexp_parser/syntax/ruby/1.8.7.rb
41
+ - lib/regexp_parser/syntax/ruby/1.8.rb
42
+ - lib/regexp_parser/syntax/ruby/1.9.1.rb
43
+ - lib/regexp_parser/syntax/ruby/1.9.2.rb
44
+ - lib/regexp_parser/syntax/ruby/1.9.3.rb
45
+ - lib/regexp_parser/syntax/ruby/1.9.rb
46
+ - lib/regexp_parser/syntax/tokens.rb
47
+ - lib/regexp_parser/syntax.rb
48
+ - lib/regexp_parser.rb
49
+ - test/helpers.rb
50
+ - test/lexer/test_all.rb
51
+ - test/lexer/test_literals.rb
52
+ - test/lexer/test_nesting.rb
53
+ - test/lexer/test_refcalls.rb
54
+ - test/parser/test_all.rb
55
+ - test/parser/test_alternation.rb
56
+ - test/parser/test_anchors.rb
57
+ - test/parser/test_errors.rb
58
+ - test/parser/test_escapes.rb
59
+ - test/parser/test_expression.rb
60
+ - test/parser/test_groups.rb
61
+ - test/parser/test_properties.rb
62
+ - test/parser/test_quantifiers.rb
63
+ - test/parser/test_refcalls.rb
64
+ - test/parser/test_sets.rb
65
+ - test/scanner/test_all.rb
66
+ - test/scanner/test_anchors.rb
67
+ - test/scanner/test_errors.rb
68
+ - test/scanner/test_escapes.rb
69
+ - test/scanner/test_groups.rb
70
+ - test/scanner/test_literals.rb
71
+ - test/scanner/test_meta.rb
72
+ - test/scanner/test_properties.rb
73
+ - test/scanner/test_quantifiers.rb
74
+ - test/scanner/test_refcalls.rb
75
+ - test/scanner/test_scripts.rb
76
+ - test/scanner/test_sets.rb
77
+ - test/scanner/test_types.rb
78
+ - test/syntax/ruby/test_1.8.rb
79
+ - test/syntax/ruby/test_1.9.1.rb
80
+ - test/syntax/ruby/test_1.9.3.rb
81
+ - test/syntax/ruby/test_all.rb
82
+ - test/syntax/test_all.rb
83
+ - test/test_all.rb
84
+ - lib/regexp_parser/scanner/property.rl
85
+ - lib/regexp_parser/scanner/scanner.rl
86
+ - Rakefile
87
+ - LICENSE
88
+ - README.rdoc
89
+ - ChangeLog
90
+ has_rdoc: true
91
+ homepage: http://github.com/ammar/regexp_parser
92
+ licenses: []
93
+
94
+ post_install_message:
95
+ rdoc_options:
96
+ - --inline-source
97
+ - --charset=UTF-8
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ segments:
114
+ - 1
115
+ - 3
116
+ - 7
117
+ version: 1.3.7
118
+ requirements: []
119
+
120
+ rubyforge_project: regexp_parser
121
+ rubygems_version: 1.3.7
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Scanner, lexer, parser for ruby's regular expressions
125
+ test_files:
126
+ - test/helpers.rb
127
+ - test/lexer/test_all.rb
128
+ - test/lexer/test_literals.rb
129
+ - test/lexer/test_nesting.rb
130
+ - test/lexer/test_refcalls.rb
131
+ - test/parser/test_all.rb
132
+ - test/parser/test_alternation.rb
133
+ - test/parser/test_anchors.rb
134
+ - test/parser/test_errors.rb
135
+ - test/parser/test_escapes.rb
136
+ - test/parser/test_expression.rb
137
+ - test/parser/test_groups.rb
138
+ - test/parser/test_properties.rb
139
+ - test/parser/test_quantifiers.rb
140
+ - test/parser/test_refcalls.rb
141
+ - test/parser/test_sets.rb
142
+ - test/scanner/test_all.rb
143
+ - test/scanner/test_anchors.rb
144
+ - test/scanner/test_errors.rb
145
+ - test/scanner/test_escapes.rb
146
+ - test/scanner/test_groups.rb
147
+ - test/scanner/test_literals.rb
148
+ - test/scanner/test_meta.rb
149
+ - test/scanner/test_properties.rb
150
+ - test/scanner/test_quantifiers.rb
151
+ - test/scanner/test_refcalls.rb
152
+ - test/scanner/test_scripts.rb
153
+ - test/scanner/test_sets.rb
154
+ - test/scanner/test_types.rb
155
+ - test/syntax/ruby/test_1.8.rb
156
+ - test/syntax/ruby/test_1.9.1.rb
157
+ - test/syntax/ruby/test_1.9.3.rb
158
+ - test/syntax/ruby/test_all.rb
159
+ - test/syntax/test_all.rb
160
+ - test/test_all.rb