Skip to content
This repository
Browse code

. Some documentation (preparing for release)

  • Loading branch information...
commit da93a075478fc426345e23d2650e2495f1345bc2 1 parent ee60fd1
Kaspar Schiess authored

Showing 2 changed files with 26 additions and 6 deletions. Show diff stats Hide diff stats

  1. +1 0  .gitignore
  2. +25 6 lib/parslet.rb
1  .gitignore
... ... @@ -0,0 +1 @@
  1 +doc
31 lib/parslet.rb
@@ -6,8 +6,6 @@ def self.included(base)
6 6 end
7 7
8 8 module ClassMethods
9   - # Parser structure ---------------------------------------------------------
10   -
11 9 # Define an entity for the parser. This generates a method of the same name
12 10 # that can be used as part of other patterns. Those methods can be freely
13 11 # mixed in your parser class with real ruby methods.
@@ -36,25 +34,46 @@ def rule(name, &definition)
36 34 end
37 35 end
38 36
39   - # Text matching ------------------------------------------------------------
40   -
  37 + # Returns an atom matching a character class. This is essentially a regular
  38 + # expression, but you should only match a single character.
  39 + #
  40 + # Example:
  41 + #
  42 + # match('[ab]') # will match either 'a' or 'b'
  43 + # match('[\n\s]') # will match newlines and spaces
  44 + #
41 45 def match(obj)
42 46 Atoms::Re.new(obj)
43 47 end
44 48 module_function :match
45 49
  50 + # Returns an atom matching the +str+ given.
  51 + #
  52 + # Example:
  53 + #
  54 + # str('class') # will match 'class'
  55 + #
46 56 def str(str)
47 57 Atoms::Str.new(str)
48 58 end
49 59 module_function :str
50 60
  61 + # Returns an atom matching any character.
  62 + #
51 63 def any
52 64 Atoms::Re.new('.')
53 65 end
54 66 module_function :any
55 67
56   - # Tree matching ------------------------------------------------------------
57   -
  68 + # Returns a placeholder for a tree transformation that will only match a
  69 + # sequence of elements. The +symbol+ you specify will be the key for the
  70 + # matched sequence in the returned dictionary.
  71 + #
  72 + # Example:
  73 + #
  74 + # # This would match a body element that contains several declarations.
  75 + # { :body => sequence(:declarations) }
  76 + #
58 77 def sequence(symbol)
59 78 Pattern::SequenceBind.new(symbol)
60 79 end

0 comments on commit da93a07

Please sign in to comment.
Something went wrong with that request. Please try again.