Created
October 30, 2010 20:55
-
-
Save mjackson/655733 to your computer and use it in GitHub Desktop.
A small demonstration of how to use string interpolation in a Citrus grammar.
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
require 'citrus' | |
Citrus.eval(<<'CODE') | |
grammar Days | |
rule every_n_days | |
('every ' number ' days') { | |
"INTERVAL=#{number}" | |
} | |
end | |
rule number | |
[0-9]+ | |
end | |
end | |
CODE | |
# grammar :Days do | |
# rule :every_n_days do | |
# all('every ', :number, ' days') { | |
# "INTERVAL=#{number}" | |
# } | |
# end | |
# | |
# rule :number do | |
# /[0-9]+/ | |
# end | |
# end | |
if $0 == __FILE__ | |
require 'test/unit' | |
class DaysTest < Test::Unit::TestCase | |
def test_every_n_days | |
match = Days.parse('every 5 days') | |
assert(match) | |
assert_equal('INTERVAL=5', match.value) | |
match = Days.parse('every 365 days') | |
assert(match) | |
assert_equal('INTERVAL=365', match.value) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment