Skip to content
This repository was archived by the owner on Feb 9, 2020. It is now read-only.
This repository was archived by the owner on Feb 9, 2020. It is now read-only.

DCG-compatible interface #6

@mndrix

Description

@mndrix

Regular expressions can be useful as building blocks for DCGs. For example,

foo -->
    game_console(Console),
    regex_dcg('games?').

I considered making a regex/5 predicate whose argument order is consistent with DCGs, but that would require one to always use regex//3 even if options and captures aren't needed. As in the example above, one often needs only a pattern.

I decided that a separate DCG version is the most appropriate. This is probably the most fundamental regular expression predicate. regex/4 might be built on top of it with something like:

regex(Pattern, Opts, Text, Captures) :-
    regex_dcg(Pattern, Opts, Captures, Text, _).

The DCG interface should only match a regular expression anchored at the first character of Text. That's consistent with the way that DCGs consume only from the head. If a DCG wants the regex to match anywhere, it can add its own logic for discarding characters that don't match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions