@@ -19,28 +19,29 @@ operators of Optscript and PostScript are the same. You can get the
19
19
basic knowledge for using Optscript from the materials for learning
20
20
PostScript.
21
21
22
- "PostScript Language Tutorial & Cookbook" published by Adobe Systems
23
- Inc. The book is known as "blue book". This is the best place to
22
+ "PostScript Language Tutorial & Cookbook" is a book published by Adobe
23
+ Systems Inc. The book, known as "blue book", is the best place to
24
24
start. PostScript is a language for controlling printers. So it has
25
- many graphical operators. Optscript is for tagging, and doesn't have
26
- such graphical operators. So you can skip the sections about graphics
25
+ many graphical operators. Optscript doesn't have such graphical
26
+ operators. So you can skip the sections about graphics
27
27
(but you may want to read them because the book is written well).
28
28
29
29
Ghostscript (``gs `` or ``gsnd ``) is an interpreter for the PostScript
30
30
language and PDF files. Unlike Optscript, it implements the full-set of
31
31
PostScript features including graphical operators. It is available
32
- under either the GNU GPL Affero license. You can Ghostscript while
32
+ under either the GNU GPL Affero license. You can use Ghostscript while
33
33
reading the blue book. Do web searching to know about Ghostscript.
34
34
35
- ``optscript `` is an command that source files are included in
36
- Universal Ctags source tree. You can use it as the replacement of
37
- ``gs ``. However, I recommend you to have ``gs `` at hand because
38
- ``optscript `` may have bugs. ``gs `` is much mature than ``optscript ``.
39
- Having two interpreters helps you to know correct behavior.
35
+ ``optscript `` is a command that source files are included in the
36
+ source tree of Universal Ctags. You can use it as the replacement of
37
+ ``gs `` to learn PostScript. However, I recommend you to have ``gs `` at
38
+ hand because ``optscript `` may have bugs. ``gs `` is much mature than
39
+ ``optscript ``. Having two interpreters helps you to know expected
40
+ behavior of the language.
40
41
41
42
Though ``gs `` has much higher qualities than ``optscript ``, eventually
42
43
you may have to build the ``optscript `` command to learn Optscript
43
- specific operators. You can built the command with "``make
44
+ specific operators for tagging . You can built the command with "``make
44
45
optscript ``".
45
46
46
47
* red book
@@ -164,9 +165,29 @@ easily, Python sessions doing the same as Optscript are also written.
164
165
>>> add5_and_print(4 )
165
166
9
166
167
167
- * string manipulation
168
+ * String manipulation
169
+
170
+ - Comparison
171
+
172
+ Optscript:
173
+
174
+ .. code-block :: console
175
+
176
+ OPT> (abc) (efg) eq { (same) = } { (different) = } ifelse
177
+ different
178
+ OPT> (abc) (abc) eq { (same) = } { (different) = } ifelse
179
+ same
180
+
181
+ Python:
182
+
183
+ .. code-block :: console
184
+
185
+ >>> if 'abc' == 'efg':
186
+ ... print ('same')
187
+ ... else:
188
+ ... print ('different')
189
+ different
168
190
169
- TBW
170
191
171
192
* array manipulation
172
193
@@ -190,6 +211,8 @@ easily, Python sessions doing the same as Optscript are also written.
190
211
191
212
Optscript in ctags
192
213
~~~~~~~~~~~~~~~~~~
214
+ Optscript executable in ctags assumes that all tags are in the corkQueue and
215
+ they have corkIndexes. See ":ref: `output-tag-stream `" about corkQueue and corkIndexes.
193
216
194
217
Related options
195
218
...............
@@ -242,12 +265,12 @@ TBW: two timings of evaluation
242
265
243
266
Put code fragments at the end of options with surrounding "``{{ ``" and
244
267
"``}} ``". Though it is not impossible, a command line is not suitable
245
- place to put code fragments because the code fragments may be long.
246
- Instead, you should write them to a .ctags file.
268
+ place to write code fragments because the options with code fragments
269
+ may be too long. Instead, you should write them to your .ctags file.
247
270
248
- .. warning :: An important rule in writing Optscript code in a file is
249
- the start marker, ``{{ `` must be at the end of line, and the end
250
- marker ``}} `` must be at the beginning of line. If you break the
271
+ .. warning :: An important rule in writing Optscript code in a .ctags
272
+ file is the start marker, ``{{ ``, must be at the end of line, and the
273
+ end marker, ``}} ``, must be at the beginning of line. If you break the
251
274
rule, the optlib loader of ctags fails to read your file.
252
275
253
276
``--_prelude-<LANG> `` is for specified code fragments run at the
@@ -269,62 +292,139 @@ represents the field has an operator for reading
269
292
(``:fieldname ``). ``w `` represents the field has an operator for
270
293
writing (``fieldname: ``).
271
294
295
+ ``optlib2c ``, a translator from .ctags file to C language source file
296
+ supports the code framents. Some of optlib parsers integrated to
297
+ Universal Ctags already use Optscript. You can find practical
298
+ examples of Optscript in files in ``optlib `` directory. The positional
299
+ rules about `{{ ` and `}} ` is applicable to ``optlib2c ``.
300
+
301
+ Data types
302
+ ..........
303
+
304
+ Non-standard data types for tagging are added. You can use it only in
305
+ ``ctags `` command, not in ``optscript `` command.
306
+
307
+ ``matchloc ``
308
+
309
+ This opaque data type is for representing a position in a source
310
+ file. The name is an acronym for "match location". ``_matchloc ``
311
+ pushes a ``matchloc `` object to ``ostack ``.
312
+
313
+ ``corkIndex:int `` or ``index:int ``
314
+
315
+ This represents a corkIndex. ``. `` pushes the corkIndex for a tag
316
+ just created with the option owning the code frament.
317
+
318
+ ``tag ``
319
+
320
+ This represents a tag data structure which is not in the corkQueue
321
+ yet. ``_tag `` is an operator pushing a ``tag `` object to
322
+ ``ostack ``. ``_commit `` puts the ``tag `` object on ``ostack `` to
323
+ the corkQueue, and pushes an integer as a corkIndex.
324
+
272
325
Operators
273
326
............................
274
327
275
328
**. ** -> ``- `` **. ** ``corkIndex:int ``
276
329
277
- Push the cork index for the tag
330
+ Push the cork index for the tag
278
331
279
332
**\\ n ** -> ``- `` **\\ n ** ``matchedString:string ``
280
333
281
- ``n `` is an integer (0 ...9) representing a group in a pattern.
334
+ ``n `` is an integer (1 ...9) representing a group in a pattern.
282
335
Push the matched string for the group.
283
336
284
337
``_matchloc ``
285
338
286
- TBW
339
+ TBW
287
340
288
341
``:field `` (See the output of ``--_list-operators ``)
289
342
290
- Get the value for the specified field from a tag
343
+ Get the value for the specified field from a tag
291
344
and put it.
292
345
293
346
``field: `` (See the output of ``--_list-operators ``)
294
347
295
- Set a value at the stack to the specified field of a tag.
348
+ Set a value at the stack to the specified field of a tag.
296
349
297
350
``_tag ``
298
351
299
- TBW
352
+ TBW
300
353
301
- ``_COMMIT ``
354
+ ``_commit ``
302
355
303
- TBW
356
+ TBW
304
357
305
358
``_traced ``
306
359
307
- TBW
360
+ TBW
308
361
309
- Data types
310
- ..........
311
362
312
- ``MATCHLOC ``
363
+ Recipes
364
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
313
365
314
- TBW
366
+ Arrange the name of a tag
367
+ ...........................................
315
368
316
- `` index:int ``
369
+ "input.foo":
317
370
318
- TBW
371
+ .. code-block ::
319
372
320
- ``TAG ``
373
+ def a
374
+ def b
321
375
322
- TBW
376
+ Goal: If a language specific extra ``extendedName `` is given, the
377
+ parser for input.foo emits extra tags having ``X `` as prefix.
323
378
324
- Recipes
325
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
379
+ The base version of .ctags ("foo0.ctags"):
380
+
381
+ .. code-block :: ctags
382
+
383
+ --langdef=foo
384
+ --map-foo=.foo
385
+ --kinddef-foo=d,definition,definitions
386
+ --regex-foo=/^def[ \t]+([a-z]+)/\1/d/
387
+
388
+ The tags output ("output0.tags") for the base version
389
+ with "``--optoins=foo0.ctags input.foo ``":
390
+
391
+ .. code-block :: tags
392
+
393
+ a input.foo /^def a$/;" d
394
+ b input.foo /^def b$/;" d
395
+
396
+ The Optscript version of .ctags ("foo1.ctags") for achieving the goal:
397
+
398
+ .. code-block :: ctags
399
+
400
+ --langdef=foo
401
+ --map-foo=.foo
402
+ --kinddef-foo=d,definition,definitions
403
+ --_extradef-foo=extendedName, tags prefixed with X
404
+ --regex-foo=/^def[ \t]+([a-z]+)/\1/d/{{
405
+ /foo.extendedName _extraenabled {
406
+ mark \1 ?X _buildstring % name, \1 + 'X'
407
+ /definition % kind
408
+ 1 _matchloc % location for \1
409
+ _tag % a tag object is pushed.
410
+ % ostack => tag
411
+ dup
412
+ % ostack => tag tag
413
+ /foo.extendedName _markextra
414
+ % ostack => tag
415
+ _commit
416
+ } if
417
+ }}
418
+
419
+ The tags output ("output1.tags") for the Optscript version
420
+ with "``--optoins=foo1.ctags --extras-foo=+'{extendedName}' input.foo ``":
421
+
422
+ .. code-block :: tags
326
423
327
- TBW
424
+ a input.foo /^def a$/;" d
425
+ aX input.foo /^def a$/;" d
426
+ b input.foo /^def b$/;" d
427
+ bX input.foo /^def b$/;" d
328
428
329
429
Difference between Optscript and PostScript
330
430
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments