summaryrefslogtreecommitdiff
path: root/decoder/grammar.cc
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2010-12-12 15:32:19 -0500
committerChris Dyer <cdyer@cs.cmu.edu>2010-12-12 15:32:19 -0500
commit8c16b9384e8b85abf9e51bc670e548bf5cd4a0c5 (patch)
tree83cb68bb8c884fcf14aa33eddf88f428ad60f807 /decoder/grammar.cc
parentb8f314dddda3d440164e4772830e3c951ba06ee4 (diff)
facility for adding programmitically generated grammars
Diffstat (limited to 'decoder/grammar.cc')
-rw-r--r--decoder/grammar.cc12
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 {