Created
August 24, 2013 23:00
-
-
Save baroquebobcat/6330888 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Parslet::Atoms::DSL | |
| def raw_as(name) | |
| Parslet::Atoms::RawAttribute.new self, name | |
| end | |
| end | |
| class Parslet::Atoms::RawAttribute < Parslet::Atoms::Base | |
| attr_reader :parslet, :name | |
| def initialize(parslet, name) | |
| super() | |
| @parslet, @name = parslet, name | |
| end | |
| def apply(source, context, consume_all) | |
| start = source.pos | |
| success, inner_value = result = parslet.apply(source, context, consume_all) | |
| return result unless success | |
| succ([:sequence, inner_value, {name => grab_raw_text(source, start)}]) | |
| end | |
| def grab_raw_text source, start | |
| finish = source.pos | |
| source.pos = start | |
| source.consume finish - start | |
| ensure | |
| source.pos = finish | |
| end | |
| def to_s_inner(prec) | |
| "#{name}:#{parslet.to_s(prec)}" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks good.
Why using a :sequence tag at L21? This would need some reasoning about.