prolog_format.pl -- Analyse format specifications
This library parses the format specification used by format/1, format/2 and format/3. The parsed specification can be used to validate the consistency of the format string and the provided arguments. For example:
?- format_types('~d bottles of beer', Types). Types = [integer].
- format_spec(+Format, -Spec:list) is semidet
- Parse a format string. Each element of Spec is one of the following:
- text(Text)
- Text sent to the output as is
- escape(Num, Colon, Action)
- A format escape. Num represents the optional numeric portion of an esape. Colon represents the optional colon in an escape. Action is an atom representing the action to be take by this escape.
- format_spec(-Spec)//
- DCG for parsing format strings. It doesn't yet generate format strings from a spec. See format_spec/2 for details.
- format_types(+Format:text, -Types:list) is det
- True when Format requires an argument list with terms of the type specified by Types. The length of this list is the number of arguments required. Each value of Types is a type as described by has_type/2.
- spec_types(+FormatSpec, -Types:list(type)) is det[private]
- True if FormatSpec requires format/2 to have arguments of Types.
Each value of Types is a type as described by has_type/2. This
notion of types is compatible with
library(mavis)
. - text_codes(Text:text, Codes:codes)[private]
- is_action(+Action:integer) is semidet[private]
- is_action(-Action:integer) is multi[private]
- True if Action is a valid format/2 action character. Iterates all acceptable action characters, if Action is unbound.
- action_types(?Action:integer, ?Types:list(type))[private]
- True if Action consumes arguments matching Types. An action (like
~
), which consumes no arguments, hasTypes=[]
. For example,?- action_types(0'~, Types). Types = []. ?- action_types(0'a, Types). Types = [atom].