Re: parsing format/{1,2,3} format strings
Jan Wielemaker <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 12/25/2013 03:37 AM, Michael Hendricks wrote:
> Does anyone have code for parsing format strings used by format/{1,2,3}
> predicates? I'm imagining something roughly like this:
>
> ?- parse_format("Total: ~2:d~n", X).
> X = [string("Total: "), tilde(2, :, d), tilde(default, '', n)].
>
> It'd be great if the predicate worked in both directions (for generating
> format strings too), but I really only need the parser at the moment.
That doesn't exist. These predicates are foreign built-ins. They are
defined in src/os/pl-fmt.c. You cannot blindly use other system's
implementation because the details vary between systems, e.g.,
SWI-Prolog provides the : extension for locale handling. The rules are
pretty simple tough, so writing this grammer should be a breeze.
You want to do type checking for the arguments?
Cheers --- Jan