Skip to content

Instantly share code, notes, and snippets.

@blambeau
Created January 13, 2012 13:22
Show Gist options
  • Save blambeau/1606092 to your computer and use it in GitHub Desktop.
Save blambeau/1606092 to your computer and use it in GitHub Desktop.
Inheritance with multiple Citrus grammars
source :rubygems
gem "citrus"
gem "rspec"
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment