aboutsummaryrefslogtreecommitdiff
path: root/ctags/docs/optscript.html
blob: 158f633e128ab32fcb651ba2e514a2046fb0291e (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
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Optscript, a programming language for extending optlib parsers &#8212; Universal Ctags 0.3.0 documentation</title>
    <link rel="stylesheet" type="text/css" href="_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="_static/classic.css" />
    
    <script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
    <script src="_static/jquery.js"></script>
    <script src="_static/underscore.js"></script>
    <script src="_static/doctools.js"></script>
    
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Extending ctags with a parser written in C" href="extending.html" />
    <link rel="prev" title="Extending ctags with Regex parser (optlib)" href="optlib.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="extending.html" title="Extending ctags with a parser written in C"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="optlib.html" title="Extending ctags with Regex parser (optlib)"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Universal Ctags 0.3.0 documentation</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">Optscript, a programming language for extending optlib parsers</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="optscript-a-programming-language-for-extending-optlib-parsers">
<span id="optscript"></span><h1>Optscript, a programming language for extending optlib parsers<a class="headerlink" href="#optscript-a-programming-language-for-extending-optlib-parsers" title="Permalink to this headline"></a></h1>
<div class="contents local topic" id="table-of-contents">
<p class="topic-title"><cite>Table of contents</cite></p>
<ul class="simple">
<li><p><a class="reference internal" href="#preparation-for-learning" id="id1">Preparation for learning</a></p></li>
<li><p><a class="reference internal" href="#syntax-extension" id="id2">Syntax extension</a></p></li>
<li><p><a class="reference internal" href="#the-optscript-command" id="id3">The <code class="docutils literal notranslate"><span class="pre">optscript</span></code> command</a></p></li>
<li><p><a class="reference internal" href="#optscript-in-ctags" id="id4">Optscript in ctags</a></p>
<ul>
<li><p><a class="reference internal" href="#related-options" id="id5">Related options</a></p></li>
<li><p><a class="reference internal" href="#operators" id="id6">Operators</a></p></li>
<li><p><a class="reference internal" href="#data-types" id="id7">Data types</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#recipes" id="id8">Recipes</a></p></li>
<li><p><a class="reference internal" href="#difference-between-optscript-and-postscript" id="id9">Difference between Optscript and PostScript</a></p></li>
</ul>
</div>
<section id="preparation-for-learning">
<h2><a class="toc-backref" href="#id1">Preparation for learning</a><a class="headerlink" href="#preparation-for-learning" title="Permalink to this headline"></a></h2>
<p><strong>Optscript</strong> is an implementation of PostScript(tm) alike stack
oriented general purpose programming language.  Developers of optlib
parsers can utilize the language for extending their parsers.</p>
<p>You may not be familiar with a stack oriented programming language.
Though there are some differences, the syntax and core non-graphical
operators of Optscript and PostScript are the same. You can get the
basic knowledge for using Optscript from the materials for learning
PostScript.</p>
<p>“PostScript Language Tutorial &amp; Cookbook” published by Adobe Systems
Inc. The book is known as “blue book”. This is the best place to
start.  PostScript is a language for controlling printers. So it has
many graphical operators. Optscript is for tagging, and doesn’t have
such graphical operators. So you can skip the sections about graphics
(but you may want to read them because the book is written well).</p>
<p>Ghostscript (<code class="docutils literal notranslate"><span class="pre">gs</span></code> or <code class="docutils literal notranslate"><span class="pre">gsnd</span></code>) is an interpreter for the PostScript
language and PDF files. Unlike Optscript, it implements the full-set of
PostScript features including graphical operators. It is available
under either the GNU GPL Affero license. You can Ghostscript while
reading the blue book. Do web searching to know about Ghostscript.</p>
<p><code class="docutils literal notranslate"><span class="pre">optscript</span></code> is an command that source files are included in
Universal Ctags source tree. You can use it as the replacement of
<code class="docutils literal notranslate"><span class="pre">gs</span></code>. However, I recommend you to have <code class="docutils literal notranslate"><span class="pre">gs</span></code> at hand because
<code class="docutils literal notranslate"><span class="pre">optscript</span></code> may have bugs. <code class="docutils literal notranslate"><span class="pre">gs</span></code> is much mature than <code class="docutils literal notranslate"><span class="pre">optscript</span></code>.
Having two interpreters helps you to know correct behavior.</p>
<p>Though <code class="docutils literal notranslate"><span class="pre">gs</span></code> has much higher qualities than <code class="docutils literal notranslate"><span class="pre">optscript</span></code>, eventually
you may have to build the <code class="docutils literal notranslate"><span class="pre">optscript</span></code> command to learn Optscript
specific operators. You can built the command with “<code class="docutils literal notranslate"><span class="pre">make</span>
<span class="pre">optscript</span></code>”.</p>
<ul>
<li><p>red book</p>
<p>TBW</p>
</li>
</ul>
</section>
<section id="syntax-extension">
<h2><a class="toc-backref" href="#id2">Syntax extension</a><a class="headerlink" href="#syntax-extension" title="Permalink to this headline"></a></h2>
<p><code class="docutils literal notranslate"><span class="pre">?</span></code> is a prefix for representing a character literal.</p>
<p>For an example, <code class="docutils literal notranslate"><span class="pre">?x</span></code> represents 120. This is a short cut for <code class="docutils literal notranslate"><span class="pre">(x)</span> <span class="pre">0</span>
<span class="pre">get</span></code>.</p>
<p>Some characters has special notation using <code class="docutils literal notranslate"><span class="pre">\</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">?\t</span></code></p>
<blockquote>
<div><p>tab</p>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">?\n</span></code></p>
<blockquote>
<div><p>newline</p>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">?\_</span></code></p>
<blockquote>
<div><p>space</p>
</div></blockquote>
</section>
<section id="the-optscript-command">
<h2><a class="toc-backref" href="#id3">The <code class="docutils literal notranslate"><span class="pre">optscript</span></code> command</a><a class="headerlink" href="#the-optscript-command" title="Permalink to this headline"></a></h2>
<p>You can run optscript with no argument:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>./optsript
<span class="go">OPT&gt;</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">OPT&gt;</span></code> is the prompt of the interpreter.
You can stop it with <code class="docutils literal notranslate"><span class="pre">quit</span></code> operator:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>./optsript
<span class="go">OPT&gt; quit</span>
<span class="gp">$</span>
</pre></div>
</div>
<p>Let’s see some example sessions.  To help you understand the session
easily, Python sessions doing the same as Optscript are also written.</p>
<ul>
<li><p>hello world</p>
<p>Optscript:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">OPT&gt; (hello, world) =</span>
<span class="go">hello, world</span>
</pre></div>
</div>
<p>Python:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">&gt;&gt;&gt; print (&#39;hello, world&#39;)</span>
<span class="go">hello, world</span>
</pre></div>
</div>
</li>
<li><p>Adding</p>
<p>Optscript:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">OPT&gt; 2 3 add =</span>
<span class="go">5</span>
</pre></div>
</div>
<p>Python:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">&gt;&gt;&gt; print (2 + 3)</span>
<span class="go">5</span>
</pre></div>
</div>
</li>
<li><p>Variables</p>
<p>Optscript:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">OPT&gt; /x 2 def</span>
<span class="go">OPT&gt; /y 3 def</span>
<span class="go">OPT&gt; x y add =</span>
<span class="go">5</span>
</pre></div>
</div>
<p>Python:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">&gt;&gt;&gt; x = 2</span>
<span class="go">&gt;&gt;&gt; y = 3</span>
<span class="go">&gt;&gt;&gt; print (x + y)</span>
<span class="go">5</span>
</pre></div>
</div>
</li>
<li><p>Procedures</p>
<p>Optscript:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">OPT&gt; /add5_and_print { 5 add = } def</span>
<span class="go">OPT&gt; 4 add5_and_print</span>
<span class="go">9</span>
</pre></div>
</div>
<p>Python:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">&gt;&gt;&gt; def add5_and_print(x):</span>
<span class="go">...    print(x + 5);</span>
<span class="go">&gt;&gt;&gt; add5_and_print(4)</span>
<span class="go">9</span>
</pre></div>
</div>
</li>
<li><p>string manipulation</p>
<p>TBW</p>
</li>
<li><p>array manipulation</p>
<p>TBW</p>
</li>
<li><p>dict manipulation</p>
<p>TBW</p>
</li>
<li><p>control flow</p>
<p>TBW</p>
</li>
<li><p>operators for printing</p>
<p>TBW</p>
</li>
<li><p>reading script from file</p>
<p>TBW</p>
</li>
</ul>
</section>
<section id="optscript-in-ctags">
<h2><a class="toc-backref" href="#id4">Optscript in ctags</a><a class="headerlink" href="#optscript-in-ctags" title="Permalink to this headline"></a></h2>
<section id="related-options">
<h3><a class="toc-backref" href="#id5">Related options</a><a class="headerlink" href="#related-options" title="Permalink to this headline"></a></h3>
<div class="highlight-ctags notranslate"><div class="highlight"><pre><span></span>--_prelude-&lt;LANG&gt;={{
<span class="w">        </span>OPTSCRIPT CODE FRAGMENTS
}}

--_sequel-&lt;LANG&gt;={{
<span class="w">        </span>OPTSCRIPT CODE FRAGMENTS
}}

--regex-&lt;LANG&gt;=&lt;PATTERN&gt;/&lt;NAME&gt;/[&lt;KIND&gt;/]LONGFLAGS...{{
<span class="w">        </span>OPTSCRIPT CODE FRAGMENTS
}}

--regex-&lt;LANG&gt;=&lt;PATTERN&gt;//LONGFLAGS...{{
<span class="w">        </span>OPTSCRIPT CODE FRAGMENTS
}}

