diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2010-12-12 15:32:19 -0500 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2010-12-12 15:32:19 -0500 |
commit | 8c16b9384e8b85abf9e51bc670e548bf5cd4a0c5 (patch) | |
tree | 83cb68bb8c884fcf14aa33eddf88f428ad60f807 /decoder/grammar.cc | |
parent | b8f314dddda3d440164e4772830e3c951ba06ee4 (diff) |
facility for adding programmitically generated grammars
Diffstat (limited to 'decoder/grammar.cc')
-rw-r--r-- | decoder/grammar.cc | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/decoder/grammar.cc b/decoder/grammar.cc index bbe2f01a..7e6bbc66 100644 --- a/decoder/grammar.cc +++ b/decoder/grammar.cc @@ -77,6 +77,12 @@ TextGrammar::TextGrammar(const string& file) : ReadFromFile(file); } +TextGrammar::TextGrammar(istream* in) : + max_span_(10), + pimpl_(new TGImpl) { + ReadFromStream(in); +} + const GrammarIter* TextGrammar::GetRoot() const { return &pimpl_->root_; } @@ -107,7 +113,11 @@ static void AddRuleHelper(const TRulePtr& new_rule, const unsigned int ctf_level void TextGrammar::ReadFromFile(const string& filename) { ReadFile in(filename); - RuleLexer::ReadRules(in.stream(), &AddRuleHelper, this); + ReadFromStream(in.stream()); +} + +void TextGrammar::ReadFromStream(istream* in) { + RuleLexer::ReadRules(in, &AddRuleHelper, this); } bool TextGrammar::HasRuleForSpan(int /* i */, int /* j */, int distance) const { |