Created
October 12, 2018 11:30
-
-
Save binford2k/f377e74bc44f2062cf9a7bb92fb470cf 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
12:29 $ ./label_provider.rb | |
Object (label provider is incomplete for Puppet::Pops::Model::Factory) | |
12:29 $ |
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
#! /usr/bin/env ruby | |
$LOAD_PATH.unshift '/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/' | |
require 'puppet' | |
require 'puppet/parser' | |
# Following the pattern in http://puppet-on-the-edge.blogspot.com/2014/02/puppet-internals-polymorphic-dispatch.html | |
class LabelProvider | |
def initialize | |
@label_visitor = Puppet::Pops::Visitor.new(self, "label") | |
end | |
def label(o) | |
@label_visitor.visit(o) | |
end | |
protected | |
def label_ArithmeticExpression(o) | |
"#{o.operator} Expression" # i.e. '+ Expression', '- Expression' etc. | |
end | |
def label_String(o) | |
"String" | |
end | |
def label_Regexp(o) | |
"Regular Expression" | |
end | |
def label_Object(o) | |
"Object (label provider is incomplete for #{o.class})" | |
end | |
end | |
filename = '/Users/ben/Projects/binford2k-itemize/manifests/init.pp' | |
parser = Puppet::Pops::Parser::EvaluatingParser.new | |
source = Puppet::FileSystem.read(filename) | |
result = parser.parse_string(source, filename) | |
provider = LabelProvider.new | |
# require 'pry' | |
# binding.pry | |
puts provider.label(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment