diff options
author | Adrian Thurston <thurston@complang.org> | 2008-11-08 19:07:15 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2008-11-08 19:07:15 +0000 |
commit | 3ba29973c2e9c97072d0733c5eb3bf543a1f85ce (patch) | |
tree | 2d2c763dccc31e07a52958440d4d95b8a89aad01 | |
parent | ef7a4e1818ac2e0d80bb3beb8cd80ab51a98548e (diff) | |
download | colm-3ba29973c2e9c97072d0733c5eb3bf543a1f85ce.tar.gz |
A global commit with revertOn cannot clear the parsed fields from Alg. Shown by
commitbt.lm test.
-rw-r--r-- | colm/pdarun.cpp | 21 | ||||
-rw-r--r-- | test/commitbt.in | 1 | ||||
-rw-r--r-- | test/commitbt.lm | 110 |
3 files changed, 130 insertions, 2 deletions
diff --git a/colm/pdarun.cpp b/colm/pdarun.cpp index ef22665e..43618025 100644 --- a/colm/pdarun.cpp +++ b/colm/pdarun.cpp @@ -102,6 +102,20 @@ long PdaRun::stackTopTarget() return state; } +/* + * Local commit: + * -clears reparse flags underneath + * -must be possible to backtrack after + * Global commit (revertOn) + * -clears all reparse flags + * -must be possible to backtrack after + * Global commit (!revertOn) + * -clears all reparse flags + * -clears all 'parsed' reverse code + * -clears all reverse code + * -clears all alg structures + */ + bool beenCommitted( Kid *kid ) { return kid->tree->alg->flags & AF_COMMITTED; @@ -204,7 +218,7 @@ head: /* Commit */ #ifdef COLM_LOG_PARSE - cerr << "rev free visiting: " << + cerr << "parsed_downref_kid visiting: " << prg->rtd->lelInfo[lel->tree->id].name << endl; #endif @@ -251,7 +265,10 @@ void PdaRun::commit() while ( topLevel > 0 ) { kid = (Kid*)vm_pop(); commitKid( sp, kid ); - parsed_downref_kid( sp, prg, kid ); + + /* Can't do this here. See commitbt.lm. */ + /* parsed_downref_kid( sp, prg, kid ); */ + topLevel -= 1; } diff --git a/test/commitbt.in b/test/commitbt.in new file mode 100644 index 00000000..24a7dece --- /dev/null +++ b/test/commitbt.in @@ -0,0 +1 @@ +1 2 3 *
\ No newline at end of file diff --git a/test/commitbt.lm b/test/commitbt.lm new file mode 100644 index 00000000..75172b4b --- /dev/null +++ b/test/commitbt.lm @@ -0,0 +1,110 @@ +# +# Local commit: +# -clears reparse flags underneath +# -must be possible to backtrack after +# Global commit (revertOn) +# -clears all reparse flags +# -must be possible to backtrack after +# Global commit (!revertOn) +# -clears all reparse flags +# -clears all 'parsed' reverse code +# -clears all reverse code +# -clears all alg structures +# + +# This test shows that a global commit with revertOn cannot clear 'parsed' +# items because it must entertain the possibility of backtracking. + +lex start +{ + ignore /[\t\n ]+/ + literal '^', '|', '-', ',', ':', '!', '?', '.' + literal '(', ')', '{', '}', '*', '&', '+' + + literal '--', ':>', ':>>', '<:', '->', '**' + + token word /[a-zA-Z_][a-zA-Z0-9_]*/ + token uint /[0-9]+/ +} + + +def expression [term expression_op*] + +def expression_op + ['|' term] +| ['&' term] +| ['-' term] +| ['--' term] + +def term [factor_rep term_rest] + +# This list is done manually to get shortest match. +def term_rest + [] +| [term_op term_rest] + +def term_op + [factor_rep] +| ['.' factor_rep] +| [':>' factor_rep] +| [':>>' factor_rep] +| ['<:' factor_rep] + +def factor_rep + [factor_neg factor_rep_op*] + +def factor_rep_op + ['*'] +| ['**'] +| ['?'] +| ['+'] +| ['{' factor_rep_num '}'] +| ['{' ',' factor_rep_num '}'] +| ['{' factor_rep_num ',' '}'] +| ['{' factor_rep_num ',' factor_rep_num '}'] + +def factor_rep_num [uint] + +def factor_neg + ['!' factor_neg] +| ['^' factor_neg] +| [factor] + +def factor + [alphabet_num] +| [word] +| ['(' expression ')'] + +def alphabet_num + [uint] + +global int i + +def suint + int i + [uint] + { + lhs.i = 0 + i = 1 + lhs = construct suint "1" + } + +def sub + [suint* '*'] + +token item + sub S + /[0-9]+/ + { + str M = pull(stdin, match_length) + sub S = parse sub(stdin) + send( make_token( typeid item, M, S ) ) + } + +def stuff + [item* '!'] +| [sub] + +stuff S = parse stuff(stdin) + +print_xml( S ) |