Skip to content

Commit

Permalink
. Updates readme to include latest API
Browse files Browse the repository at this point in the history
  • Loading branch information
kschiess committed Mar 22, 2010
1 parent 1d382c2 commit ba3ef46
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
20 changes: 16 additions & 4 deletions README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# INTRODUCTION
INTRODUCTION

A small experiment on PEG grammars. PEG means Parsing Expression Grammars [1].
These are a different kind of grammars that recognize almost the same
Expand All @@ -19,8 +19,9 @@ debugging and error generation.
[1] http://en.wikipedia.org/wiki/Parsing_expression_grammar
[2] http://pdos.csail.mit.edu/~baford/packrat/popl04/peg-popl04.pdf

# SYNOPSIS
SYNOPSIS

require 'pp'
require 'parslet'
include Parslet

Expand All @@ -42,9 +43,20 @@ debugging and error generation.
# Here's how you can grab results from that tree:
require 'rexp_matcher'
RExpMatcher.new(tree).
match({:string => :_x}) { |d| puts "String contents: #{d[:x]}" }
match({:string => :_x}) { |d| puts "String contents: #{d[:x]}" }

# STATUS
# Here's how to transform that tree into something else
require 'tree_transform'
class StringLiteral < Struct.new(:text); end
transform = TreeTransform.new
transform.rule(:string => :_x) { |d| StringLiteral.new(d[:x]) }

transform.apply(tree)
# => #<struct StringLiteral text="This is a \\\"String\\\" ... escape stuff">

# Voilà

STATUS

This is in a usable alpha state, although I've only just begun working on the
above goals. Maybe I will incorporate this into rooc
Expand Down
12 changes: 12 additions & 0 deletions example/readme.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
$:.unshift '../lib'

require 'pp'
require 'parslet'
include Parslet

Expand All @@ -22,3 +23,14 @@
require 'rexp_matcher'
RExpMatcher.new(tree).
match({:string => :_x}) { |d| puts "String contents: #{d[:x]}" }

# Here's how to transform that tree into something else
require 'tree_transform'
class StringLiteral < Struct.new(:text); end
transform = TreeTransform.new
transform.rule(:string => :_x) { |d| StringLiteral.new(d[:x]) }

transform.apply(tree)
# => #<struct StringLiteral text="This is a \\\"String\\\" ... escape stuff">

# Voilà

0 comments on commit ba3ef46

Please sign in to comment.