Logtalk reference manual
Built-in method: phrase/3

phrase/3

Description

phrase(NonTerminal, Input, Rest)
phrase(::NonTerminal, Input, Rest)
phrase(Object::NonTerminal, Input, Rest)

True if the list Input of tokens can be parsed using the specified non-terminal NonTerminal. The list Rest is what remains of the list Input after parsing succeeded. This method also accepts grammar rule bodies in the first argument. This built-in method is declared private and thus cannot be used as a message to an object. When using a back-end Prolog compiler supporting a module system, calls in the format phrase(Module:NonTerminal, Input, Rest) may also be used.

This method is opaque to cuts in the first argument.

Template and modes

phrase(+callable, ?list, ?list)

Errors

NonTerminal is a variable:
instantiation_error
NonTerminal is neither a variable nor a callable term:
type_error(callable, NonTerminal)
Input is neither a partial list nor a list:
type_error(list, Input)
Rest is neither a partial list nor a list:
type_error(list, Rest)

Examples

To parse a list of tokens using a local non-terminal:
phrase(NonTerminal, Input, Rest)
To parse a list of tokens using a non-terminal within the scope of self:
phrase(::NonTerminal, Input, Rest)
To parse a list of tokens using a public non-terminal of an explicit object:
phrase(Object::NonTerminal, Input, Rest)