Class: Parslet::Expression
- Inherits:
-
Object
- Object
- Parslet::Expression
- Includes:
- Parslet
- Defined in:
- lib/parslet/expression.rb
Overview
Allows specifying rules as strings using the exact same grammar that treetop does, minus the actions. This is on one hand a good example of a fully fledged parser and on the other hand might even turn out really useful.
This can be viewed as an extension to parslet and might even be hosted in its own gem one fine day.
Defined Under Namespace
Classes: Treetop
Instance Method Summary collapse
-
#initialize(str, opts = {}, context = self) ⇒ Expression
constructor
Creates a parslet from a foreign language expression.
-
#parse(str) ⇒ Object
Parses the string and returns a parse tree.
-
#to_parslet ⇒ Object
Turns this expression into a parslet.
-
#transform(tree) ⇒ Object
Transforms the parse tree into a parslet expression.
Methods included from Parslet
any, dynamic, exp, included, infix_expression, match, scope, sequence, simple, str, subtree
Constructor Details
#initialize(str, opts = {}, context = self) ⇒ Expression
20 21 22 23 24 25 |
# File 'lib/parslet/expression.rb', line 20 def initialize(str, opts={}, context=self) @type = opts[:type] || :treetop @exp = str @parslet = transform( parse(str)) end |
Instance Method Details
#parse(str) ⇒ Object
Parses the string and returns a parse tree.
41 42 43 44 |
# File 'lib/parslet/expression.rb', line 41 def parse(str) parser = Treetop::Parser.new parser.parse(str) end |
#to_parslet ⇒ Object
Turns this expression into a parslet.
48 49 50 |
# File 'lib/parslet/expression.rb', line 48 def to_parslet @parslet end |