Modernize. Suppress warnings. Go for escript.
--HG--
rename : bin/granolam => bin/granolam_shell
Cat's Eye Technologies
8 years ago
0 | #!/usr/bin/env escript | |
1 | %% -*- erlang -*- | |
2 | ||
0 | 3 | -module(granolam). |
1 | 4 | -vsn('2002.0314'). % This work is a part of the public domain. |
2 | 5 | |
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]). | |
4 | 9 | |
5 | 10 | -define(g0(X),X++S)->" "++X++" "++sub(S). |
6 | 11 | -define(g1(X),X|R0])->{Q,R1}=). |
34 | 39 | case find(N,P) of |
35 | 40 | {N,nil,L} -> |
36 | 41 | interpret(pick(L,M),P,?y,M); |
37 | {N,V,L} when atom(V)-> | |
42 | {N,V,L} when is_atom(V)-> | |
38 | 43 | {N0,P0,S0,C0,CS0,M0} = do(N,V,P,?y,M), |
39 | 44 | {N1,V1,L1}=find(N0,P0), |
40 | 45 | case N0 of |
88 | 93 | replace(N,T,G)];replace(N,{N,S,L}=P,G)->G;replace(N,{O,S,L},G)->replace(N,L,G); |
89 | 94 | replace(N,V,G)->V. push(C,S,G)->{N,D,L}=find(C,S),replace(C,S,{N,D,[G|L]}). pop |
90 | 95 | (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]) | |
92 | 97 | ->format(H)++format(T);format({N,nil,L})->io_lib:format("~w(~s)",[N,format(L)]) |
93 | 98 | ;format({N,V,L})->io_lib:format("~w=~s(~s)",[N,format(V),format(L)]);format(_) |
94 | 99 | |
108 | 113 | test(_)->unknown_test. |
109 | 114 | shell()->{?y}=interpret(input()),io:fwrite("~s@~w~n",[format(S),C]), |
110 | 115 | shell(). |
116 | ||
117 | %% Script Interface ------------------------------------------------------ | |
118 | ||
119 | main([N]) -> | |
120 | {ok, b} = file:read_file(N),run(binary_to_list(b)). |