Created
August 12, 2015 16:16
-
-
Save yorickpeterse/46b22a758641eefb6369 to your computer and use it in GitHub Desktop.
This file contains 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
def on_call_lang(input, arg, &block) | |
lang_var = unique_literal('lang') | |
node = unique_literal('node') | |
found = unique_literal('found') | |
xml_lang = unique_literal('xml_lang') | |
matched = unique_literal('matched') | |
conversion = literal(Conversion) | |
ast = lang_var.assign(try_match_first_node(arg, input)) | |
.followed_by(lang_var.assign(conversion.to_string(lang_var))) | |
.followed_by(matched.assign(self.false)) | |
.followed_by(node.assign(input)) | |
.followed_by(xml_lang.assign(string('xml:lang'))) | |
.followed_by do | |
node.respond_to?(symbol(:attribute)).while_true do | |
found.assign(node.get(xml_lang)) | |
.followed_by do | |
found.if_true do | |
found.eq(lang_var) | |
.if_true do | |
if block_given? | |
yield | |
else | |
matched.assign(self.true) | |
.followed_by(send_message(:break)) | |
end | |
end | |
.else { send_message(:break) } | |
end | |
end | |
.followed_by(node.assign(node.parent)) | |
end | |
end | |
block_given? ? ast : ast.followed_by(matched) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment