What's the idiomatic way of developing DCGs?

@EricGT I misread your reply. You are correct that I didn’t show a fully reproducible example. Here is the input file I used:

% cat d02-example.input 
1-3 a: abcde
1-3 b: cdefg
2-9 c: ccccccccc

The program in its entirety consists of these three predicates, copy-pasted from above, plus the dcg/basics import:

:- use_module(library(dcg/basics)).

parse_rules(File, Rules) :-
    phrase_from_file(all_rules(Rules), File).

all_rules([R|Rules]) -->
    password_rule(R),
    !,
    all_rules(Rules).
all_rules([]) --> [].

password_rule(policy_password(Lower, Upper, Char, Password)) -->
    integer(Lower), "-", integer(Upper), " ", [Char], ": ",
    nonblanks(Password),
    "\n".

I do not use a custom startup file or configuration, it is vanilla SWI-Prolog.

1 Like