--mline-regex-&lt;LANG&gt;=&lt;PATTERN&gt;/&lt;NAME&gt;/[&lt;KIND&gt;/]LONGFLAGS...{{
<span class="w">        </span>OPTSCRIPT CODE FRAGMENTS
}}

--mline-regex-&lt;LANG&gt;=&lt;PATTERN&gt;//LONGFLAGS...{{
<span class="w">        </span>OPTSCRIPT CODE FRAGMENTS
}}

--_mtable-regex-&lt;LANG&gt;=&lt;TABLE&gt;/&lt;PATTERN&gt;/&lt;NAME&gt;/[&lt;KIND&gt;/]LONGFLAGS...{{
<span class="w">        </span>OPTSCRIPT CODE FRAGMENTS
}}

--_mtable-regex-&lt;LANG&gt;=&lt;TABLE&gt;/&lt;PATTERN&gt;//LONGFLAGS...{{
<span class="w">        </span>OPTSCRIPT CODE FRAGMENTS
}}

--_list-operators

--list-fields
</pre></div>
</div>
<p>You can run optscript code fragments when pattern specified with
options matches successfully. The options are <code class="docutils literal notranslate"><span class="pre">--regex-&lt;LANG&gt;</span></code>,
<code class="docutils literal notranslate"><span class="pre">--mline-regex-&lt;LANG&gt;</span></code>, and <code class="docutils literal notranslate"><span class="pre">--_mtable-regex-&lt;LANG&gt;</span></code> as you
expect. In addition, <code class="docutils literal notranslate"><span class="pre">--_prelude-&lt;LANG&gt;</span></code> and <code class="docutils literal notranslate"><span class="pre">--_sequel-&lt;LANG&gt;</span></code>
options also take code fragments.</p>
<p>TBW: two timings of evaluation</p>
<p>Put code fragments at the end of options with surrounding “<code class="docutils literal notranslate"><span class="pre">{{</span></code> and
<code class="docutils literal notranslate"><span class="pre">}}</span></code>”. Though it is not impossible, a command line is not suitable
place to put code fragments because the code fragments may be long.
Instead, you should write them to a .ctags file.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>An important rule in writing Optscript code in a file is
the start marker, <code class="docutils literal notranslate"><span class="pre">{{</span></code> must be at the end of line, and the end
marker <code class="docutils literal notranslate"><span class="pre">}}</span></code> must be at the beginning of line. If you break the
rule, the optlib loader of ctags fails to read your file.</p>
</div>
<p><code class="docutils literal notranslate"><span class="pre">--_prelude-&lt;LANG&gt;</span></code> is for specified code fragments run at the
beginning of parsing a source file. You can use this option for
defining the common code used in the parser.</p>
<p><code class="docutils literal notranslate"><span class="pre">--_sequel-&lt;LANG&gt;</span></code> is for for specified code fragments run at the end
of parser a source file. You can use this option for debug-printing
the final state of parsing the source file.
e.g. <code class="docutils literal notranslate"><span class="pre">--_sequel-Foo={{</span> <span class="pre">_traced</span> <span class="pre">{</span> <span class="pre">pstack</span> <span class="pre">}</span> <span class="pre">if</span> <span class="pre">}}</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">--_list-operators</span></code> lists all operators (and built-in procedures)
and exits. In additions to operators defined in  <code class="docutils literal notranslate"><span class="pre">optscript</span></code>,
<code class="docutils literal notranslate"><span class="pre">ctags</span></code> provides operators for tagging.</p>
<p><code class="docutils literal notranslate"><span class="pre">OP</span></code> column of <code class="docutils literal notranslate"><span class="pre">--list-fields</span></code> represents the availability of
operators for accessing the field specified in the line.  <code class="docutils literal notranslate"><span class="pre">r</span></code>
represents the field has an operator for reading
(<code class="docutils literal notranslate"><span class="pre">:fieldname</span></code>). <code class="docutils literal notranslate"><span class="pre">w</span></code> represents the field has an operator for
writing (<code class="docutils literal notranslate"><span class="pre">fieldname:</span></code>).</p>
</section>
<section id="operators">
<h3><a class="toc-backref" href="#id6">Operators</a><a class="headerlink" href="#operators" title="Permalink to this headline"></a></h3>
<p><strong>.</strong> -&gt; <code class="docutils literal notranslate"><span class="pre">-</span></code> <strong>.</strong> <code class="docutils literal notranslate"><span class="pre">corkIndex:int</span></code></p>
<blockquote>
<div><p>Push the cork index for the tag</p>
</div></blockquote>
<p><strong>\n</strong> -&gt; <code class="docutils literal notranslate"><span class="pre">-</span></code> <strong>\n</strong> <code class="docutils literal notranslate"><span class="pre">matchedString:string</span></code></p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">n</span></code> is an integer (0…9) representing a group in a pattern.
Push the matched string for the group.</p>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">_matchloc</span></code></p>
<blockquote>
<div><p>TBW</p>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">:field</span></code> (See the output of <code class="docutils literal notranslate"><span class="pre">--_list-operators</span></code>)</p>
<blockquote>
<div><dl class="simple">
<dt>Get the value for the specified field from a tag</dt><dd><p>and put it.</p>
</dd>
</dl>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">field:</span></code> (See the output of <code class="docutils literal notranslate"><span class="pre">--_list-operators</span></code>)</p>
<blockquote>
<div><p>Set a value at the stack to the specified field of a tag.</p>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">_tag</span></code></p>
<blockquote>
<div><p>TBW</p>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">_COMMIT</span></code></p>
<blockquote>
<div><p>TBW</p>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">_traced</span></code></p>
<blockquote>
<div><p>TBW</p>
</div></blockquote>
</section>
<section id="data-types">
<h3><a class="toc-backref" href="#id7">Data types</a><a class="headerlink" href="#data-types" title="Permalink to this headline"></a></h3>
<p><code class="docutils literal notranslate"><span class="pre">MATCHLOC</span></code></p>
<blockquote>
<div><p>TBW</p>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">index:int</span></code></p>
<blockquote>
<div><p>TBW</p>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">TAG</span></code></p>
<blockquote>
<div><p>TBW</p>
</div></blockquote>
</section>
</section>
<section id="recipes">
<h2><a class="toc-backref" href="#id8">Recipes</a><a class="headerlink" href="#recipes" title="Permalink to this headline"></a></h2>
<p>TBW</p>
</section>
<section id="difference-between-optscript-and-postscript">
<h2><a class="toc-backref" href="#id9">Difference between Optscript and PostScript</a><a class="headerlink" href="#difference-between-optscript-and-postscript" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li><p>Memory management</p></li>
<li><p>Dynamically extendable data type</p>
<ul>
<li><p>string</p></li>
<li><p>array</p></li>
</ul>
</li>
</ul>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Optscript, a programming language for extending optlib parsers</a><ul>
<li><a class="reference internal" href="#preparation-for-learning">Preparation for learning</a></li>
<li><a class="reference internal" href="#syntax-extension">Syntax extension</a></li>
<li><a class="reference internal" href="#the-optscript-command">The <code class="docutils literal notranslate"><span class="pre">optscript</span></code> command</a></li>
<li><a class="reference internal" href="#optscript-in-ctags">Optscript in ctags</a><ul>
<li><a class="reference internal" href="#related-options">Related options</a></li>
<li><a class="reference internal" href="#operators">Operators</a></li>
<li><a class="reference internal" href="#data-types">Data types</a></li>
</ul>
</li>
<li><a class="reference internal" href="#recipes">Recipes</a></li>
<li><a class="reference internal" href="#difference-between-optscript-and-postscript">Difference between Optscript and PostScript</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="optlib.html"
                        title="previous chapter">Extending ctags with Regex parser (<em>optlib</em>)</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="extending.html"
                        title="next chapter">Extending ctags with a parser written in C</a></p>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="extending.html" title="Extending ctags with a parser written in C"
             >next</a> |</li>
        <li class="right" >
          <a href="optlib.html" title="Extending ctags with Regex parser (optlib)"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Universal Ctags 0.3.0 documentation</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">Optscript, a programming language for extending optlib parsers</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2015, Universal Ctags Team.
      Last updated on 11 Jun 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.0.2.
    </div>
  </body>
</html>