public
Created

Inheritance with multiple Citrus grammars

  • Download Gist
Gemfile
Ruby
1 2 3
source :rubygems
gem "citrus"
gem "rspec"
spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
require 'rubygems' unless RUBY_VERSION >= "1.9"
require 'citrus'
 
Citrus.eval <<-EOF
grammar WithPar
rule function
/[a-z]/+ parens
end
rule parens '()' end
end
grammar WithBrack
include WithPar
root function
rule parens '{}' end
end
EOF
 
describe "inheritance in Citrus" do
it 'WithPar should use parentheses' do
WithPar.parse("hello()").should_not be_nil
end
it 'WithBrack should not allow parentheses' do
lambda{ WithBrack.parse("hello()") }.should raise_error(Citrus::ParseError)
end
it 'WithBrack should use brackets' do
WithBrack.parse("hello{}").should_not be_nil
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.