Permalink
Browse files

+ prsnt? -> present?, absnt? -> absent?

Thanks to txus (Josep M. Bach) for nudging me ever so slightly into that
direction and for providing a patch. I rewrote it to have it exactly my
way, which is not saying that the patch was bad. It just testifies my
perfectionism. Thanks a lot, it makes sense to have it this way.
  • Loading branch information...
kschiess committed Mar 2, 2011
1 parent 04bbe35 commit 39fc3d9034d7fd71d50a204e4a62829355fe231a
View
@@ -1,3 +1,8 @@
+= 2.0 / ?? (future release changes, like a reminder to self)
+
+ - prsnt? and absnt? are now finally banned into oblivion. Wasting vocals for
+ the win.
+
= 1.2.0 / ???
+ Parslet::Parser is now also a grammar atom, it can be composed freely with
View
@@ -19,8 +19,8 @@ class ALanguage < Parslet::Parser
rule(:spaces) { space.repeat }
rule(:space) { multiline_comment | line_comment | str(' ') }
- rule(:line_comment) { (str('//') >> (newline.absnt? >> any).repeat).as(:line) }
- rule(:multiline_comment) { (str('/*') >> (str('*/').absnt? >> any).repeat >> str('*/')).as(:multi) }
+ rule(:line_comment) { (str('//') >> (newline.absent? >> any).repeat).as(:line) }
+ rule(:multiline_comment) { (str('/*') >> (str('*/').absent? >> any).repeat >> str('*/')).as(:multi) }
end
code = %q(
View
@@ -5,15 +5,15 @@
require 'parslet'
class ErbParser < Parslet::Parser
- rule(:ruby) { (str('%>').absnt? >> any).repeat.as(:ruby) }
+ rule(:ruby) { (str('%>').absent? >> any).repeat.as(:ruby) }
rule(:expression) { (str('=') >> ruby).as(:expression) }
rule(:comment) { (str('#') >> ruby).as(:comment) }
rule(:code) { ruby.as(:code) }
rule(:erb) { expression | comment | code }
rule(:erb_with_tags) { str('<%') >> erb >> str('%>') }
- rule(:text) { (str('<%').absnt? >> any).repeat(1) }
+ rule(:text) { (str('<%').absent? >> any).repeat(1) }
rule(:text_with_ruby) { (text.as(:text) | erb_with_tags).repeat.as(:text) }
root(:text_with_ruby)
View
@@ -18,7 +18,7 @@
# S = E2 | E1 S
def this(name, &block); return Parslet::Atoms::Entity.new(name, &block) end
-def epsilon; any.absnt? end
+def epsilon; any.absent? end
# Traditional repetition will try as long as the pattern can be matched and
# then give up. This is greedy and blind.
View
@@ -45,7 +45,7 @@ class Parser < Parslet::Parser
rule(:string) {
str('"') >> (
str('\\') >> any |
- str('"').absnt? >> any
+ str('"').absent? >> any
).repeat.as(:string) >> str('"') >> space?
}
end
View
@@ -11,7 +11,7 @@
parser = str('"') >>
(
str('\\') >> any |
- str('"').absnt? >> any
+ str('"').absent? >> any
).repeat.as(:string) >>
str('"')
View
@@ -21,7 +21,7 @@ def tag(opts={})
parslet = str('<')
parslet = parslet >> str('/') if close
- parslet = parslet >> (str('>').absnt? >> match("[a-zA-Z]")).repeat(1).as(:name)
+ parslet = parslet >> (str('>').absent? >> match("[a-zA-Z]")).repeat(1).as(:name)
parslet = parslet >> str('>')
parslet
View
@@ -26,7 +26,7 @@ class LiteralsParser < Parslet::Parser
str('"') >>
(
(str('\\') >> any) |
- (str('"').absnt? >> any)
+ (str('"').absent? >> any)
).repeat.as(:string) >>
str('"')
end
View
@@ -101,11 +101,11 @@ class HereDocs < Parslet::Parser
# a doc_line is either the stop tag followed by nothing
# or just any kind of line.
rule(:doc_line) {
- (end_tag.absnt? >> gobble_eol).repeat >> end_tag
+ (end_tag.absent? >> gobble_eol).repeat >> end_tag
}
rule(:end_tag) { tag.matches(:tag) >> space? >> eol }
# eats anything until an end of line is found
- rule(:gobble_eol) { (eol.absnt? >> any).repeat >> eol }
+ rule(:gobble_eol) { (eol.absent? >> any).repeat >> eol }
rule(:eol) { match['\n\r'].repeat(1) }
rule(:space?) { str(' ').repeat }
View
@@ -50,9 +50,9 @@ def |(parslet)
#
# Example:
# # Only proceed the parse if 'a' is absent.
- # str('a').absnt?
+ # str('a').absent?
#
- def absnt?
+ def absent?
Parslet::Atoms::Lookahead.new(self, false)
end
@@ -61,11 +61,19 @@ def absnt?
#
# Example:
# # Only proceed the parse if 'a' is present.
- # str('a').prsnt?
+ # str('a').present?
#
- def prsnt?
+ def present?
Parslet::Atoms::Lookahead.new(self, true)
end
+
+ # Alias for present? that will disappear in 2.0 (deprecated)
+ #
+ alias prsnt? present?
+
+ # Alias for absent? that will disappear in 2.0 (deprecated)
+ #
+ alias absnt? absent?
# Marks a parslet atom as important for the tree output. This must be used
# to achieve meaningful output from the #parse method.
@@ -2,7 +2,7 @@
#
# Example:
#
-# str('foo').prsnt? # matches when the input contains 'foo', but leaves it
+# str('foo').present? # matches when the input contains 'foo', but leaves it
#
class Parslet::Atoms::Lookahead < Parslet::Atoms::Base
attr_reader :positive
@@ -33,7 +33,7 @@ class Parser < Parslet::Parser # :nodoc:
rule(:char_class) {
(str('[') >>
(str('\\') >> any |
- str(']').absnt? >> any).repeat(1) >>
+ str(']').absent? >> any).repeat(1) >>
str(']')).as(:match) >> space?
}
@@ -45,7 +45,7 @@ class Parser < Parslet::Parser # :nodoc:
str('\'') >>
(
(str('\\') >> any) |
- (str("'").absnt? >> any)
+ (str("'").absent? >> any)
).repeat.as(:string) >>
str('\'') >> space?
}
@@ -23,7 +23,7 @@ class ArgumentListParser
str('"') >>
(
str('\\') >> any |
- str('"').absnt? >> any
+ str('"').absent? >> any
).repeat.as(:string) >>
str('"') >> space?
end
@@ -118,8 +118,8 @@ class ALanguage < Parslet::Parser
rule(:space?) { space.repeat }
rule(:space) { multiline_comment.as(:multi) | line_comment.as(:line) | str(' ') }
- rule(:line_comment) { str('//') >> (match["\n\r"].absnt? >> any).repeat }
- rule(:multiline_comment) { str('/*') >> (str('*/').absnt? >> any).repeat >> str('*/') }
+ rule(:line_comment) { str('//') >> (match["\n\r"].absent? >> any).repeat }
+ rule(:multiline_comment) { str('/*') >> (str('*/').absent? >> any).repeat >> str('*/') }
end
describe ALanguage do
def remove_indent(s)
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe Parslet::Atoms::DSL do
+ describe "deprecated methods" do
+ let(:parslet) { Parslet.str('foo') }
+ describe "<- #absnt?" do
+ subject { parslet.absnt? }
+ its(:bound_parslet) { should == parslet }
+ its(:positive) { should == false }
+ end
+ describe "<- #prsnt?" do
+ subject { parslet.prsnt? }
+ its(:bound_parslet) { should == parslet }
+ its(:positive) { should == true }
+ end
+ end
+end
@@ -65,7 +65,7 @@ def visit_lookahead(positive, parslet)
it "should transform a positive lookahead into a negative lookahead" do
apply(
# The order of the sequence gets reversed as well...
- str('foo') >> str('foo').absnt?
+ str('foo') >> str('foo').absent?
).should parse('oof')
end
end
@@ -61,7 +61,7 @@
end
end
describe Parslet::Atoms::Lookahead do
- let(:parslet) { str('a').absnt? }
+ let(:parslet) { str('a').absent? }
it "should call back visitor" do
visitor.should_receive(:visit_lookahead).with(false, Parslet::Atoms::Base).once
View
@@ -173,10 +173,10 @@ def src(str); Parslet::Source.new str; end
parslet.inspect.should == "'foo' / 'bar'"
end
end
- describe "str('foo').prsnt? (positive lookahead)" do
+ describe "str('foo').present? (positive lookahead)" do
attr_reader :parslet
before(:each) do
- @parslet = str('foo').prsnt?
+ @parslet = str('foo').present?
end
it "should inspect as &'foo'" do
@@ -203,10 +203,10 @@ def src(str); Parslet::Source.new str; end
end
end
end
- describe "str('foo').absnt? (negative lookahead)" do
+ describe "str('foo').absent? (negative lookahead)" do
attr_reader :parslet
before(:each) do
- @parslet = str('foo').absnt?
+ @parslet = str('foo').absent?
end
it "should inspect as !'foo'" do
@@ -232,7 +232,7 @@ def src(str); Parslet::Source.new str; end
attr_reader :parslet
before(:each) do
# repeat will always succeed, since it has a minimum of 0. It will not
- # modify input position in that case. absnt? will, depending on
+ # modify input position in that case. absent? will, depending on
# implementation, match as much as possible and call its inner element
# again. This leads to an infinite loop. This example tests for the
# absence of that loop.
@@ -350,9 +350,9 @@ def src(str); Parslet::Source.new str; end
parslet.parse('ab').should == { :a => 'b' }
end
end
- context "str('a').absnt?" do
+ context "str('a').absent?" do
it "should return something in merge, even though it is nil" do
- (str('a').absnt? >> str('b').as(:b)).
+ (str('a').absent? >> str('b').as(:b)).
parse('b').should == {:b => 'b'}
end
end
@@ -38,7 +38,7 @@ class MiniLisp < Parslet::Parser
rule(:string) {
str('"') >> (
str('\\') >> any |
- str('"').absnt? >> any
+ str('"').absent? >> any
).repeat.as(:string) >> str('"') >> space?
}
end

0 comments on commit 39fc3d9

Please sign in to comment.