Permalink
Browse files

. Some documentation (preparing for release)

  • Loading branch information...
kschiess committed Oct 12, 2010
1 parent ee60fd1 commit da93a075478fc426345e23d2650e2495f1345bc2
Showing with 26 additions and 6 deletions.
  1. +1 −0 .gitignore
  2. +25 −6 lib/parslet.rb
View
@@ -0,0 +1 @@
+doc
View
@@ -6,8 +6,6 @@ def self.included(base)
end
module ClassMethods
- # Parser structure ---------------------------------------------------------
-
# Define an entity for the parser. This generates a method of the same name
# that can be used as part of other patterns. Those methods can be freely
# mixed in your parser class with real ruby methods.
@@ -36,25 +34,46 @@ def rule(name, &definition)
end
end
- # Text matching ------------------------------------------------------------
-
+ # Returns an atom matching a character class. This is essentially a regular
+ # expression, but you should only match a single character.
+ #
+ # Example:
+ #
+ # match('[ab]') # will match either 'a' or 'b'
+ # match('[\n\s]') # will match newlines and spaces
+ #
def match(obj)
Atoms::Re.new(obj)
end
module_function :match
+ # Returns an atom matching the +str+ given.
+ #
+ # Example:
+ #
+ # str('class') # will match 'class'
+ #
def str(str)
Atoms::Str.new(str)
end
module_function :str
+ # Returns an atom matching any character.
+ #
def any
Atoms::Re.new('.')
end
module_function :any
- # Tree matching ------------------------------------------------------------
-
+ # Returns a placeholder for a tree transformation that will only match a
+ # sequence of elements. The +symbol+ you specify will be the key for the
+ # matched sequence in the returned dictionary.
+ #
+ # Example:
+ #
+ # # This would match a body element that contains several declarations.
+ # { :body => sequence(:declarations) }
+ #
def sequence(symbol)
Pattern::SequenceBind.new(symbol)
end

0 comments on commit da93a07

Please sign in to comment.