blob: 5c248ad9f56fc909acdf7b88ad0e66dfb1777b18 (
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
% Copyright 2009 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.
\ProvidesFileRCS{pgfmoduleparser.code.tex}
%
% This file defines commands for defining a letter-by-letter parser
% based on a dfa.
%
% Parse the following text
%
% #1 = parser
%
% Description:
%
% This command starts the parser #1 in the initial state "initial". It
% will parse the following text, stopping when the state "final" has
% been reached.
\def\pgfparserparse#1{%
\def\pgf@parser{#1}%
\def\pgf@parser@state{initial}%
\pgf@parser@parse%
}
\def\pgf@parser@parse{%
\futurelet\pgf@parser@symbol\pgf@parser@cont%
}
\def\pgf@parser@cont{%
% Ok, defined?
\expandafter\let\expandafter\pgf@parser@action%
\csname pgf@parser@a@\pgf@parser @\pgf@parser@state @\meaning\pgf@parser@symbol\endcsname%
\ifx\pgf@parser@action\relax%
\expandafter\let\expandafter\pgf@parser@action%
\csname pgf@parser@a@\pgf@parser @all@\meaning\pgf@parser@symbol\endcsname%
\ifx\pgf@parser@action\relax%
\pgferror{Unexpected character
'\meaning\pgf@parser@symbol' in parser '\pgf@parser' in state
'\pgf@parser@state'}%
\fi%
\fi%
\pgf@parser@action%
\ifx\pgf@parser@symbol\pgfutil@sptoken%
\expandafter\pgf@parser@rid@space%
\else%
\expandafter\pgf@parser@rid@other%
\fi%
}
\def\pgf@parser@ridded{%
\ifx\pgf@parser@state\pgf@parser@final@text%
% done
\else%
\expandafter\pgf@parser@parse%
\fi%
}
\def\pgf@parser@final@text{final}
{%
\def\:{\pgf@parser@rid@space} \expandafter\gdef\: {\futurelet\pgf@parser@ignore\pgf@parser@ridded}
\gdef\pgf@parser@rid@other{\afterassignment\pgf@parser@ridded\let\pgf@parser@ignore=}
}
% Switches the state
%
% #1 = new state
%
% Description:
%
% This command can be used inside a state action to switch to a
% different state.
\def\pgfparserswitch#1{\def\pgf@parser@state{#1}}
% Defines an action to be taken in a state for some symbol
%
% #1 = parser
% #2 = state
% #3 = symbol text (result of saying \meaning on the symbol)
% #4 = action
%
% Description:
%
% When the parser encounters #3 while being in state #2, then code #4
% is executed.
%
% When #2 is set to the special text "all", then the symbol is handled
% in all states by #4, except when a state defines something special
% for this symbol
\def\pgfparserdef#1#2#3#4{%
\expandafter\def\csname pgf@parser@a@#1@#2@#3\endcsname{#4}
}
\endinput
|