blob: 757539c188b3a930637e88f742907a5bf2a479f3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
%%
%% This is file `xpeek.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% xpeek.dtx (with options: `package')
%% ----------------------------------------------------------------
%%
%% xpeek: Define commands that peek ahead in the input stream
%%
%% Copyright © 2012 by Joel C. Salomon.
%%
%% This work consists of the file xpeek.dtx,
%% and the derived files xpeek.ins,
%% xpeek.pdf, &
%% xpeek.sty.
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
%% license or (at your option) any later version. The latest version
%% of this license is at ‹http://www.latex-project.org/lppl.txt›.
%%
%% This work is “maintained” (per LPPL maintenance status) by
%% Joel C. Salomon ‹joelcsalomon@gmail.com›.
%%
%% ----------------------------------------------------------------
\RequirePackage{expl3, xparse}
\ProvidesExplPackage
{xpeek} {2012/08/15} {0.2}
{Define commands that peek ahead in the input stream}
\tl_new:N \g_xpeek_matchlist_tl
\tl_new:N \g_xpeek_ignorelist_tl
\tl_new:N \l__xpeek_code_tl
\cs_new_protected:Npn \xpeek_after:nw #1
{
\tl_set:Nn \l__xpeek_code_tl {#1}
\peek_after:Nw \l__xpeek_code_tl
}
\tl_new:N \l__xpeek_collected_tokens_tl
\cs_new_protected:Npn \xpeek_collect_do:nn #1#2
{
\tl_clear:N \l__xpeek_collected_tokens_tl
\__xpeek_collect_do:nnn {#1} {#2} {}
}
\cs_new_protected:Npn \__xpeek_collect_do:nnn #1#2#3
{
\xpeek_after:nw
{
\xpeek_if_in:NNTF #1 \l_peek_token
{
\tl_put_right:Nn \l__xpeek_collected_tokens_tl {#3}
\__xpeek_collect_do:nnn {#1} {#2}
}
{
#2 { \l__xpeek_collected_tokens_tl #3 }
}
}
}
\bool_new:N \l__xpeek_bool
\prg_new_protected_conditional:Npnn \xpeek_if_in:NN #1#2 { TF }
{
\bool_set_false:N \l__xpeek_bool
\tl_map_inline:Nn #1
{
\token_if_eq_charcode:NNT #2 ##1
{
\bool_set_true:N \l__xpeek_bool
\tl_map_break:
}
}
\bool_if:NTF \l__xpeek_bool
{ \prg_return_true: } { \prg_return_false: }
}
%%
%%
%% End of file `xpeek.sty'.
|