-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexing-python-indentation-using-spirit-lex.html
303 lines (284 loc) · 26.6 KB
/
lexing-python-indentation-using-spirit-lex.html
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<!DOCTYPE html>
<!--[if IE 8]> <html class="no-js lt-ie9" lang="zh-cn"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="zh-cn"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>道可叨 | Lexing Python Indentation using Spirit.Lex </title>
<meta name="viewport" content="width=device-width">
<meta name="author" content="Qiang">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<link href="http://localhost:8000/feeds/atom.xml" type="application/atom+xml" rel="alternate" title="道可叨 Atom Feed" />
<link rel="stylesheet" href="https://zhuoqiang.github.io/theme/css/app.css">
<script src="https://zhuoqiang.github.io/theme/js/vendor/custom.modernizr.js"></script>
</head>
<body>
<header>
<hgroup>
<a href="https://zhuoqiang.github.io">
<h1 i18n>道可叨</h1>
<h2>Free Will</h2>
</a>
</hgroup>
</header>
<section>
<article>
<header>
<h1><a href="https://zhuoqiang.github.io/lexing-python-indentation-using-spirit-lex.html">Lexing Python Indentation using Spirit.Lex</a></h1>
</header> <div>
<section>
<p>Python is well known for its whitespace-sensitivity grammar. The indentation level provides block scoping in python language. While it is possible to parse python using just straight Spirit.Qi, however, it looks messy to mixing the low level indentation handling in the parsing level. Fortunately Spirit.Lex could be a help here to transform the indentation to a bunch of proper <tt class="docutils literal">BEGIN</tt> or <tt class="docutils literal">END</tt> tokens, which will simplify the parsing logic later.</p>
<p>Here's how to deal with indentation: for each line of the input, current line's indentation level will be compared with previews one stored in a stack:</p>
<ul class="simple">
<li>If the indentation is increasing it is pushed into the stack and a <tt class="docutils literal">BEGIN</tt> token is generated</li>
<li>If indentation is not changed, just continue and nothing happens</li>
<li>if it is decreasing comparing with the top indentation number on the stack, the top number then will be popped off from the stack and a corresponding <tt class="docutils literal">END</tt> token is generated until the same indentation number appears on top of the stack. If the same indentation number cannot be found on the stack, an indentation error occurs.</li>
</ul>
<p>At the end of the input, an <tt class="docutils literal">END</tt> token is generated for each indentation level remains on the stack (until only 0 remains).</p>
<p>For simplicity let's handle just spaces for now and ignore tabs</p>
<p>The first shot is to match zero or more spaces at the beginning of the line and then calculate the total length of the spaces in a semantic action</p>
<div class="highlight"><pre><span></span><span class="n">token_def</span><span class="o"><></span> <span class="n">indent_</span><span class="p">(</span><span class="s">"^[ ]*"</span><span class="p">);</span>
<span class="n">token_def</span><span class="o"><></span> <span class="n">identifier_</span><span class="p">(</span><span class="s">"[a-zA-Z_]</span><span class="se">\\</span><span class="s">w*"</span><span class="p">);</span>
<span class="k">this</span><span class="o">-></span><span class="n">self</span>
<span class="o">=</span> <span class="n">indent_</span><span class="p">[</span><span class="n">_val</span><span class="o">=</span><span class="n">_end</span><span class="o">-</span><span class="n">_begin</span><span class="p">]</span>
<span class="o">|</span> <span class="n">identifier_</span>
<span class="p">;</span>
</pre></div>
<p>However, this won't work for lines without spaces at the beginning.</p>
<div class="highlight"><pre><span></span><span class="n">a_variable_without_any_indent</span>
</pre></div>
<p>The above will only match <tt class="docutils literal">identifier_</tt> but not zero length <tt class="docutils literal">indent_</tt>. It seems there is no way to match the pseudo <tt class="docutils literal">beginning of line</tt> anchors with Spirit.Lex</p>
<p>The workaround is to match newline manually and switch to another lexer state dedicating for indentation.</p>
<div class="highlight"><pre><span></span><span class="k">template</span> <span class="o"><</span><span class="k">typename</span> <span class="n">Lexer</span><span class="o">></span>
<span class="k">class</span> <span class="nc">Tokens</span> <span class="o">:</span> <span class="k">public</span> <span class="n">lex</span><span class="o">::</span><span class="n">lexer</span><span class="o"><</span><span class="n">Lexer</span><span class="o">></span> <span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
<span class="n">Tokens</span><span class="p">()</span>
<span class="o">:</span> <span class="n">indent_</span><span class="p">(</span><span class="s">"[ ]*"</span><span class="p">)</span>
<span class="p">,</span> <span class="n">newline_</span><span class="p">(</span><span class="s">"[</span><span class="se">\\</span><span class="s">n</span><span class="se">\\</span><span class="s">r</span><span class="se">\\</span><span class="s">f]+"</span><span class="p">)</span>
<span class="p">,</span> <span class="n">whitespace_</span><span class="p">(</span><span class="s">"[ </span><span class="se">\\</span><span class="s">t]+"</span><span class="p">)</span>
<span class="p">,</span> <span class="n">if_</span><span class="p">(</span><span class="s">"if"</span><span class="p">)</span>
<span class="p">,</span> <span class="n">identifier_</span><span class="p">(</span><span class="s">"[a-zA-Z_]</span><span class="se">\\</span><span class="s">w*"</span><span class="p">)</span>
<span class="p">,</span> <span class="n">equal_</span><span class="p">(</span><span class="s">"=="</span><span class="p">)</span>
<span class="p">,</span> <span class="n">colon_</span><span class="p">(</span><span class="sc">':'</span><span class="p">)</span>
<span class="p">,</span> <span class="n">assign_</span><span class="p">(</span><span class="sc">'='</span><span class="p">)</span>
<span class="p">,</span> <span class="n">integer_</span><span class="p">(</span><span class="s">"</span><span class="se">\\</span><span class="s">d+"</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">this</span><span class="o">-></span><span class="n">self</span>
<span class="o">=</span> <span class="n">indent_</span><span class="p">[</span><span class="n">HandleIndent</span><span class="p">(</span><span class="n">scopeLevels_</span><span class="p">)]</span>
<span class="p">;</span>
<span class="k">this</span><span class="o">-></span><span class="n">self</span><span class="p">(</span><span class="s">"NORMAL"</span><span class="p">)</span>
<span class="o">=</span> <span class="n">newline_</span><span class="p">[</span><span class="n">HandleNewline</span><span class="p">(</span><span class="n">scopeLevels_</span><span class="p">)]</span>
<span class="o">|</span> <span class="n">whitespace_</span><span class="p">[</span><span class="n">lex</span><span class="o">::</span><span class="n">_pass</span><span class="o">=</span><span class="n">lex</span><span class="o">::</span><span class="n">pass_flags</span><span class="o">::</span><span class="n">pass_ignore</span><span class="p">]</span>
<span class="o">|</span> <span class="n">if_</span>
<span class="o">|</span> <span class="n">equal_</span>
<span class="o">|</span> <span class="n">colon_</span> <span class="o">|</span> <span class="n">assign_</span>
<span class="o">|</span> <span class="n">integer_</span>
<span class="o">|</span> <span class="n">identifier_</span>
<span class="p">;</span>
<span class="p">}</span>
<span class="k">private</span><span class="o">:</span>
<span class="n">lex</span><span class="o">::</span><span class="n">token_def</span><span class="o"><></span> <span class="n">indent_</span><span class="p">;</span>
<span class="n">lex</span><span class="o">::</span><span class="n">token_def</span><span class="o"><></span> <span class="n">newline_</span><span class="p">,</span> <span class="n">whitespace_</span><span class="p">;</span>
<span class="c1">// keywords</span>
<span class="n">lex</span><span class="o">::</span><span class="n">token_def</span><span class="o"><></span> <span class="n">if_</span><span class="p">;</span>
<span class="n">lex</span><span class="o">::</span><span class="n">token_def</span><span class="o"><></span> <span class="n">identifier_</span><span class="p">;</span>
<span class="c1">// operators</span>
<span class="n">lex</span><span class="o">::</span><span class="n">token_def</span><span class="o"><></span> <span class="n">equal_</span><span class="p">;</span>
<span class="c1">// delimiters</span>
<span class="n">lex</span><span class="o">::</span><span class="n">token_def</span><span class="o"><></span> <span class="n">colon_</span><span class="p">,</span> <span class="n">assign_</span><span class="p">;</span>
<span class="c1">// literal</span>
<span class="n">lex</span><span class="o">::</span><span class="n">token_def</span><span class="o"><></span> <span class="n">integer_</span><span class="p">;</span>
<span class="n">std</span><span class="o">::</span><span class="n">stack</span><span class="o"><</span><span class="kt">int</span><span class="o">></span> <span class="n">scopeLevels_</span><span class="p">;</span>
<span class="p">};</span>
</pre></div>
<p>Here we use the default <tt class="docutils literal">INITIAL</tt> lexer state for indentation handling and <tt class="docutils literal">NORMAL</tt> state for other token matching. Actually the indentation handling must be the <tt class="docutils literal">INITIAL</tt> state in order to handle the first line since there is no newline before it.</p>
<p>We use a stack <tt class="docutils literal">scopeLevels_</tt> to help store indentation levels:</p>
<div class="highlight"><pre><span></span><span class="k">enum</span> <span class="n">TokenIds</span> <span class="p">{</span>
<span class="n">kTokenBegin</span> <span class="o">=</span> <span class="mi">1000</span><span class="p">,</span>
<span class="n">kTokenEnd</span> <span class="o">=</span> <span class="mi">1001</span><span class="p">,</span>
<span class="p">};</span>
<span class="k">class</span> <span class="nc">HandleIndent</span> <span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
<span class="n">HandleIndent</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">stack</span><span class="o"><</span><span class="kt">int</span><span class="o">>&</span> <span class="n">scopeLevels</span><span class="p">)</span>
<span class="o">:</span> <span class="n">scopeLevels_</span><span class="p">(</span><span class="n">scopeLevels</span><span class="p">)</span>
<span class="p">{}</span>
<span class="k">template</span> <span class="o"><</span><span class="k">typename</span> <span class="n">Iterator</span><span class="p">,</span> <span class="k">typename</span> <span class="n">IdType</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Context</span><span class="o">></span>
<span class="kt">void</span> <span class="k">operator</span><span class="p">()</span> <span class="p">(</span>
<span class="n">Iterator</span><span class="o">&</span> <span class="n">start</span><span class="p">,</span>
<span class="n">Iterator</span><span class="o">&</span> <span class="n">end</span><span class="p">,</span>
<span class="n">BOOST_SCOPED_ENUM</span><span class="p">(</span><span class="n">lex</span><span class="o">::</span><span class="n">pass_flags</span><span class="p">)</span><span class="o">&</span> <span class="n">passFlag</span><span class="p">,</span>
<span class="n">IdType</span><span class="o">&</span> <span class="n">id</span><span class="p">,</span> <span class="n">Context</span><span class="o">&</span> <span class="n">context</span><span class="p">)</span> <span class="p">{</span>
<span class="kt">int</span> <span class="k">const</span> <span class="n">level</span> <span class="o">=</span> <span class="n">std</span><span class="o">::</span><span class="n">distance</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">scopeLevels_</span><span class="p">.</span><span class="n">empty</span><span class="p">())</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">level</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="k">throw</span> <span class="n">std</span><span class="o">::</span><span class="n">runtime_error</span><span class="p">(</span><span class="s">"Indent must start from 0!"</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">scopeLevels_</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">level</span><span class="p">);</span>
<span class="p">}</span>
<span class="c1">// If the level is same, just ignore it and switch to normal state</span>
<span class="k">if</span> <span class="p">(</span><span class="n">level</span> <span class="o">==</span> <span class="n">scopeLevels_</span><span class="p">.</span><span class="n">top</span><span class="p">())</span> <span class="p">{</span>
<span class="n">passFlag</span> <span class="o">=</span> <span class="n">lex</span><span class="o">::</span><span class="n">pass_flags</span><span class="o">::</span><span class="n">pass_ignore</span><span class="p">;</span>
<span class="n">context</span><span class="p">.</span><span class="n">set_state_name</span><span class="p">(</span><span class="s">"NORMAL"</span><span class="p">);</span>
<span class="p">}</span>
<span class="c1">// If the level is larger, emit BEGIN and push the new level on stack</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">level</span> <span class="o">></span> <span class="n">scopeLevels_</span><span class="p">.</span><span class="n">top</span><span class="p">())</span> <span class="p">{</span>
<span class="n">scopeLevels_</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">level</span><span class="p">);</span>
<span class="n">id</span> <span class="o">=</span> <span class="n">kTokenBegin</span><span class="p">;</span>
<span class="n">context</span><span class="p">.</span><span class="n">set_state_name</span><span class="p">(</span><span class="s">"NORMAL"</span><span class="p">);</span>
<span class="p">}</span>
<span class="c1">// If the level is smaller, emit END and pop the top level from stack</span>
<span class="k">else</span> <span class="p">{</span> <span class="c1">//Dedent, end scope</span>
<span class="n">scopeLevels_</span><span class="p">.</span><span class="n">pop</span><span class="p">();</span>
<span class="c1">// Level must be one of the numbers occurring on the stack</span>
<span class="k">if</span> <span class="p">(</span><span class="n">scopeLevels_</span><span class="p">.</span><span class="n">empty</span><span class="p">()</span> <span class="o">||</span> <span class="n">level</span> <span class="o">></span> <span class="n">scopeLevels_</span><span class="p">.</span><span class="n">top</span><span class="p">())</span> <span class="p">{</span>
<span class="k">throw</span> <span class="n">std</span><span class="o">::</span><span class="n">runtime_error</span><span class="p">(</span><span class="s">"Dedenting failed, could not find indent matching previews "</span><span class="p">);</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
<span class="c1">// make it a zero match, we can generate multiple END token by this trick</span>
<span class="n">end</span> <span class="o">=</span> <span class="n">start</span><span class="p">;</span>
<span class="n">id</span> <span class="o">=</span> <span class="n">kTokenEnd</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">private</span><span class="o">:</span>
<span class="n">std</span><span class="o">::</span><span class="n">stack</span><span class="o"><</span><span class="kt">int</span><span class="o">>&</span> <span class="n">scopeLevels_</span><span class="p">;</span>
<span class="p">};</span>
<span class="k">class</span> <span class="nc">HandleNewline</span> <span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
<span class="n">HandleNewline</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">stack</span><span class="o"><</span><span class="kt">int</span><span class="o">>&</span> <span class="n">scopeLevels</span><span class="p">)</span>
<span class="o">:</span> <span class="n">scopeLevels_</span><span class="p">(</span><span class="n">scopeLevels</span><span class="p">)</span>
<span class="p">{}</span>
<span class="k">template</span> <span class="o"><</span><span class="k">typename</span> <span class="n">Iterator</span><span class="p">,</span> <span class="k">typename</span> <span class="n">IdType</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Context</span><span class="o">></span>
<span class="kt">void</span> <span class="k">operator</span><span class="p">()</span> <span class="p">(</span>
<span class="n">Iterator</span><span class="o">&</span> <span class="n">start</span><span class="p">,</span>
<span class="n">Iterator</span><span class="o">&</span> <span class="n">end</span><span class="p">,</span>
<span class="n">BOOST_SCOPED_ENUM</span><span class="p">(</span><span class="n">lex</span><span class="o">::</span><span class="n">pass_flags</span><span class="p">)</span><span class="o">&</span> <span class="n">passFlag</span><span class="p">,</span>
<span class="n">IdType</span><span class="o">&</span> <span class="n">id</span><span class="p">,</span> <span class="n">Context</span><span class="o">&</span> <span class="n">context</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">context</span><span class="p">.</span><span class="n">get_eoi</span><span class="p">()</span> <span class="o">==</span> <span class="n">end</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// If the "end of input" is reached</span>
<span class="c1">// we pop up all the non-zero levels.</span>
<span class="c1">// for each pop up we generate a corresponding END token</span>
<span class="c1">// here we apply the zero-match trick again to emit multiple END token</span>
<span class="k">if</span> <span class="p">(</span><span class="n">scopeLevels_</span><span class="p">.</span><span class="n">top</span><span class="p">()</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="n">scopeLevels_</span><span class="p">.</span><span class="n">pop</span><span class="p">();</span>
<span class="n">end</span> <span class="o">=</span> <span class="n">start</span><span class="p">;</span>
<span class="n">id</span> <span class="o">=</span> <span class="n">kTokenEnd</span><span class="p">;</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">passFlag</span> <span class="o">=</span> <span class="n">lex</span><span class="o">::</span><span class="n">pass_flags</span><span class="o">::</span><span class="n">pass_ignore</span><span class="p">;</span>
<span class="n">context</span><span class="p">.</span><span class="n">set_state_name</span><span class="p">(</span><span class="s">"INITIAL"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">private</span><span class="o">:</span>
<span class="n">std</span><span class="o">::</span><span class="n">stack</span><span class="o"><</span><span class="kt">int</span><span class="o">>&</span> <span class="n">scopeLevels_</span><span class="p">;</span>
<span class="p">};</span>
</pre></div>
<p>Notice how we apply the <cite>zero-length matching</cite> trick to generate multiple tokens.</p>
<p>Now, let's try lex some python code:</p>
<div class="highlight"><pre><span></span><span class="k">if</span> <span class="n">a</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">if</span> <span class="n">b</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">c</span>
<span class="k">if</span> <span class="n">d</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
<span class="n">e</span>
</pre></div>
<p>Here's the result:</p>
<div class="highlight"><pre><span></span><span class="k">if</span>
<span class="n">a</span>
<span class="o">==</span>
<span class="mi">1</span>
<span class="p">:</span>
<span class="n">BEGIN</span>
<span class="k">if</span>
<span class="n">b</span>
<span class="o">==</span>
<span class="mi">0</span>
<span class="p">:</span>
<span class="n">BEGIN</span>
<span class="n">c</span>
<span class="n">END</span>
<span class="n">END</span>
<span class="k">if</span>
<span class="n">d</span>
<span class="o">==</span>
<span class="mi">3</span>
<span class="p">:</span>
<span class="n">BEGIN</span>
<span class="n">e</span>
<span class="n">END</span>
</pre></div>
<p>Spirit.Qi could treat the <tt class="docutils literal">BEGIN</tt> and <tt class="docutils literal">END</tt> tokens as block delimiters, exactly as curly braces in C/C++.</p>
<p>There's still a limitation however: There must be a newline at the end of the input otherwise the end of input cannot be detected in the HandleNewline function. A possible workaround I could think of is to have an iterator adapter to add the missing newline in the end of the input if needed.</p>
<p>It would make lexing python much easier if Spirit.Lex could support matching pseudo tokens like:</p>
<ul class="simple">
<li>Begin of the line</li>
<li>End of the line</li>
<li>Begin of the input</li>
<li>End of the input</li>
</ul>
<p>For Spirit.Lex currently there is no clear way to fail the whole lexing process inside the semantic action. Assigning <tt class="docutils literal">pass_failed</tt> flag won't work since it only fails current token's matching process. In the code above an exception is thrown to stop the lexing process, however I do hope there is a build-in support for this.</p>
<p>Finally, there seems no debug support in Spirit.Lex as in Spirit.Qi. A debug support like what Spirit.Qi provides will be very handy for trouble shooting in Spirit.Lex (Spirix.Lex actually has debug support using the macro <tt class="docutils literal">BOOST_SPIRIT_LEXERTL_DEBUG</tt>)</p>
<p>References:</p>
<ul class="simple">
<li><a class="reference external" href="http://docs.python.org/release/3.1.3/reference/lexical_analysis.html#indentation">Python lexical analysis for indentation</a></li>
<li><a class="reference external" href="http://boost.2283326.n4.nabble.com/lexing-python-redux-td2681157.htm">Lexing python redux discussion</a></li>
</ul>
</section>
</div>
<footer>
<p>
<time datetime="2011-09-08T22:06:00+08:00" pubdate>2011-09-08</time><a href="https://zhuoqiang.github.io/category/programming.html"><span class="category" i18n>programming</span></a>
</p>
<ul>
<li><a href="https://zhuoqiang.github.io/tag/boost.html"><span class="tag" i18n>boost</span></i></a>
<li><a href="https://zhuoqiang.github.io/tag/c.html"><span class="tag" i18n>c++</span></i></a>
<li><a href="https://zhuoqiang.github.io/tag/compiler.html"><span class="tag" i18n>compiler</span></i></a>
<li><a href="https://zhuoqiang.github.io/tag/english.html"><span class="tag" i18n>english</span></i></a>
<li><a href="https://zhuoqiang.github.io/tag/python.html"><span class="tag" i18n>python</span></i></a>
<li><a href="https://zhuoqiang.github.io/tag/spirit.html"><span class="tag" i18n>spirit</span></i></a>
</ul>
</footer><link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
<script src="https://unpkg.com/gitalk@latest/dist/gitalk.min.js"></script>
<div id="gitalk-container"></div>
<script type="text/javascript">
var gitalk = new Gitalk({
clientID: "2f60008869581fd61d19",
clientSecret: "6b303dcf58c04cd35782bae82540921663cbfda8",
repo: "zhuoqiang.github.com",
owner: "zhuoqiang",
admin: ["zhuoqiang"],
id: "lexing-python-indentation-using-spirit-lex",
title: "Lexing Python Indentation using Spirit.Lex",
perPage: 30,
distractionFreeMode: true,
pagerDirection: "last",
});
gitalk.render('gitalk-container');
</script></article>
</section>
<footer>
<p>@ <a href="mailto:[email protected]"><span i18n>Qiang</span></a> | <span class="heart"><a href="https://github.com/getpelican/pelican">Pelican</a> & <a href="https://bitbucket.org/zhuoqiang/jing">Jing</a></span></p>
</footer>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js"></script>
<script>window.jQuery || document.write('<script src="https://zhuoqiang.github.io/theme/js/vendor/jquery-1.8.3.min.js"><\/script>')</script>
<script src="https://zhuoqiang.github.io/theme/js/vendor/moment.min.js"></script>
<script src="https://zhuoqiang.github.io/theme/js/vendor/moment-lang.min.js"></script>
<script src="https://zhuoqiang.github.io/theme/js/vendor/i18next-1.6.0.min.js"></script>
<script src="https://zhuoqiang.github.io/theme/js/main.js"></script>
<script type="text/javascript">
var GoSquared = {};
GoSquared.acct = "GSN-743443-H";
(function(w){
function gs(){
w._gstc_lt = +new Date;
var d = document, g = d.createElement("script");
g.type = "text/javascript";
g.src = "//d1l6p2sc9645hc.cloudfront.net/tracker.js";
var s = d.getElementsByTagName("script")[0];
s.parentNode.insertBefore(g, s);
}
w.addEventListener ?
w.addEventListener("load", gs, false) :
w.attachEvent("onload", gs);
})(window);
</script>
</body>
</html>