Subject: Re: [SWIPL] DCG rules and error reporting

From: "Richard A. O'Keefe" <[email-masked]>
Date: Wed, 10 Oct 2001 11:27:13 +1300 (NZDT)

Keeping track of line numbers in DCGs?

(1) Split the parsing task into a tokenising task and a parsing task proper.
(2) In the tokenising task, either
    (a) attach source coordinates to every token.
        Instead of id(foo), use id(foo)*pos(L1,C1,L2,C2)
        where L1,C1 is where the token starts and L2,C2 is where it ends.
or  (b) attach source coordinates to selected token types,
or  (c) insert line change tokens.
(3) In the parsing task, either
    (x) construct source coordinates for non-terminals from the terminals
        (usually the first and last, or you might pick infix operators or
        something as representative) they are made of
or  (y) ignore source coordinates during parsing, just letting the
        error reporting machinery look for them.

In a parser of mine, I chose (2a,3x).  It was less work than I feared.