[m-users.] DCGs: equivalent of Prolog's phrase/2 and phrase/3 predicates?

Sean Charles (emacstheviking) objitsu at gmail.com
Sun May 9 01:26:16 AEST 2021


Not according to the documentation I’ve read. It has an imaginary `transform` function for the purpose of explanation. It -is- just a standard call though, the file calculator.m in the samples folder has been my main source of guidance, as well as gratuitous grep-ping of the source for the release I am using, 20.6.1

In the end I made it `set` like this, I don’t see why skipping whitespace should fail anyway, if it isn’t there then the next part of the calling rule can deal with it!

:- pred skip_ws(list(char)::in, list(char)::out) is det.

skip_ws(In, Out) :-
    trace[io(!S), run_time(env("FELT_DBG"))]
    (io.format("skip_ws: ",[],!S),
     io.print_line(In,!S)
    ),
    ( if [C|Cs] = In then
        ( list.member(C, [' ', '\t']) ->
            skip_ws(Cs, Out)
        ;
            Out =In
        )
        else
            Out = In
    ).

This seems to work and I hope I understand why. It’s ugly, I will work on it some more, here is the output for a trial from the console:

{16:25}~/Documents/code/mercury/f2:repl-start ✗ ➭ ./felt -r  
DBUG> checking error mode: plain
DBUG> checking target language: c
DBUG> ** felt_options:
two(error_mode, maybe_string(yes("plain")), two(targets, bool(no), three(help, bool(no), version, bool(no), empty, empty, empty), two(target, maybe_string(yes("c")), empty, empty)), two(syntax_check, bool(no), three(output_file, maybe_string(yes("-")), wrap_code, bool(no), empty, empty, empty), two(repl, bool(yes), empty, empty)))
DBUG> ** Files:
[]
REPL ARGS
[]
FELT ➭ help                
['h', 'e', 'l', 'p', ' ', '\t', '\t', ' ', ' ', ' ', '\t', '\t', '\n']
skip_ws: [' ', '\t', '\t', ' ', ' ', ' ', '\t', '\t', '\n']
skip_ws: ['\t', '\t', ' ', ' ', ' ', '\t', '\t', '\n']
skip_ws: ['\t', ' ', ' ', ' ', '\t', '\t', '\n']
skip_ws: [' ', ' ', ' ', '\t', '\t', '\n']
skip_ws: [' ', ' ', '\t', '\t', '\n']
skip_ws: [' ', '\t', '\t', '\n']
skip_ws: ['\t', '\t', '\n']
skip_ws: ['\t', '\n']
skip_ws: ['\n']
FELT ➭  Got a command:
help
FELT ➭ ^D
FELT ➭ Be excellent to one another.
{16:25}~/Documents/code/mercury/f2:repl-start ✗ ➭ 


Thanks Volker for the input.
Sean.



> On 8 May 2021, at 16:14, Volker Wysk <post at volker-wysk.de> wrote:
> 
> Hi!
> 
> In Prolog, it's the rule to call a DCG rule via the "phrase" predicate. It's
> not clear what it does. In Mercury, the normal way seems to be to directly
> call the DCG rule. Since a DCG rule is just a regular predicate in both
> cases, this ought to work.
> 
> Is there an equivalent for Prolog's "phrase" in Mercury?
> 
> Bye,
> Volker
> _______________________________________________
> users mailing list
> users at lists.mercurylang.org
> https://lists.mercurylang.org/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20210508/609a73f6/attachment-0001.html>


More information about the users mailing list