Skip to content

Instantly share code, notes, and snippets.

@mjackson
Created October 30, 2010 20:55
Show Gist options
  • Save mjackson/655733 to your computer and use it in GitHub Desktop.
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.
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