Last active
May 29, 2025 18:49
-
-
Save eignnx/51c526b2aa69a68c10366edb63a763d2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| main :- | |
| catch( | |
| ( phrase_from_stream(unlimited(parser), user_input) -> true | |
| ; format('% parse failure!~n', []) ), | |
| _, | |
| format('% caught exception!~n', []) | |
| ), | |
| format('% exiting...~n', []). | |
| unlimited(Goal) --> | |
| call(Goal), | |
| unlimited(Goal). | |
| parser --> | |
| { format('% trying to parse :NOP...~n', []) }, | |
| `:NOP\n`, | |
| { format('% parsed :NOP!~n', []) }. | |
| parser --> | |
| { format('% trying to parse :EXIT...~n', []) }, | |
| `:EXIT\n`, | |
| { format('% parsed :EXIT!~n', []) }, | |
| { format('% throwing...~n', []) }, | |
| { throw(error(breakoutplease, _)) }. | |
| /* | |
| ?- main. | |
| % trying to parse :NOP... | |
| |: INVALID | |
| % trying to parse :EXIT... | |
| % parse failure! | |
| % exiting... | |
| true. | |
| ?- main. | |
| % trying to parse :NOP... | |
| |: :NOP | |
| % parsed :NOP! | |
| % trying to parse :NOP... | |
| :EXIT | |
| % trying to parse :EXIT... | |
| % parsed :EXIT! | |
| % throwing... | |
| % caught exception! | |
| % exiting... | |
| true. | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment