This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/Logtalk/examples/dcgs/shell.lgt
pmoura b25690af56 Logtalk 2.17.1 files.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1071 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
2004-06-06 22:46:45 +00:00

55 lines
1.0 KiB
Plaintext

:- object(shell).
:- info([
version is 1.0,
date is 2004/4/29,
author is 'Paulo Moura',
comment is 'Simple example of command-line shell parsing.']).
:- public(parse/2).
:- mode(parse(@list, -list), zero_or_one).
:- info(parse/2, [
comment is 'Parses a sequence of commands.',
argnames is ['Sequence', 'Commands']]).
parse(Sequence, Commands) :-
phrase(commands(Commands), Sequence).
commands([C| Cs]) -->
command(C), separator, commands(Cs).
commands([C]) -->
command(C).
separator --> ";".
whitespace --> " ", whitespace.
whitespace --> [].
command(Cd) -->
whitespace, "cd", whitespace, cdargs(Args), whitespace,
{atom_concat(cd, Args, Cd)}.
command(Ls) -->
whitespace, "ls", whitespace, lsargs(Args), whitespace,
{atom_concat(ls, Args, Ls)}.
command(pwd) -->
whitespace, "pwd", whitespace.
cdargs(' ~') --> "~".
cdargs(' ..') --> "..".
cdargs(' .') --> ".".
cdargs('') --> [].
lsargs(' -l') --> "-l".
lsargs(' -a') --> "-a".
lsargs('') --> [].
:- end_object.