Skip to content

Instantly share code, notes, and snippets.

@baroquebobcat
Created August 24, 2013 23:00
Show Gist options
  • Select an option

  • Save baroquebobcat/6330888 to your computer and use it in GitHub Desktop.

Select an option

Save baroquebobcat/6330888 to your computer and use it in GitHub Desktop.
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
@kschiess

Copy link
Copy Markdown

Looks good.

Why using a :sequence tag at L21? This would need some reasoning about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment