Last active
March 23, 2022 14:49
-
-
Save GeoffChurch/d1aadcb76ced9c62cd9c31105f88f32c to your computer and use it in GitHub Desktop.
Reified DCG utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- use_module(library(reif)). | |
phrase_t(P, I, O, T) :- phrase(call(P, T), I, O). | |
if_(If, Then, Else, I, O) :- | |
if_(phrase_t(If, I, M), | |
phrase(Then, M, O), | |
phrase(Else, M, O)). | |
% Example: | |
eos([], []). | |
maximal_munch(_) --> eos. | |
maximal_munch(P) --> if_(P, maximal_munch(P), []). | |
oneX(X, false), [Y] --> [Y], {dif(X, Y)}. | |
oneX(X, true) --> [X]. | |
:- phrase(maximal_munch(oneX(a)), _, _). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment