]> git.wincent.com - walrat.git/commitdiff
Trim some fat
authorGreg Hurrell <greg@hurrell.net>
Wed, 22 Oct 2014 01:04:20 +0000 (18:04 -0700)
committerGreg Hurrell <greg@hurrell.net>
Wed, 22 Oct 2014 01:04:20 +0000 (18:04 -0700)
lib/walrat/parslet_combining.rb
lib/walrat/string_result.rb

index 7dac2510c8505b690c59fec94d653bdbeed4ded1..a57c17037d82d2b42d22f807cbd2865edfceab95 100755 (executable)
@@ -13,24 +13,24 @@ module Walrat
   module ParsletCombining
     # Convenience method.
     def memoizing_parse string, options = {}
-      self.to_parseable.memoizing_parse string, options
+      to_parseable.memoizing_parse string, options
     end
 
     # Convenience method.
     def parse string, options = {}
-      self.to_parseable.parse string, options
+      to_parseable.parse string, options
     end
 
     # Defines a sequence of Parslets (or ParsletCombinations).
     # Returns a ParsletSequence instance.
     def sequence first, second, *others
-      Walrat::ParsletSequence.new first.to_parseable,
+      ParsletSequence.new first.to_parseable,
         second.to_parseable, *others
     end
 
     # Shorthand for ParsletCombining.sequence(first, second).
     def &(next_parslet)
-      self.sequence self, next_parslet
+      sequence self, next_parslet
     end
 
     # Defines a sequence of Parslets similar to the sequence method but with
@@ -42,45 +42,45 @@ module Walrat
     #   'foo' >> 'bar'.one_or_more  # returns results like ['foo', 'bar', 'bar', 'bar']
     #
     def merge first, second, *others
-      Walrat::ParsletMerge.new first.to_parseable,
+      ParsletMerge.new first.to_parseable,
         second.to_parseable, *others
     end
 
     # Shorthand for ParsletCombining.sequence(first, second)
     def >>(next_parslet)
-      self.merge self, next_parslet
+      merge self, next_parslet
     end
 
     # Defines a choice of Parslets (or ParsletCombinations).
     # Returns a ParsletChoice instance.
     def choice left, right, *others
-      Walrat::ParsletChoice.new left.to_parseable,
+      ParsletChoice.new left.to_parseable,
         right.to_parseable, *others
     end
 
     # Shorthand for ParsletCombining.choice(left, right)
     def |(alternative_parslet)
-      self.choice self, alternative_parslet
+      choice self, alternative_parslet
     end
 
     # Defines a repetition of the supplied Parslet (or ParsletCombination).
     # Returns a ParsletRepetition instance.
     def repetition parslet, min, max
-      Walrat::ParsletRepetition.new parslet.to_parseable, min, max
+      ParsletRepetition.new parslet.to_parseable, min, max
     end
 
     # Shorthand for ParsletCombining.repetition.
     def repeat min = nil, max = nil
-      self.repetition self, min, max
+      repetition self, min, max
     end
 
     def repetition_with_default parslet, min, max, default
-      Walrat::ParsletRepetitionDefault.new parslet.to_parseable, min,
+      ParsletRepetitionDefault.new parslet.to_parseable, min,
         max, default
     end
 
     def repeat_with_default min = nil, max = nil, default = nil
-      self.repetition_with_default self, min, max, default
+      repetition_with_default self, min, max, default
     end
 
     # Shorthand for ParsletCombining.repetition(0, 1).
@@ -94,36 +94,36 @@ module Walrat
     # explicitly passing an "ArrayResult.new")
     def optional default_return_value = NoParameterMarker.instance
       if default_return_value == NoParameterMarker.instance
-        self.repeat 0, 1 # default behaviour
+        repeat 0, 1 # default behaviour
       else
-        self.repeat_with_default 0, 1, default_return_value
+        repeat_with_default 0, 1, default_return_value
       end
     end
 
     # Alternative to optional.
     def zero_or_one
-      self.optional
+      optional
     end
 
     # possible synonym "star"
     def zero_or_more default_return_value = NoParameterMarker.instance
       if default_return_value == NoParameterMarker.instance
-        self.repeat 0 # default behaviour
+        repeat 0 # default behaviour
       else
-        self.repeat_with_default 0, nil, default_return_value
+        repeat_with_default 0, nil, default_return_value
       end
     end
 
     # possible synonym "plus"
     def one_or_more
-      self.repeat 1
+      repeat 1
     end
 
     # Parsing Expression Grammar support.
     # Succeeds if parslet succeeds but consumes no input (throws an
     # :AndPredicateSuccess symbol).
     def and_predicate parslet
-      Walrat::AndPredicate.new parslet.to_parseable
+      AndPredicate.new parslet.to_parseable
     end
 
     # Shorthand for and_predicate
@@ -131,7 +131,7 @@ module Walrat
     # that "?" at the end of a method name should indicate a method that
     # returns true or false.
     def and?
-      self.and_predicate self
+      and_predicate self
     end
 
     # Parsing Expression Grammar support.
@@ -142,8 +142,8 @@ module Walrat
     # operator, like this:
     #       rule :foo, :p1 & :p2.not_predicate
     #       rule :foo, :p1 & :p2.not!
-    def not_predicate parslet
-      Walrat::NotPredicate.new parslet.to_parseable
+    def not_predicate parslet = self
+      NotPredicate.new parslet.to_parseable
     end
 
     # Shorthand for not_predicate.
@@ -151,7 +151,7 @@ module Walrat
     # that "!" at the end of a method name should indicate a destructive
     # behaviour on (mutation of) the receiver.
     def not!
-      self.not_predicate self
+      not_predicate self
     end
 
     # Succeeds if parsing succeeds, consuming the output, but doesn't actually
@@ -160,12 +160,12 @@ module Walrat
     # This is for elements which are required but which shouldn't appear in the
     # final AST.
     def omission parslet
-      Walrat::ParsletOmission.new parslet.to_parseable
+      ParsletOmission.new parslet.to_parseable
     end
 
     # Shorthand for ParsletCombining.omission
     def skip
-      self.omission self
+      omission self
     end
   end # module ParsletCombining
 end # module Walrat
index 84f92ce43f793ede33a635121600fb7e73ba2e3d..350fb6a5636dab0993e858871798f0b86efa1d47 100644 (file)
@@ -5,7 +5,7 @@ require 'walrat'
 
 module Walrat
   class StringResult < String
-    include Walrat::LocationTracking
+    include LocationTracking
 
     def initialize string = ""
       self.source_text = string