lib/wlang/dialect.rb in wlang-0.9.1 vs lib/wlang/dialect.rb in wlang-0.9.2
- old
+ new
@@ -49,10 +49,13 @@
attr_reader :parent
# Sub dialects by name
attr_reader :dialects
+ # Post transformer
+ attr_accessor :post_transformer
+
#
# Creates a dialect instance. _builder_ block is a chunk of code of the DSL
# that will be executed twice: once at construction time to create sub dialects
# nodes and install file extensions and once at building time to install ruleset
# and encoders.
@@ -121,11 +124,11 @@
# See RuleSet::add_rules
def add_rules(mod, pairs)
@ruleset = RuleSet.new if @ruleset.nil?
@ruleset.add_rules(mod, pairs)
end
-
+
### Query API ################################################################
# Returns qualified name of this dialect
def qualified_name
parentname = @parent.nil? ? "" : @parent.to_s
@@ -165,10 +168,22 @@
# found but not last of qualified name -> build it and delegate
child_dialect.build!
return child_dialect.dialect(name[1..-1])
end
end
+
+ # Applies post transformation
+ def apply_post_transform(text)
+ case self.post_transformer
+ when String
+ WLang::encode(text, self.post_transformer, {})
+ when Proc
+ self.post_transformer.call(text)
+ else
+ text
+ end
+ end
#
# Finds an encoder by name.
#
def encoder(name)
@@ -219,10 +234,11 @@
### Other utilities ##########################################################
# Factors a spacing friendly buffer for instantiation in this dialect
def factor_buffer
- IntelligentBuffer.new
+ #IntelligentBuffer.new
+ ""
end
# Returns a string representation
def to_s
qualified_name
\ No newline at end of file