Created
January 13, 2012 13:22
-
-
Save blambeau/1606092 to your computer and use it in GitHub Desktop.
Inheritance with multiple Citrus grammars
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
source :rubygems | |
gem "citrus" | |
gem "rspec" |
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 '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