diff options
author | Peter Mikkelsen <peter@pmikkelsen.com> | 2021-06-29 16:28:09 +0000 |
---|---|---|
committer | Peter Mikkelsen <peter@pmikkelsen.com> | 2021-06-29 16:28:09 +0000 |
commit | 8fdf0bc6e9770e2cea4d8e18299ff5a8a9aa0802 (patch) | |
tree | 34f90a0006bf6e06be587cd0d7a71aa8408b8c9c /parser.c | |
parent | 02145f06ac007d730bc16930185fe18fa3e76c68 (diff) |
Fix some parser errors, and accept clauses without a body
Diffstat (limited to 'parser.c')
-rw-r--r-- | parser.c | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -99,19 +99,19 @@ prologtext(void) return; Term *t = fullterm(AtomTok, L".", nil); - if(t->tag != CompoundTerm || runestrcmp(t->text, L":-") != 0 || !(t->arity == 1 || t->arity == 2)){ - print("Expected directive or clause as toplevel\n"); - print("Got %S\n", prettyprint(t)); - print("Tag=%d arity=%d text=\"%S\"\n", t->tag, t->arity, t->text); - syntaxerror("prologtext"); - } - if(t->arity == 1){ - /* A directive */ + if(t->tag == CompoundTerm && runestrcmp(t->text, L":-") == 0 && t->arity == 1){ + /* A Directive */ print("Got directive: %S\n", prettyprint(t)); + }else if(t->tag == CompoundTerm && runestrcmp(t->text, L":-") == 0 && t->arity == 2){ + /* A clause with a body */ + print("Got clause with body: %S\n", prettyprint(t)); + }else if(t->tag == AtomTerm || t->tag == CompoundTerm){ + /* A clause without a body */ + print("Got clause without body: %S\n", prettyprint(t)); }else{ - /* A clause */ - print("Got clause: %S\n", prettyprint(t)); + print("Expected directive or clause as toplevel\n"); + syntaxerror("prologtext"); } if(lookahead.tag == AtomTok && runestrcmp(lookahead.text, L".") == 0) @@ -537,6 +537,11 @@ Integer: exits("lexer"); Functor: + if(peek == Beof){ + Bgetrune(parsein); + return; + } + peek = Bgetrune(parsein); if(peek == L'(') lookahead.tag = FunctorTok; @@ -556,6 +561,6 @@ match(int tag) void syntaxerror(char *where) { - print("Syntax error: Unexpected %d token in %s\n", lookahead.tag, where); + print("Syntax error: Unexpected %d (%S) token in %s\n", lookahead.tag, lookahead.text, where); exits("syntax error"); }
\ No newline at end of file |