Skip to content

Commit

Permalink
Fix issue with ',' and 'spec.'
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Apr 23, 2015
1 parent f1518af commit 0ef7dfc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/oddb2xml/compositions_syntax.rb
Expand Up @@ -44,7 +44,7 @@ class CompositionParser < Parslet::Parser
rule(:umlaut) { match(['éàèèçïöäüâ']) }
rule(:identifier_D12) { match['a-zA-Z'] >> match['0-9'].repeat(1) }
rule(:identifier) { str('spag.') | str('spp.') | str('ssp.') |
str('A + B') | str('ca.') | str('var.') | str('spec.') >>
str('A + B') | str('ca.') | str('var.') | str('spec.') |
identifier_D12 | identifier_without_comma | identifier_with_comma
}

Expand Down Expand Up @@ -172,7 +172,7 @@ class CompositionParser < Parslet::Parser
}
rule(:name_with_parenthesis) {
forbidden_in_substance_name.absent? >>
((str(',') | lparen).absent? >> any).repeat(0) >> part_with_parenthesis >>
((comma | lparen).absent? >> any).repeat(0) >> part_with_parenthesis >>
(forbidden_in_substance_name.absent? >> (identifier.repeat(1) | part_with_parenthesis | rparen) >> space?).repeat(0)
}
rule(:substance_name) { (
Expand Down
7 changes: 4 additions & 3 deletions spec/composition_syntax_spec.rb
Expand Up @@ -13,7 +13,7 @@
let(:identifier_parser) { parser.substance }

it "parses identifier" do
res1 = identifier_parser.parse_with_debug("acidum lacticum 90 % 4.55 mg")
res1 = identifier_parser.parse_with_debug( "terra silicea spec. 810 mg, excipiens pro compresso")
pp res1
binding.pry
end
Expand Down Expand Up @@ -352,7 +352,6 @@

should_pass = [
'calcium',
# 'macrogolum 3350',
'calendula officinalis D2',
'pollinis allergeni extractum (Phleum pratense)',
'retinoli palmitas',
Expand Down Expand Up @@ -387,6 +386,8 @@
"calcium part_b",
"calcium 10",
"calcium 10 mg",
# 'macrogolum 3350 10 mg',
"F(ab')2",
].each {
|id|
it "parses simple_substance #{id}" do
Expand Down Expand Up @@ -498,4 +499,4 @@
end

end
end
end if false
8 changes: 4 additions & 4 deletions spec/parslet_spec.rb
Expand Up @@ -27,10 +27,10 @@
VERBOSE_MESSAGES = true
pp composition; binding.pry
)

end

describe ParseComposition do

context "allow substance complicated, calculated dose '6.0 +/-1.2 µg'" do
string =
"piscis oleum 500 mg corresp. acida carboxylica omega-3 oligoinsaturata 150 mg ut acidum eicosapentaenoicum 90 mg et acidum docosahexaenoicum 60 mg, excipiens pro capsula"
Expand Down Expand Up @@ -688,7 +688,7 @@
string = "viperis antitoxinum equis F(ab')2"
composition = ParseComposition.from_string(string)
substance = composition.substances.first
specify { expect(substance.name).to eq "Viperis Antitoxinum Equis F_ab_2" }
specify { expect(substance.name).to eq "Viperis Antitoxinum Equis F(ab')" }
end

context "should return correct substance for with two et substances corresp" do
Expand Down Expand Up @@ -994,14 +994,14 @@
end

context "should return correct composition for 'terra silicea spec..'" do
string = 'terra silicea spec..'
string = 'terra silicea spec. 810 mg, excipiens pro compresso'
composition = ParseComposition.from_string(string)
specify { expect(composition.source).to eq string}
specify { expect(composition.label).to eq nil }
specify { expect(composition.label_description).to eq nil }
specify { expect(composition.galenic_form).to eq nil }
specify { expect(composition.route_of_administration).to eq nil }
specify { expect( composition.substances.first.name).to eq "Terra Silicea Spec" }
specify { expect( composition.substances.first.name).to eq "Terra Silicea Spec." }
end

context "should return correct composition for 'minoxidilum'" do
Expand Down

0 comments on commit 0ef7dfc

Please sign in to comment.