Mercurial > vim
comparison src/regexp_nfa.c @ 4533:6a2005efa02b v7.3.1014
updated for version 7.3.1014
Problem: New regexp state dump is hard to read.
Solution: Make the state dump more pretty. (Taro Muraoka)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Sat, 25 May 2013 12:28:11 +0200 |
parents | 1be43c095aff |
children | 45f97c349537 |
comparison
equal
deleted
inserted
replaced
4532:e2c89fb27344 | 4533:6a2005efa02b |
---|---|
181 static int nfa_regbranch __ARGS((void)); | 181 static int nfa_regbranch __ARGS((void)); |
182 static int nfa_reg __ARGS((int paren)); | 182 static int nfa_reg __ARGS((int paren)); |
183 #ifdef DEBUG | 183 #ifdef DEBUG |
184 static void nfa_set_code __ARGS((int c)); | 184 static void nfa_set_code __ARGS((int c)); |
185 static void nfa_postfix_dump __ARGS((char_u *expr, int retval)); | 185 static void nfa_postfix_dump __ARGS((char_u *expr, int retval)); |
186 static void nfa_print_state __ARGS((FILE *debugf, nfa_state_T *state, int ident)); | 186 static void nfa_print_state __ARGS((FILE *debugf, nfa_state_T *state)); |
187 static void nfa_print_state2 __ARGS((FILE *debugf, nfa_state_T *state, garray_T *indent)); | |
187 static void nfa_dump __ARGS((nfa_regprog_T *prog)); | 188 static void nfa_dump __ARGS((nfa_regprog_T *prog)); |
188 #endif | 189 #endif |
189 static int *re2post __ARGS((void)); | 190 static int *re2post __ARGS((void)); |
190 static nfa_state_T *new_state __ARGS((int c, nfa_state_T *out, nfa_state_T *out1)); | 191 static nfa_state_T *new_state __ARGS((int c, nfa_state_T *out, nfa_state_T *out1)); |
191 static nfa_state_T *post2nfa __ARGS((int *postfix, int *end, int nfa_calc_size)); | 192 static nfa_state_T *post2nfa __ARGS((int *postfix, int *end, int nfa_calc_size)); |
1809 | 1810 |
1810 /* | 1811 /* |
1811 * Print the NFA starting with a root node "state". | 1812 * Print the NFA starting with a root node "state". |
1812 */ | 1813 */ |
1813 static void | 1814 static void |
1814 nfa_print_state(debugf, state, ident) | 1815 nfa_print_state(debugf, state) |
1815 FILE *debugf; | 1816 FILE *debugf; |
1816 nfa_state_T *state; | 1817 nfa_state_T *state; |
1817 int ident; | 1818 { |
1818 { | 1819 garray_T indent; |
1819 int i; | 1820 |
1821 ga_init2(&indent, 1, 64); | |
1822 ga_append(&indent, '\0'); | |
1823 nfa_print_state2(debugf, state, &indent); | |
1824 ga_clear(&indent); | |
1825 } | |
1826 | |
1827 static void | |
1828 nfa_print_state2(debugf, state, indent) | |
1829 FILE *debugf; | |
1830 nfa_state_T *state; | |
1831 garray_T *indent; | |
1832 { | |
1833 char_u *p; | |
1820 | 1834 |
1821 if (state == NULL) | 1835 if (state == NULL) |
1822 return; | 1836 return; |
1823 | 1837 |
1824 fprintf(debugf, "(%2d)", abs(state->id)); | 1838 fprintf(debugf, "(%2d)", abs(state->id)); |
1825 for (i = 0; i < ident; i++) | 1839 |
1826 fprintf(debugf, "%c", ' '); | 1840 /* Output indent */ |
1841 p = (char_u *)indent->ga_data; | |
1842 if (indent->ga_len >= 3) | |
1843 { | |
1844 int last = indent->ga_len - 3; | |
1845 char_u save[2]; | |
1846 | |
1847 STRNCPY(save, &p[last], 2); | |
1848 STRNCPY(&p[last], "+-", 2); | |
1849 fprintf(debugf, " %s", p); | |
1850 STRNCPY(&p[last], save, 2); | |
1851 } | |
1852 else | |
1853 fprintf(debugf, " %s", p); | |
1827 | 1854 |
1828 nfa_set_code(state->c); | 1855 nfa_set_code(state->c); |
1829 fprintf(debugf, "%s %s (%d) (id=%d)\n", | 1856 fprintf(debugf, "%s%s (%d) (id=%d)\n", |
1830 state->negated ? "NOT" : "", code, state->c, abs(state->id)); | 1857 state->negated ? "NOT " : "", code, state->c, abs(state->id)); |
1831 if (state->id < 0) | 1858 if (state->id < 0) |
1832 return; | 1859 return; |
1833 | 1860 |
1834 state->id = abs(state->id) * -1; | 1861 state->id = abs(state->id) * -1; |
1835 nfa_print_state(debugf, state->out, ident + 4); | 1862 |
1836 nfa_print_state(debugf, state->out1, ident + 4); | 1863 /* grow indent for state->out */ |
1864 indent->ga_len -= 1; | |
1865 if (state->out1) | |
1866 ga_concat(indent, "| "); | |
1867 else | |
1868 ga_concat(indent, " "); | |
1869 ga_append(indent, '\0'); | |
1870 | |
1871 nfa_print_state2(debugf, state->out, indent); | |
1872 | |
1873 /* replace last part of indent for state->out1 */ | |
1874 indent->ga_len -= 3; | |
1875 ga_concat(indent, " "); | |
1876 ga_append(indent, '\0'); | |
1877 | |
1878 nfa_print_state2(debugf, state->out1, indent); | |
1879 | |
1880 /* shrink indent */ | |
1881 indent->ga_len -= 3; | |
1882 ga_append(indent, '\0'); | |
1837 } | 1883 } |
1838 | 1884 |
1839 /* | 1885 /* |
1840 * Print the NFA state machine. | 1886 * Print the NFA state machine. |
1841 */ | 1887 */ |
1845 { | 1891 { |
1846 FILE *debugf = fopen(NFA_REGEXP_DUMP_LOG, "a"); | 1892 FILE *debugf = fopen(NFA_REGEXP_DUMP_LOG, "a"); |
1847 | 1893 |
1848 if (debugf != NULL) | 1894 if (debugf != NULL) |
1849 { | 1895 { |
1850 nfa_print_state(debugf, prog->start, 0); | 1896 nfa_print_state(debugf, prog->start); |
1851 fclose(debugf); | 1897 fclose(debugf); |
1852 } | 1898 } |
1853 } | 1899 } |
1854 #endif /* ENABLE_LOG */ | 1900 #endif /* ENABLE_LOG */ |
1855 #endif /* DEBUG */ | 1901 #endif /* DEBUG */ |
3503 #ifdef DEBUG | 3549 #ifdef DEBUG |
3504 fprintf(f, "\tRegexp is \"%s\"\n", nfa_regengine.expr); | 3550 fprintf(f, "\tRegexp is \"%s\"\n", nfa_regengine.expr); |
3505 #endif | 3551 #endif |
3506 fprintf(f, "\tInput text is \"%s\" \n", reginput); | 3552 fprintf(f, "\tInput text is \"%s\" \n", reginput); |
3507 fprintf(f, " =======================================================\n\n\n\n\n\n\n"); | 3553 fprintf(f, " =======================================================\n\n\n\n\n\n\n"); |
3508 nfa_print_state(f, start, 0); | 3554 nfa_print_state(f, start); |
3509 fprintf(f, "\n\n"); | 3555 fprintf(f, "\n\n"); |
3510 fclose(f); | 3556 fclose(f); |
3511 } | 3557 } |
3512 else | 3558 else |
3513 EMSG(_("Could not open temporary log file for writing ")); | 3559 EMSG(_("Could not open temporary log file for writing ")); |