summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-read.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/lisp-on-tex/lisp-read.sty')
-rw-r--r--Master/texmf-dist/tex/latex/lisp-on-tex/lisp-read.sty205
1 files changed, 125 insertions, 80 deletions
diff --git a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-read.sty b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-read.sty
index a64512ff91c..e93e752521f 100644
--- a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-read.sty
+++ b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-read.sty
@@ -1,83 +1,128 @@
-\def\lispread#1#2{\gdef\@read@buffer{#2\@@eof\@@eof}\@lispread#1}
-\def\@lispread#1{%
-\begingroup
- \readchar
- \if(\expandafter\noexpand\@currentread
- \readchar
- \if\expandafter\noexpand\@currentread)%
- \gdef#1{\@tlabel@nil{}}%
- \else
- \unreadchar
- \@lispread\@temp@i
- \readchar
- \if.\expandafter\noexpand\@currentread
- \let\@save@temp\@temp@i
- \@lispread\@temp@ii
- \let\@temp@i\@save@temp
- \readchar
- \if)\expandafter\noexpand\@currentread
- \expandafter\expandafter\expandafter\@make@cons
- \expandafter\expandafter\expandafter#1%
- \expandafter\@temp@i\@temp@ii
- \else
- \errmessage{LISP on TeX [Parse] :CANNOT FIND )}%
- \fi
- \else\if)\expandafter\noexpand\@currentread
- \expandafter\@make@cons\expandafter#1\@temp@i\@tlabel@nil{}%
- \else
- \unreadchar
- \expandafter\gdef
- \expandafter\@read@buffer
- \expandafter{%
- \expandafter(\@read@buffer}%
- \let\@save@temp\@temp@i
- \@lispread\@temp@ii
- \let\@temp@i\@save@temp
- \expandafter\expandafter\expandafter\@make@cons
- \expandafter\expandafter\expandafter#1%
- \expandafter\@temp@i\@temp@ii
- \fi\fi
- \fi
- \else\ifcat\relax\expandafter\noexpand\@currentread
- \expandafter\gdef\expandafter#1\expandafter{%
- \expandafter\@tlabel@symbol\expandafter{\@currentread}}%
- \else\if'\expandafter\noexpand\@currentread
- \expandafter\@read@string\expandafter#1\expandafter\@lisp@empty\@read@buffer\@@end
- \else\if/\expandafter\noexpand\@currentread
- \readchar
- \xdef#1{\noexpand\@tlabel@bool{\@currentread}}%
- \else\if:\expandafter\noexpand\@currentread
- \expandafter\@read@num\expandafter#1\@read@buffer
- \else\if!\expandafter\noexpand\@currentread
- \expandafter\@read@dimen\expandafter#1\@read@buffer
- \else\if @\expandafter\noexpand\@currentread
- \expandafter\@read@skip\expandafter#1\@read@buffer
- \else\if +\expandafter\noexpand\@currentread % parser module
- \readchar
- \expandafter\@read@module\expandafter#1\@currentread\@@end
- \fi\fi\fi\fi\fi\fi\fi\fi
-\endgroup}
-
-\newcount\@temp@read@cnt
-\def\@read@num#1#2\@@eof\@@eof{%
- \afterassignment\@@read@num\@temp@read@cnt#2\@@end
- \expandafter\gdef
- \expandafter#1%
- \expandafter{\expandafter\@tlabel@int\expandafter{\the\@temp@read@cnt}}}
-\def\@@read@num#1\@@end{\gdef\@read@buffer{#1\@@eof\@@eof}}
+%%
+%% This is file `lisp-read.sty'.
+%%
+%% License: Modified BSD - see LICENSE file
+%%
-\def\@read@dimen#1#2\@@eof\@@eof{\afterassignment\@@read@dimen\dimen@#2\@@end
-\expandafter\gdef\expandafter#1\expandafter{\expandafter\@tlabel@dimen\expandafter{\the\dimen@}}}
-\let\@@read@dimen\@@read@num
+%% End Of Input(EOI)
+\def\@end@lispread{\@@end@lispread}
-\def\@read@skip#1#2\@@eof\@@eof{\afterassignment\@@read@skip\skip@#2\@@end
-\expandafter\gdef\expandafter#1\expandafter{\expandafter\@tlabel@skip\expandafter{\the\skip@}}}
-\let\@@read@skip\@@read@num
+%% Reader Macro
+%% @param #1 callback function (which gets a S-exp and do something)
+%% @param #2 the first letter of the input or EOI
+%% @return #1\@tlabel@xxx{contents}
+\def\@lispread#1#2{\begingroup\@lispread@main#1#2}
-\def\@read@string#1#2'#3\@@end{%
- \expandafter\gdef\expandafter#1%
- \expandafter{\expandafter\@tlabel@string\expandafter{#2}}% expand \@lisp@empty
- \gdef\@read@buffer{#3}}% I don't consider that #3 is single grouped tokens. In LISP on TeX, it never happen.
-
-\def\@read@module#1#2::#3\@@end{% #1 : register, #2 : module name (MUST unique), #3 : parse target
- \csname @mod@read@#2\endcsname#1{#3}}
+%% The first branch
+%% @param #1 callback function
+%% @param #2 the first letter of the input or EOI
+\def\@lispread@main#1#2{% Define \@@next, the continuation.
+ \if\noexpand#2(% [Branch 1] CONS cell or NIL
+ \def\@@next{\@lispread@cell#1}%
+ \else\ifcat\noexpand#2\relax% [Branch 2] A control sequence or a control symbol
+ \ifx#2\@end@lispread % [Branch 2-1] EOI
+ \def\@@next{\endgroup#1\@tlabel@exception{!Found End of Input!}}%
+ \else
+ \def\@@next{\@lispread@symbol#1#2}% [Branch 2-2] Symbol
+ \fi
+ \else\if\noexpand#2'% [Branch 3] String
+ \def\@@next{\@lispread@string#1}%
+ \else\if\noexpand#2/% [Branch 4] Boolean
+ \def\@@next{\@lispread@bool#1}%
+ \else\if\noexpand#2:% [Branch 5] Integer
+ \def\@@next{\@lispread@int#1}%
+ \else\if\noexpand#2!% [Branch 6] Dimension
+ \def\@@next{\@lispread@dimen#1}%
+ \else\if\noexpand#2@% [Branch 7] Skip
+ \def\@@next{\@lispread@skip#1}%
+ \else\if\noexpand#2+% [Branch 8] call a Reader Module
+ \def\@@next{\@lispread@module#1}%
+ \else % Otherwise -- parse error
+ \errmessage{LISP on teX [read]: no such type start with \noexpand#2}%
+ \fi\fi\fi\fi\fi\fi\fi\fi
+ \@@next}
+%% Symbol
+\def\@lispread@symbol#1#2{%
+ \endgroup#1\@tlabel@symbol{#2}}
+%% String
+\def\@lispread@string#1#2'{%
+ \endgroup#1\@tlabel@string{#2}}
+%% Boolean
+\def\@lispread@bool#1#2{%
+ \endgroup#1\@tlabel@bool{#2}}
+%% Reader Module
+\def\@lispread@module#1#2{%
+ \@lispread@module@main\@register@lispread@module#2\@@end
+ \endgroup
+ \expandafter#1\@register@lispread@module}
+\def\@lispread@module@main#1#2::#3\@@end{\csname @mod@read@#2\endcsname#1{#3}}
+%% Integer
+\newcount\@cnt@lispread@int
+\def\@lispread@int#1{%
+ \gdef\@lispread@int@callback{\@lispread@int@main#1}%
+ \afterassignment\@lispread@int@callback
+ \global\@cnt@lispread@int}
+\def\@lispread@int@main#1{%
+ \endgroup\expandafter#1\expandafter\@tlabel@int\expandafter{\the\@cnt@lispread@int}}
+%% Skip
+\newskip\@cnt@lispread@skip
+\def\@lispread@skip#1{%
+ \gdef\@lispread@skip@callback{\@lispread@skip@main#1}%
+ \afterassignment\@lispread@skip@callback
+ \global\@cnt@lispread@skip}
+\def\@lispread@skip@main#1{%
+ \endgroup\expandafter#1\expandafter\@tlabel@skip\expandafter{\the\@cnt@lispread@skip}}
+%% Dimen
+\newdimen\@cnt@lispread@dimen
+\def\@lispread@dimen#1{%
+ \gdef\@lispread@dimen@callback{\@lispread@dimen@main#1}%
+ \afterassignment\@lispread@dimen@callback
+ \global\@cnt@lispread@dimen}
+\def\@lispread@dimen@main#1{%
+ \endgroup\expandafter#1\expandafter\@tlabel@dimen\expandafter{\the\@cnt@lispread@dimen}}
+%% CONS cell or NIL
+\def\@lispread@cell#1#2{%
+ \if\noexpand#2)% [Branch 1] NIL
+ \def\@@next{\endgroup#1\@tlabel@nil{}}%
+ \else % Otherwise CONS cell
+ \def\@@next{\@lispread@cell@car#1#2}%
+ \fi\@@next}
+%% first part of CONS cell : read CAR
+\def\@lispread@cell@car#1{%
+ \def\@lispread@car@reg##1##2{%
+ \def\@reg@lispread@car{##1{##2}}%
+ \@lispread@cell@dot#1}%
+ \@lispread\@lispread@car@reg}
+\def\@lispread@cell@dot#1#2{%
+ \if\noexpand#2.%
+ \def\@@next{%
+ \def\@lispread@cell@fincheck####1####2{%
+ \def\@reg@lispread@cdr{####1{####2}}%
+ \@lispread@fin#1}%
+ \@lispread\@lispread@cell@fincheck}% kokonaosu
+ \else
+ \def\@@next{\@lispread@cell@cdr#1(#2}%
+ \fi\@@next}
+\def\@lispread@cell@cdr#1{%
+ \def\@lispread@cdr@reg##1##2{%
+ \expandafter\@read@malloc\expandafter\@reg@tmp\@reg@lispread@car##1{##2}%
+ \expandafter\endgroup\expandafter#1\@reg@tmp}%
+ \@lispread\@lispread@cdr@reg}
+\def\@lispread@fin#1#2{%
+ \if\noexpand#2)%
+ \def\@@next{%
+ \expandafter\expandafter\expandafter\@read@malloc
+ \expandafter\expandafter\expandafter\@reg@tmp
+ \expandafter\@reg@lispread@car\@reg@lispread@cdr
+ \expandafter\endgroup\expandafter#1\@reg@tmp}%
+ \else
+ \def\@@next{\errmessage{LISP on teX [read]: missing )}}%
+ \fi\@@next}
+\def\@read@malloc#1#2#3#4#5{%
+ \expandafter\gdef\csname car\the\@malloc\endcsname{#2{#3}}%
+ \expandafter\gdef\csname cdr\the\@malloc\endcsname{#4{#5}}%
+ \expandafter\@@read@malloc\expandafter#1\csname car\the\@malloc\endcsname\csname cdr\the\@malloc\endcsname}
+\def\@@read@malloc#1#2{\expandafter\@@@read@malloc\expandafter#1\expandafter#2}
+\def\@@@read@malloc#1#2#3{%
+ \global\advance\@malloc1
+ \def#1{\@tlabel@cons{#2#3}}} \ No newline at end of file