parslet 1.2.3 → 1.3.0
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.
- data/HISTORY.txt +21 -0
- data/README +1 -1
- data/example/ignore_whitespace.rb +66 -0
- data/example/mathn.rb +44 -0
- data/example/output/ignore_whitespace.out +1 -0
- data/example/output/ip_address.out +2 -2
- data/example/output/mathn.out +4 -0
- data/lib/parslet.rb +8 -1
- data/lib/parslet/atoms.rb +1 -0
- data/lib/parslet/atoms/alternative.rb +1 -1
- data/lib/parslet/atoms/base.rb +26 -157
- data/lib/parslet/atoms/can_flatten.rb +132 -0
- data/lib/parslet/atoms/lookahead.rb +5 -8
- data/lib/parslet/atoms/str.rb +1 -1
- data/lib/parslet/atoms/visitor.rb +23 -9
- data/lib/parslet/bytecode.rb +6 -0
- data/lib/parslet/bytecode/compiler.rb +138 -0
- data/lib/parslet/bytecode/instructions.rb +358 -0
- data/lib/parslet/bytecode/vm.rb +209 -0
- data/lib/parslet/cause.rb +62 -0
- data/lib/parslet/export.rb +2 -2
- data/lib/parslet/rig/rspec.rb +18 -17
- data/lib/parslet/source.rb +66 -48
- data/lib/parslet/source/line_cache.rb +7 -1
- data/lib/parslet/transform/context.rb +15 -7
- metadata +57 -16
- data/Gemfile +0 -16
- data/lib/parslet/atoms/transform.rb +0 -75
@@ -60,6 +60,12 @@ class Parslet::Source
|
|
60
60
|
# # would describe [0, 10], (10, 20], (20, 30]
|
61
61
|
#
|
62
62
|
module RangeSearch # :nodoc:
|
63
|
+
def find_mid(left, right)
|
64
|
+
# NOTE: Jonathan Hinkle reported that when mathn is required, just
|
65
|
+
# dividing and relying on the integer truncation is not enough.
|
66
|
+
left + ((right - left) / 2).floor
|
67
|
+
end
|
68
|
+
|
63
69
|
# Scans the array for the first number that is > than bound. Returns the
|
64
70
|
# index of that number.
|
65
71
|
#
|
@@ -71,7 +77,7 @@ class Parslet::Source
|
|
71
77
|
right = size - 1
|
72
78
|
|
73
79
|
loop do
|
74
|
-
mid = left
|
80
|
+
mid = find_mid(left, right)
|
75
81
|
|
76
82
|
if self[mid] > bound
|
77
83
|
right = mid
|
@@ -11,14 +11,22 @@ require 'blankslate'
|
|
11
11
|
# end
|
12
12
|
#
|
13
13
|
class Parslet::Transform::Context < BlankSlate # :nodoc:
|
14
|
-
|
15
|
-
|
14
|
+
reveal :methods
|
15
|
+
reveal :respond_to?
|
16
|
+
reveal :inspect
|
17
|
+
reveal :to_s
|
18
|
+
reveal :instance_variable_set
|
19
|
+
|
20
|
+
def meta_def(name, &body)
|
21
|
+
metaclass = class <<self; self; end
|
22
|
+
|
23
|
+
metaclass.send(:define_method, name, &body)
|
16
24
|
end
|
17
25
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
26
|
+
def initialize(bindings)
|
27
|
+
bindings.each do |key, value|
|
28
|
+
meta_def(key.to_sym) { value }
|
29
|
+
instance_variable_set("@#{key}", value)
|
30
|
+
end
|
23
31
|
end
|
24
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parslet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: blankslate
|
16
|
-
requirement: &
|
16
|
+
requirement: &70331801365680 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70331801365680
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70331801365040 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70331801365040
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: flexmock
|
38
|
-
requirement: &
|
38
|
+
requirement: &70331802115280 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70331802115280
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &70331802114800 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70331802114800
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: sdoc
|
60
|
-
requirement: &
|
60
|
+
requirement: &70331802114300 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,40 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70331802114300
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard
|
71
|
+
requirement: &70331802113400 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70331802113400
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: guard-rspec
|
82
|
+
requirement: &70331802112700 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70331802112700
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: growl
|
93
|
+
requirement: &70331802112180 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70331802112180
|
69
102
|
description:
|
70
103
|
email: kaspar.schiess@absurd.li
|
71
104
|
executables: []
|
@@ -73,13 +106,13 @@ extensions: []
|
|
73
106
|
extra_rdoc_files:
|
74
107
|
- README
|
75
108
|
files:
|
76
|
-
- Gemfile
|
77
109
|
- HISTORY.txt
|
78
110
|
- LICENSE
|
79
111
|
- Rakefile
|
80
112
|
- README
|
81
113
|
- lib/parslet/atoms/alternative.rb
|
82
114
|
- lib/parslet/atoms/base.rb
|
115
|
+
- lib/parslet/atoms/can_flatten.rb
|
83
116
|
- lib/parslet/atoms/context.rb
|
84
117
|
- lib/parslet/atoms/dsl.rb
|
85
118
|
- lib/parslet/atoms/entity.rb
|
@@ -89,9 +122,13 @@ files:
|
|
89
122
|
- lib/parslet/atoms/repetition.rb
|
90
123
|
- lib/parslet/atoms/sequence.rb
|
91
124
|
- lib/parslet/atoms/str.rb
|
92
|
-
- lib/parslet/atoms/transform.rb
|
93
125
|
- lib/parslet/atoms/visitor.rb
|
94
126
|
- lib/parslet/atoms.rb
|
127
|
+
- lib/parslet/bytecode/compiler.rb
|
128
|
+
- lib/parslet/bytecode/instructions.rb
|
129
|
+
- lib/parslet/bytecode/vm.rb
|
130
|
+
- lib/parslet/bytecode.rb
|
131
|
+
- lib/parslet/cause.rb
|
95
132
|
- lib/parslet/convenience.rb
|
96
133
|
- lib/parslet/error_tree.rb
|
97
134
|
- lib/parslet/export.rb
|
@@ -114,9 +151,11 @@ files:
|
|
114
151
|
- example/empty.rb
|
115
152
|
- example/erb.rb
|
116
153
|
- example/ignore.rb
|
154
|
+
- example/ignore_whitespace.rb
|
117
155
|
- example/ip_address.rb
|
118
156
|
- example/json.rb
|
119
157
|
- example/local.rb
|
158
|
+
- example/mathn.rb
|
120
159
|
- example/minilisp.rb
|
121
160
|
- example/output/boolean_algebra.out
|
122
161
|
- example/output/comments.out
|
@@ -126,9 +165,11 @@ files:
|
|
126
165
|
- example/output/empty.err
|
127
166
|
- example/output/erb.out
|
128
167
|
- example/output/ignore.out
|
168
|
+
- example/output/ignore_whitespace.out
|
129
169
|
- example/output/ip_address.out
|
130
170
|
- example/output/json.out
|
131
171
|
- example/output/local.out
|
172
|
+
- example/output/mathn.out
|
132
173
|
- example/output/minilisp.out
|
133
174
|
- example/output/parens.out
|
134
175
|
- example/output/readme.out
|
@@ -160,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
160
201
|
version: '0'
|
161
202
|
segments:
|
162
203
|
- 0
|
163
|
-
hash:
|
204
|
+
hash: 3769329244908936169
|
164
205
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
206
|
none: false
|
166
207
|
requirements:
|
@@ -169,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
210
|
version: '0'
|
170
211
|
requirements: []
|
171
212
|
rubyforge_project:
|
172
|
-
rubygems_version: 1.8.
|
213
|
+
rubygems_version: 1.8.16
|
173
214
|
signing_key:
|
174
215
|
specification_version: 3
|
175
216
|
summary: Parser construction library with great error reporting in Ruby.
|
data/Gemfile
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'parslet/atoms/visitor'
|
3
|
-
|
4
|
-
# A helper class that allows transforming one grammar into another. You can
|
5
|
-
# use this class as a base class:
|
6
|
-
#
|
7
|
-
# Example:
|
8
|
-
# class MyTransform < Parslet::Atoms::Transform
|
9
|
-
# def visit_str(str)
|
10
|
-
# # mangle string here
|
11
|
-
# super(str)
|
12
|
-
# end
|
13
|
-
# end
|
14
|
-
#
|
15
|
-
# Note that all the methods in a Transform must return parser atoms. The
|
16
|
-
# quickest way to do so is to call super with your own arguments. This will
|
17
|
-
# just create the same kind of atom that was just visited.
|
18
|
-
#
|
19
|
-
# In essence, this base class performs what is called an 'identity transform'
|
20
|
-
# with one small caveat: It returns a brand new grammar composed of brand new
|
21
|
-
# parser atoms. This is like a deep clone of your grammar.
|
22
|
-
#
|
23
|
-
# But nothing stops you from doing something that is far from a deep clone.
|
24
|
-
# You can totally transform the language your grammar accepts. Or maybe
|
25
|
-
# turn all repetitions into non-greedy ones? Go wild.
|
26
|
-
#
|
27
|
-
class Parslet::Atoms::Transform
|
28
|
-
# Applies a transformation to a grammar and returns a new grammar that
|
29
|
-
# is the result of the transform.
|
30
|
-
#
|
31
|
-
# Example:
|
32
|
-
# Parslet::Atoms::Transform.new.apply(my_grammar) # => deep clone of my_grammar
|
33
|
-
#
|
34
|
-
def apply(grammar)
|
35
|
-
grammar.accept(self)
|
36
|
-
end
|
37
|
-
|
38
|
-
def visit_str(str)
|
39
|
-
Parslet.str(str)
|
40
|
-
end
|
41
|
-
|
42
|
-
def visit_sequence(parslets)
|
43
|
-
parslets[1..-1].inject(parslets[0]) { |a,p| a >> p.accept(self) }
|
44
|
-
end
|
45
|
-
|
46
|
-
def visit_re(match)
|
47
|
-
Parslet.match(match)
|
48
|
-
end
|
49
|
-
|
50
|
-
def visit_alternative(parslets)
|
51
|
-
parslets[1..-1].inject(parslets[0]) { |a,p| a | p.accept(self) }
|
52
|
-
end
|
53
|
-
|
54
|
-
def visit_lookahead(positive, parslet)
|
55
|
-
Parslet::Atoms::Lookahead.new(positive, parslet.accept(self))
|
56
|
-
end
|
57
|
-
|
58
|
-
def visit_entity(name, block)
|
59
|
-
# NOTE: This is kinda tricky. We return a new entity that keeps a reference
|
60
|
-
# to the transformer around. Once somebody accesses the parslet in that
|
61
|
-
# entity, the original block will produce the original parslet, and then
|
62
|
-
# we transform that then and there. Its lazy and futuristic!
|
63
|
-
transformer = self
|
64
|
-
transformed_block = proc { block.call.accept(transformer) }
|
65
|
-
Parslet::Atoms::Entity.new(name, &transformed_block)
|
66
|
-
end
|
67
|
-
|
68
|
-
def visit_named(name, parslet)
|
69
|
-
parslet.accept(self).as(name)
|
70
|
-
end
|
71
|
-
|
72
|
-
def visit_repetition(min, max, parslet)
|
73
|
-
parslet.accept(self).repeat(min, max)
|
74
|
-
end
|
75
|
-
end
|