git @ Cat's Eye Technologies GraNoLa-M / 921424e
Modernize. Suppress warnings. Go for escript. --HG-- rename : bin/granolam => bin/granolam_shell Cat's Eye Technologies 8 years ago
3 changed file(s) with 15 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
+0
-2
bin/granolam less more
0 #!/bin/sh
1 ERL_LIBS=`dirname $0`/../../ erl -noshell -run granolam shell -run init stop
0 #!/bin/sh
1 ERL_LIBS=`dirname $0`/../../ erl -noshell -run granolam shell -run init stop
0 #!/usr/bin/env escript
1 %% -*- erlang -*-
2
03 -module(granolam).
14 -vsn('2002.0314'). % This work is a part of the public domain.
25
3 -export([parse/1, interpret/1, run/1, test/1, shell/0]).
6 -compile([nowarn_unused_vars]).
7
8 -export([parse/1, interpret/1, run/1, test/1, shell/0, main/1]).
49
510 -define(g0(X),X++S)->" "++X++" "++sub(S).
611 -define(g1(X),X|R0])->{Q,R1}=).
3439 case find(N,P) of
3540 {N,nil,L} ->
3641 interpret(pick(L,M),P,?y,M);
37 {N,V,L} when atom(V)->
42 {N,V,L} when is_atom(V)->
3843 {N0,P0,S0,C0,CS0,M0} = do(N,V,P,?y,M),
3944 {N1,V1,L1}=find(N0,P0),
4045 case N0 of
8893 replace(N,T,G)];replace(N,{N,S,L}=P,G)->G;replace(N,{O,S,L},G)->replace(N,L,G);
8994 replace(N,V,G)->V. push(C,S,G)->{N,D,L}=find(C,S),replace(C,S,{N,D,[G|L]}). pop
9095 (C, S)->case find(C,S) of{N,D,[]}->{S,nil};{N,D,[H|T]}->{replace(C,S,{N,D,T}),
91 H}end. format([])->"";format(A) when atom(A)->"^"++atom_to_list(A);format([H|T])
96 H}end. format([])->"";format(A) when is_atom(A)->"^"++atom_to_list(A);format([H|T])
9297 ->format(H)++format(T);format({N,nil,L})->io_lib:format("~w(~s)",[N,format(L)])
9398 ;format({N,V,L})->io_lib:format("~w=~s(~s)",[N,format(V),format(L)]);format(_)
9499
108113 test(_)->unknown_test.
109114 shell()->{?y}=interpret(input()),io:fwrite("~s@~w~n",[format(S),C]),
110115 shell().
116
117 %% Script Interface ------------------------------------------------------
118
119 main([N]) ->
120 {ok, b} = file:read_file(N),run(binary_to_list(b)).