tree drd_info_rep::get_syntax (tree t, path p) { if (is_atomic (t)) { string s= t->label; if (N(s) == 1 || !existing_tree_label (s)) return UNINIT; return get_syntax (as_tree_label (s)); } else if (is_func (t, VALUE, 1) && is_atomic (t[0])) { string s= t[0]->label; if (!existing_tree_label (s)) return UNINIT; return get_syntax (as_tree_label (s)); } else if (L(t) < START_EXTENSIONS) return UNINIT; else { tree fun= the_drd->get_syntax (L(t)); if (fun == UNINIT) return UNINIT; else if (N(t) == 0 && !is_func (fun, MACRO)) return fun; else if (!is_func (fun, MACRO)) return UNINIT; else { int i, n= N(fun)-1; hashmap<tree,tree> tab (UNINIT); for (i=0; i<n; i++) { tree var= tree (ARG, fun[i]); tree val= ""; if (i < N(t)) { if (p == path (-1)) val= t[i]; else val= tree (QUASI, t[i], (tree) (p * i)); } tab (var)= val; } return replace (fun[n], tab); } } }
bool drd_info_rep::contains (string l) { return existing_tree_label (l) && info->contains (as_tree_label (l)); }
void packrat_parser_rep::serialize (tree t, path p) { if (is_nil (p) || p->item != -1) current_start (p)= N(current_string); if (is_atomic (t)) { int begin= N(current_string); int pos=0; string s= t->label; while (true) { if (N(current_string) != begin + pos) if (is_nil (p) || p->item != -1) { //cout << p * pos << " <-> " << N(current_string) << LF; //cout << " " << s (0, pos) << LF; //cout << " " << current_string (begin, N(current_string)) << LF; current_path_pos (p * pos)= N(current_string); current_pos_path (N(current_string))= p * pos; } if (pos >= N(s)) break; int start= pos; tm_char_forwards (s, pos); if (pos == start+1) current_string << s[start]; else { // FIXME: where did we use this kind of syntactical substitutions? tree r (UNINIT); string ss= s (start, pos); if (N(ss) != 1 && existing_tree_label (ss)) r= the_drd->get_syntax (as_tree_label (ss)); //if (r != UNINIT) cout << "Rewrite " << ss << " -> " << r << "\n"; if (r == UNINIT) current_string << ss; else serialize (r, path (-1)); } } } else switch (L(t)) { case RAW_DATA: current_string << "<\\rawdata></>"; break; case DOCUMENT: case PARA: for (int i=0; i<N(t); i++) { serialize (t[i], p * i); current_string << "\n"; } break; case SURROUND: serialize (t[0], p * 0); serialize (t[2], p * 2); serialize (t[1], p * 1); break; case CONCAT: for (int i=0; i<N(t); i++) serialize (t[i], p * i); break; case RIGID: serialize (t[0], p * 0); break; case HIDDEN: break; case FREEZE: case UNFREEZE: serialize (t[0], p * 0); break; case HSPACE: case VAR_VSPACE: case VSPACE: case SPACE: case HTAB: break; case MOVE: case SHIFT: case RESIZE: case CLIPPED: serialize (t[0], p * 0); break; case WITH_LIMITS: case LINE_BREAK: case NEW_LINE: case NEXT_LINE: case NO_BREAK: case YES_INDENT: case NO_INDENT: case VAR_YES_INDENT: case VAR_NO_INDENT: case VAR_PAGE_BREAK: case PAGE_BREAK: case VAR_NO_PAGE_BREAK: case NO_PAGE_BREAK: case VAR_NO_BREAK_HERE: case NO_BREAK_HERE: case NO_BREAK_START: case NO_BREAK_END: case VAR_NEW_PAGE: case NEW_PAGE: case VAR_NEW_DPAGE: case NEW_DPAGE: break; case WIDE: case NEG: serialize (t[0], p * 0); break; case SYNTAX: serialize (t[1], path (-1)); break; case TFORMAT: case TWITH: case CWITH: case CELL: serialize (t[N(t)-1], p * (N(t)-1)); break; case WITH: if (t[0] == "mode" && t[1] != "math"); else serialize (t[N(t)-1], p * (N(t)-1)); break; case VALUE: { tree r= the_drd->get_syntax (t); //if (r != UNINIT) cout << "Rewrite " << t << " -> " << r << "\n"; if (r != UNINIT) serialize (r, path (-1)); else serialize_compound (t, p); break; } case STYLE_WITH: case VAR_STYLE_WITH: case LOCUS: serialize (t[N(t)-1], p * (N(t)-1)); break; case ID: case HARD_ID: case LINK: case URL: case SCRIPT: case OBSERVER: case FIND_ACCESSIBLE: break; case HLINK: case ACTION: serialize (t[0], p * 0); break; case SET_BINDING: case GET_BINDING: case LABEL: case REFERENCE: case PAGEREF: case GET_ATTACHMENT: case WRITE: case TOC_NOTIFY: break; case SPECIFIC: serialize (t[1], p * 1); break; case FLAG: break; case HYPHENATE_AS: serialize (t[1], p * 1); break; default: serialize_compound (t, p); break; } if (is_nil (p) || p->item != -1) current_end (p)= N(current_string); }