Sha256: 92d045fb8365063d1ce2fef858df5343c0ffac804dbb3c0cdfb1dbeefed664b9

Contents?: true

Size: 998 Bytes

Versions: 1

Compression:

Stored size: 998 Bytes

Contents

# 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. 
# 
# NOT FINISHED & EXPERIMENTAL
#
class Parslet::Expression
  include Parslet
  
  autoload :Treetop, 'parslet/expression/treetop'
  
  def initialize(str, opts={})
    @type = opts[:type] || :treetop
    @exp = str
    @parslet = transform(
      parse(str))
  end
  
  # Transforms the parse tree into a parslet expression. 
  #
  def transform(tree)
    transform = Treetop::Transform.new
    
    # pp tree
    transform.apply(tree)
  end
  
  # Parses the string and returns a parse tree.
  #
  def parse(str)
    parser = Treetop::Parser.new
    parser.parse(str)
  end

  # Turns this expression into a parslet.
  #
  def to_parslet
    @parslet
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
parslet-0.11.0 lib/parslet/expression.rb