Annotation of parser3/src/main/pa_dictionary.C, revision 1.17.2.6.2.3
1.1 parser 1: /** @file
2: Parser: dictionary class impl.
3:
1.17.2.4 paf 4: Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
1.12 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.15 paf 6: */
1.1 parser 7:
1.17.2.6.2.3! paf 8: static const char* IDENT_DICTIONARY_C="$Date: 2003/03/20 09:41:46 $";
1.1 parser 9:
10: #include "pa_dictionary.h"
1.4 parser 11: #include "pa_exception.h"
1.1 parser 12:
1.17.2.6 paf 13: // could not make this static: gcc complains "prev decl was extern"
14: void pa_dictionary_add_first(Table::element_type row, Dictionary* self) {
1.4 parser 15: // get a=>b values
1.17.2.6.2.3! paf 16: const String* a=row->get(0);
1.4 parser 17: // empty 'a' check
1.17.2.6.2.3! paf 18: if(!*a) {
1.14 paf 19: throw Exception("parser.runtime",
1.17.2.1 paf 20: a,
1.4 parser 21: "dictionary table 'from' column elements must not be empty");
22: }
1.17.2.1 paf 23: unsigned char c=(unsigned char)a->first_char();
24: if(!self->starting_line_of[c])
25: self->starting_line_of[c]=self->constructor_line;
26:
27: self->constructor_line++;
1.1 parser 28: }
1.17.2.6.2.3! paf 29: Dictionary::Dictionary(Table& atable): table(atable) {
1.1 parser 30: // grab first letters of first column of a table
1.17.2.6.2.3! paf 31: constructor_line=1; table.for_each(pa_dictionary_add_first, this);
1.1 parser 32: }
33:
1.4 parser 34: #ifndef DOXYGEN
35: struct First_that_starts_info {
36: int line;
1.17.2.6.2.3! paf 37: const char* str;
1.4 parser 38: };
39: #endif
1.17.2.1 paf 40: static bool starts(Table::element_type row, First_that_starts_info* info) {
1.4 parser 41: // skip irrelevant lines
1.17.2.1 paf 42: if(info->line>1) {
43: --info->line;
1.4 parser 44: return 0;
45: }
1.1 parser 46:
1.17.2.6.2.3! paf 47: return row->get(0)->this_starts(info->str);
1.1 parser 48: }
1.17.2.6.2.3! paf 49: Table::element_type Dictionary::first_that_starts(const char* str) const {
1.4 parser 50: First_that_starts_info info;
1.17.2.6.2.3! paf 51: if(info.line=starting_line_of[(unsigned char)*str]) {
! 52: info.str=str;
! 53: return table.first_that(starts, &info);
1.4 parser 54: } else
1.17.2.2 paf 55: return Table::element_type(0);
1.1 parser 56: }
E-mail: