diff options
author | Adrian Thurston <thurston@complang.org> | 2012-09-15 14:30:57 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-09-15 14:30:57 -0400 |
commit | ccecc7cbc893d90630b341f120b45ec18a65e954 (patch) | |
tree | dc815c4d0483db902079e75ddadcb72a4dfef383 | |
parent | 0ffd931959c0372dcc08b039a27f85d4181cd39f (diff) | |
download | colm-ccecc7cbc893d90630b341f120b45ec18a65e954.tar.gz |
simple parse error reporting for constructor and matching
Giving the location of the pattern/constructor and then the location within it.
Really should give the absolute position instead of the relatvie. That should
come later.
-rw-r--r-- | colm/compiler.cc | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/colm/compiler.cc b/colm/compiler.cc index c3887fd0..73436cd5 100644 --- a/colm/compiler.cc +++ b/colm/compiler.cc @@ -1292,29 +1292,37 @@ void Compiler::parsePatterns() Tree **sp = prg->stackRoot; - for ( ConsList::Iter repl = replList; repl.lte(); repl++ ) { + for ( ConsList::Iter cons = replList; cons.lte(); cons++ ) { //cerr << "parsing replacement at " << - // repl->loc.line << ' ' << repl->loc.col << endl; + // cons->loc.line << ' ' << cons->loc.col << endl; InputStream *in = new InputStream; FsmRun *fsmRun = new FsmRun; - repl->pdaRun = new PdaRun; + cons->pdaRun = new PdaRun; initInputStream( in ); - initPdaRun( repl->pdaRun, prg, pdaTables, fsmRun, repl->langEl->parserId, 0, false, 0 ); + initPdaRun( cons->pdaRun, prg, pdaTables, fsmRun, cons->langEl->parserId, 0, false, 0 ); initFsmRun( fsmRun, prg ); Stream *res = streamAllocate( prg ); res->id = LEL_ID_STREAM; - res->in = newSourceStreamCons( repl ); + res->in = newSourceStreamCons( cons ); appendStream( in, (Tree*)res ); setEof( in ); - newToken( prg, repl->pdaRun, fsmRun ); - long pcr = parseLoop( prg, sp, repl->pdaRun, fsmRun, in, PcrStart ); + newToken( prg, cons->pdaRun, fsmRun ); + long pcr = parseLoop( prg, sp, cons->pdaRun, fsmRun, in, PcrStart ); assert( pcr == PcrDone ); - if ( repl->pdaRun->parseError ) - cout << "parse error" << endp; + if ( cons->pdaRun->parseError ) { + cout << "PARSE ERROR " << cons->loc.line << ":" << cons->loc.col; + + if ( cons->pdaRun->parseErrorText != 0 ) { + cout << ", offset into constructor " << + cons->pdaRun->parseErrorText->tokdata->data; + } + + cout << endl; + } } for ( PatList::Iter pat = patternList; pat.lte(); pat++ ) { @@ -1338,8 +1346,17 @@ void Compiler::parsePatterns() newToken( prg, pat->pdaRun, fsmRun ); long pcr = parseLoop( prg, sp, pat->pdaRun, fsmRun, in, PcrStart ); assert( pcr == PcrDone ); - if ( pat->pdaRun->parseError ) - cout << "parse error" << endp; + if ( pat->pdaRun->parseError ) { + cout << "PARSE ERROR " << pat->loc.line << + ":" << pat->loc.col; + + if ( pat->pdaRun->parseErrorText != 0 ) { + cout << ", offset into pattern " << + pat->pdaRun->parseErrorText->tokdata->data; + } + + cout << endl; + } } fillInPatterns( prg ); |