Annotation of parser3/src/main/pa_dictionary.C, revision 1.17.2.6.2.6
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.6! paf 8: static const char* IDENT_DICTIONARY_C="$Date: 2003/03/21 14:49:00 $";
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.5 paf 18: if(a->is_empty()) {
1.14 paf 19: throw Exception("parser.runtime",
1.17.2.6.2.5 paf 20: 0, //&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.17.2.6.2.6! paf 30: // clear starting_lines
! 31: memset(starting_line_of, 0, sizeof(starting_line_of));
1.1 parser 32: // grab first letters of first column of a table
1.17.2.6.2.3 paf 33: constructor_line=1; table.for_each(pa_dictionary_add_first, this);
1.1 parser 34: }
35:
1.4 parser 36: #ifndef DOXYGEN
1.17.2.6.2.4 paf 37: struct First_that_begins_info {
1.4 parser 38: int line;
1.17.2.6.2.3 paf 39: const char* str;
1.4 parser 40: };
41: #endif
1.17.2.6.2.4 paf 42: static bool starts(Table::element_type row, First_that_begins_info* info) {
1.4 parser 43: // skip irrelevant lines
1.17.2.1 paf 44: if(info->line>1) {
45: --info->line;
1.4 parser 46: return 0;
47: }
1.1 parser 48:
1.17.2.6.2.3 paf 49: return row->get(0)->this_starts(info->str);
1.1 parser 50: }
1.17.2.6.2.4 paf 51: Table::element_type Dictionary::first_that_begins(const char* str) const {
52: First_that_begins_info info;
1.17.2.6.2.3 paf 53: if(info.line=starting_line_of[(unsigned char)*str]) {
54: info.str=str;
55: return table.first_that(starts, &info);
1.4 parser 56: } else
1.17.2.2 paf 57: return Table::element_type(0);
1.1 parser 58: }
E-mail: