xref: /Universal-ctags/docs/internal.rst (revision aaaac7eeac8399141aa8e6d9e6ec0379931848b2)
1b45a42b3SHiroo HAYASHI.. ctags Internal API
2b45a42b3SHiroo HAYASHI.. ---------------------------------------------------------------------
35ab497a3SMasatake YAMATO
4063580daSHiroo HAYASHI.. _input-text-stream:
5063580daSHiroo HAYASHI
65ab497a3SMasatake YAMATOInput text stream
7eb375513SMasatake YAMATO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85ab497a3SMasatake YAMATO
9bde94b5aSMasatake YAMATO.. figure:: input-text-stream.svg
10bde94b5aSMasatake YAMATO	    :scale: 80%
11bde94b5aSMasatake YAMATO
12e54558c7SMasatake YAMATOFunction prototypes for handling input text stream are declared in
1386bcb5c2SHiroo HAYASHI``main/read.h``. The file exists in Exuberant Ctags, too.  However, the
14e54558c7SMasatake YAMATOnames functions are changed when overhauling ``--line-directive``
15e54558c7SMasatake YAMATOoption. (In addition macros were converted to functions for making
16e54558c7SMasatake YAMATOdata structures for the input text stream opaque.)
17bde94b5aSMasatake YAMATO
1886bcb5c2SHiroo HAYASHICtags has 3 groups of functions for handling input: *input*, *bypass*, and
1986bcb5c2SHiroo HAYASHI*raw*. Parser developers should use input group. The rest of two
20bde94b5aSMasatake YAMATOare for ctags main part.
21bde94b5aSMasatake YAMATO
22bde94b5aSMasatake YAMATO
23338e986cSMasatake YAMATO.. _inputFile:
24338e986cSMasatake YAMATO
25bde94b5aSMasatake YAMATO`inputFile` type and the functions of input group
26eb375513SMasatake YAMATO......................................................................
27bde94b5aSMasatake YAMATO
283cd8570eSHiroo HAYASHI.. note:: The original version of this section was written
293cd8570eSHiroo HAYASHI	before ``inputFile`` type and ``File`` variable are made private.
30e54558c7SMasatake YAMATO
3186bcb5c2SHiroo HAYASHI``inputFile`` is the type for representing the input file and stream for
3286bcb5c2SHiroo HAYASHIa parser. It was declared in ``main/read.h`` but now it is defined in
3386bcb5c2SHiroo HAYASHI``main/read.c``.
34e54558c7SMasatake YAMATO
3586bcb5c2SHiroo HAYASHICtags uses a file static variable ``File`` having type ``inputFile`` for
3686bcb5c2SHiroo HAYASHImaintaining the input file and stream. ``File`` is also defined in
3786bcb5c2SHiroo HAYASHImain/read.c as ``inputFile`` is.
38bde94b5aSMasatake YAMATO
3986bcb5c2SHiroo HAYASHI``fp`` and ``line`` are the essential fields of ``File``. ``fp`` having type
4086bcb5c2SHiroo HAYASHIwell known ``MIO`` declared in ``main/mio.h``. By calling functions of input group
4186bcb5c2SHiroo HAYASHI(``getcFromInputFile`` and ``readLineFromInputFile``), a parser gets input
4286bcb5c2SHiroo HAYASHItext from ``fp``.
43bde94b5aSMasatake YAMATO
443cd8570eSHiroo HAYASHIThe functions of input group updates fields ``input`` and ``source`` of ``File`` variable.
4586bcb5c2SHiroo HAYASHIThese two fields has type ``inputFileInfo``. These two fields are for mainly
46bde94b5aSMasatake YAMATOtracking the name of file and the current line number. Usually ctags uses
473cd8570eSHiroo HAYASHIonly ``input`` field. ``source`` field is used only when ``#line`` directive is found
48bde94b5aSMasatake YAMATOin the current input text stream.
49bde94b5aSMasatake YAMATO
50bde94b5aSMasatake YAMATOA case when a tool generates the input file from another file, a tool
51bde94b5aSMasatake YAMATOcan record the original source file to the generated file with using
523cd8570eSHiroo HAYASHIthe ``#line`` directive. ``source`` field is used for tracking/recording the
5386bcb5c2SHiroo HAYASHIinformation appeared on ``#line`` directives.
54bde94b5aSMasatake YAMATO
55bde94b5aSMasatake YAMATORegex pattern matching are also done behind calling the functions of
56bde94b5aSMasatake YAMATOthis group.
57bde94b5aSMasatake YAMATO
58bde94b5aSMasatake YAMATO
59bde94b5aSMasatake YAMATOThe functions of bypass group
60eb375513SMasatake YAMATO......................................................................
6186bcb5c2SHiroo HAYASHIThe functions of bypass group (``readLineFromBypass`` and
6286bcb5c2SHiroo HAYASHI``readLineFromBypassSlow``) are used for reading text from ``fp`` field of
6386bcb5c2SHiroo HAYASHI``File`` static variable without updating ``input`` and ``source`` fields of
643cd8570eSHiroo HAYASHI``File`` variable.
65bde94b5aSMasatake YAMATO
66bde94b5aSMasatake YAMATO
67bde94b5aSMasatake YAMATOParsers may not need the functions of this group.  The functions are
68bde94b5aSMasatake YAMATOused in ctags main part. The functions are used to make pattern
69bde94b5aSMasatake YAMATOfields of tags file, for example.
70bde94b5aSMasatake YAMATO
71bde94b5aSMasatake YAMATO
72bde94b5aSMasatake YAMATOThe functions of raw group
73eb375513SMasatake YAMATO......................................................................
7486bcb5c2SHiroo HAYASHIThe functions of this group (``readLineRaw`` and ``readLineRawWithNoSeek``)
7586bcb5c2SHiroo HAYASHItake a parameter having type ``MIO``; and don't touch ``File`` static
76bde94b5aSMasatake YAMATOvariable.
77bde94b5aSMasatake YAMATO
78bde94b5aSMasatake YAMATOParsers may not need the functions of this group.  The functions are
79bde94b5aSMasatake YAMATOused in ctags main part. The functions are used to load option files,
80bde94b5aSMasatake YAMATOfor example.
81bde94b5aSMasatake YAMATO
828fc51ccaSHiroo HAYASHI
838fc51ccaSHiroo HAYASHI.. NOT REVIEWED YET
848fc51ccaSHiroo HAYASHI
858fc51ccaSHiroo HAYASHI.. _output-tag-stream:
868fc51ccaSHiroo HAYASHI
878fc51ccaSHiroo HAYASHIOutput tag stream
888fc51ccaSHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
898fc51ccaSHiroo HAYASHI
908fc51ccaSHiroo HAYASHI.. figure:: output-tag-stream.svg
918fc51ccaSHiroo HAYASHI	    :scale: 80%
928fc51ccaSHiroo HAYASHI
938fc51ccaSHiroo HAYASHICtags provides ``makeTagEntry`` to parsers as an entry point for writing
948fc51ccaSHiroo HAYASHItag information to MIO. ``makeTagEntry`` calls ``writeTagEntry`` if the
952095a109SMasatake YAMATOparser does not set ``CORK_QUEUE`` to ``useCork`` field. ``writeTagEntry`` calls ``writerWriteTag``.
968fc51ccaSHiroo HAYASHI``writerWriteTag`` just calls ``writeEntry`` of writer backends.
978fc51ccaSHiroo HAYASHI``writerTable`` variable holds the four backends: ctagsWriter, etagsWriter,
988fc51ccaSHiroo HAYASHIxrefWriter, and jsonWriter.
998fc51ccaSHiroo HAYASHIOne of them is chosen depending on the arguments passed to ctags.
1008fc51ccaSHiroo HAYASHI
1012095a109SMasatake YAMATOIf ``CORK_QUEUE`` is set to ``useCork``, the tag information goes to a queue on memory.
1028fc51ccaSHiroo HAYASHIThe queue is flushed when ``useCork`` in unset. See "`cork API`_" for more
1038fc51ccaSHiroo HAYASHIdetails.
1048fc51ccaSHiroo HAYASHI
1058fc51ccaSHiroo HAYASHIcork API
1068fc51ccaSHiroo HAYASHI......................................................................
1078fc51ccaSHiroo HAYASHI
1088fc51ccaSHiroo HAYASHIBackground and Idea
109b45a42b3SHiroo HAYASHI^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1108fc51ccaSHiroo HAYASHI*cork API* is introduced for recording scope information easier.
1118fc51ccaSHiroo HAYASHI
1128fc51ccaSHiroo HAYASHIBefore introducing cork API, a scope information must be recorded as
1138fc51ccaSHiroo HAYASHIstrings. It is flexible but memory management is required.
1148fc51ccaSHiroo HAYASHIFollowing code is taken from ``clojure.c`` (with some modifications).
1158fc51ccaSHiroo HAYASHI
1168fc51ccaSHiroo HAYASHI.. code-block:: c
1178fc51ccaSHiroo HAYASHI
1188fc51ccaSHiroo HAYASHI		if (vStringLength (parent) > 0)
1198fc51ccaSHiroo HAYASHI		{
1208fc51ccaSHiroo HAYASHI			current.extensionFields.scope[0] = ClojureKinds[K_NAMESPACE].name;
1218fc51ccaSHiroo HAYASHI			current.extensionFields.scope[1] = vStringValue (parent);
1228fc51ccaSHiroo HAYASHI		}
1238fc51ccaSHiroo HAYASHI
1248fc51ccaSHiroo HAYASHI		makeTagEntry (&current);
1258fc51ccaSHiroo HAYASHI
1268fc51ccaSHiroo HAYASHI``parent``, ``scope [0]`` and ``scope [1]`` are vStrings. The parser must manage
1278fc51ccaSHiroo HAYASHItheir life cycles; the parser cannot free them till the tag referring them via
1288fc51ccaSHiroo HAYASHIits scope fields are emitted, and must free them after emitting.
1298fc51ccaSHiroo HAYASHI
1308fc51ccaSHiroo HAYASHIcork API provides more solid way to hold scope information. cork API
1318fc51ccaSHiroo HAYASHIexpects ``parent``, which represents scope of a tag(``current``)
1328fc51ccaSHiroo HAYASHIcurrently parser dealing, is recorded to a *tags* file before recording
1338fc51ccaSHiroo HAYASHIthe ``current`` tag via ``makeTagEntry`` function.
1348fc51ccaSHiroo HAYASHI
1358fc51ccaSHiroo HAYASHIFor passing the information about ``parent`` to ``makeTagEntry``,
1368fc51ccaSHiroo HAYASHI``tagEntryInfo`` object was created. It was used just for recording; and
1378fc51ccaSHiroo HAYASHIfreed after recording.  In cork API, it is not freed after recording;
1388fc51ccaSHiroo HAYASHIa parser can reused it as scope information.
1398fc51ccaSHiroo HAYASHI
1408fc51ccaSHiroo HAYASHIHow to use
141b45a42b3SHiroo HAYASHI^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1428fc51ccaSHiroo HAYASHI
1438fc51ccaSHiroo HAYASHISee a commit titled with "`clojure: use cork <https://github.com/universal-ctags/ctags/commit/ef181e6>`_".
1448fc51ccaSHiroo HAYASHII applied cork API to the clojure parser.
1458fc51ccaSHiroo HAYASHI
1468fc51ccaSHiroo HAYASHICork API can be enabled and disabled per parser,
1478fc51ccaSHiroo HAYASHIand is disabled by default. So there is no impact till you
1488fc51ccaSHiroo HAYASHIenables it in your parser.
1498fc51ccaSHiroo HAYASHI
1508fc51ccaSHiroo HAYASHI``useCork`` field is introduced in ``parserDefinition`` type:
1518fc51ccaSHiroo HAYASHI
1528fc51ccaSHiroo HAYASHI.. code-block:: c
1538fc51ccaSHiroo HAYASHI
1548fc51ccaSHiroo HAYASHI		typedef struct {
1558fc51ccaSHiroo HAYASHI		...
1568fc51ccaSHiroo HAYASHI				unsigned int useCork;
1578fc51ccaSHiroo HAYASHI		...
1588fc51ccaSHiroo HAYASHI		} parserDefinition;
1598fc51ccaSHiroo HAYASHI
1608fc51ccaSHiroo HAYASHISet ``CORK_QUEUE`` to ``useCork`` like:
1618fc51ccaSHiroo HAYASHI
1628fc51ccaSHiroo HAYASHI.. code-block:: c
1638fc51ccaSHiroo HAYASHI
1648fc51ccaSHiroo HAYASHI    extern parserDefinition *ClojureParser (void)
1658fc51ccaSHiroo HAYASHI    {
1668fc51ccaSHiroo HAYASHI	    ...
1678fc51ccaSHiroo HAYASHI	    parserDefinition *def = parserNew ("Clojure");
1688fc51ccaSHiroo HAYASHI	    ...
1698fc51ccaSHiroo HAYASHI	    def->useCork = CORK_QUEUE;
1708fc51ccaSHiroo HAYASHI	    return def;
1718fc51ccaSHiroo HAYASHI    }
1728fc51ccaSHiroo HAYASHI
1738fc51ccaSHiroo HAYASHIWhen ctags running a parser with ``useCork`` being ``CORK_QUEUE``, all output
1748fc51ccaSHiroo HAYASHIrequested via ``makeTagEntry`` function calling is stored to an internal
1758fc51ccaSHiroo HAYASHIqueue, not to ``tags`` file.  When parsing an input file is done, the
1768fc51ccaSHiroo HAYASHItag information stored automatically to the queue are flushed to
1778fc51ccaSHiroo HAYASHI``tags`` file in batch.
1788fc51ccaSHiroo HAYASHI
1798fc51ccaSHiroo HAYASHIWhen calling ``makeTagEntry`` with a ``tagEntryInfo`` object (``parent``),
1808fc51ccaSHiroo HAYASHIit returns an integer. The integer can be used as handle for referring
1818fc51ccaSHiroo HAYASHIthe object after calling.
1828fc51ccaSHiroo HAYASHI
1838fc51ccaSHiroo HAYASHI
1848fc51ccaSHiroo HAYASHI.. code-block:: c
1858fc51ccaSHiroo HAYASHI
18624f34239SMasatake YAMATO		int parent = CORK_NIL;
1878fc51ccaSHiroo HAYASHI		...
1888fc51ccaSHiroo HAYASHI		parent = makeTagEntry (&e);
1898fc51ccaSHiroo HAYASHI
1908fc51ccaSHiroo HAYASHIThe handle can be used by setting to a ``scopeIndex``
1918fc51ccaSHiroo HAYASHIfield of ``current`` tag, which is in the scope of ``parent``.
1928fc51ccaSHiroo HAYASHI
1938fc51ccaSHiroo HAYASHI.. code-block:: c
1948fc51ccaSHiroo HAYASHI
1958fc51ccaSHiroo HAYASHI		current.extensionFields.scopeIndex = parent;
1968fc51ccaSHiroo HAYASHI
1978fc51ccaSHiroo HAYASHIWhen passing ``current`` to ``makeTagEntry``, the ``scopeIndex`` is
1988fc51ccaSHiroo HAYASHIreferred for emitting the scope information of ``current``.
1998fc51ccaSHiroo HAYASHI
2008fc51ccaSHiroo HAYASHI``scopeIndex`` must be set to ``CORK_NIL`` if a tag is not in any scope.
2018fc51ccaSHiroo HAYASHIWhen using ``scopeIndex`` of ``current``, ``NULL`` must be assigned to both
2028fc51ccaSHiroo HAYASHI``current.extensionFields.scope[0]`` and
2038fc51ccaSHiroo HAYASHI``current.extensionFields.scope[1]``.  ``initTagEntry`` function does this
2048fc51ccaSHiroo HAYASHIinitialization internally, so you generally you don't have to write
2058fc51ccaSHiroo HAYASHIthe initialization explicitly.
2068fc51ccaSHiroo HAYASHI
2078fc51ccaSHiroo HAYASHIAutomatic full qualified tag generation
208b45a42b3SHiroo HAYASHI^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2098fc51ccaSHiroo HAYASHI
2108fc51ccaSHiroo HAYASHIIf a parser uses the cork API for recording and emitting scope
2118fc51ccaSHiroo HAYASHIinformation, ctags can reuse it for generating *full qualified (FQ)
2128fc51ccaSHiroo HAYASHItags*. Set ``requestAutomaticFQTag`` field of ``parserDefinition`` to
2138fc51ccaSHiroo HAYASHI``TRUE`` then the main part of ctags emits FQ tags on behalf of the parser
2148fc51ccaSHiroo HAYASHIif ``--extras=+q`` is given.
2158fc51ccaSHiroo HAYASHI
2168fc51ccaSHiroo HAYASHIAn example can be found in DTS parser:
2178fc51ccaSHiroo HAYASHI
2188fc51ccaSHiroo HAYASHI.. code-block:: c
2198fc51ccaSHiroo HAYASHI
2208fc51ccaSHiroo HAYASHI    extern parserDefinition* DTSParser (void)
2218fc51ccaSHiroo HAYASHI    {
2228fc51ccaSHiroo HAYASHI	    static const char *const extensions [] = { "dts", "dtsi", NULL };
2238fc51ccaSHiroo HAYASHI	    parserDefinition* const def = parserNew ("DTS");
2248fc51ccaSHiroo HAYASHI	    ...
2258fc51ccaSHiroo HAYASHI	    def->requestAutomaticFQTag = TRUE;
2268fc51ccaSHiroo HAYASHI	    return def;
2278fc51ccaSHiroo HAYASHI    }
2288fc51ccaSHiroo HAYASHI
2298fc51ccaSHiroo HAYASHISetting ``requestAutomaticFQTag`` to ``TRUE`` implies setting
2308fc51ccaSHiroo HAYASHI``useCork`` to ``CORK_QUEUE``.
2318fc51ccaSHiroo HAYASHI
2328fc51ccaSHiroo HAYASHI.. NOT REVIEWED YET
2338fc51ccaSHiroo HAYASHI
2344998477cSMasatake YAMATO.. _symtabAPI:
2354998477cSMasatake YAMATO
2364998477cSMasatake YAMATOsymbol table API
2374998477cSMasatake YAMATO^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2384998477cSMasatake YAMATO
2394998477cSMasatake YAMATO*symbol table* API is an extension to the cork API. The cork API was
2404998477cSMasatake YAMATOintroduced to provide the simple way to represent mapping (*forward
2414998477cSMasatake YAMATOmapping*) from a language object (*child object*) to its upper scope
2424998477cSMasatake YAMATO(*parent object*). *symbol table* API is for representing the mapping
2434998477cSMasatake YAMATO(*reverse mapping*) opposite direction; you can look up (or traverse)
2444998477cSMasatake YAMATOchild tags defined (or used) in a given tag.
2454998477cSMasatake YAMATO
2464998477cSMasatake YAMATOTo use this API, a parser must set ``CORK_SYMTAB`` to ``useCork`` member
2474998477cSMasatake YAMATOof ``parserDefinition`` in addition to setting ``CORK_QUEUE`` as preparation.
2484998477cSMasatake YAMATO
2494998477cSMasatake YAMATOAn example taken from R parser:
2504998477cSMasatake YAMATO
2514998477cSMasatake YAMATO.. code-block:: c
2524998477cSMasatake YAMATO
2534998477cSMasatake YAMATO	extern parserDefinition *RParser (void)
2544998477cSMasatake YAMATO	{
2554998477cSMasatake YAMATO		static const char *const extensions[] = { "r", "R", "s", "q", NULL };
2564998477cSMasatake YAMATO		parserDefinition *const def = parserNew ("R");
2574998477cSMasatake YAMATO
2584998477cSMasatake YAMATO		...
2594998477cSMasatake YAMATO
2604998477cSMasatake YAMATO		def->useCork = CORK_QUEUE | CORK_SYMTAB;
2614998477cSMasatake YAMATO
2624998477cSMasatake YAMATO		...
2634998477cSMasatake YAMATO
2644998477cSMasatake YAMATO		return def;
2654998477cSMasatake YAMATO	}
2664998477cSMasatake YAMATO
2674998477cSMasatake YAMATO
2684998477cSMasatake YAMATOTo install a reverse mapping between a parent and its child tags,
2694998477cSMasatake YAMATOcall ``registerEntry`` with the cork index for a child after making
2704998477cSMasatake YAMATOthe child tag filling ``scopeIndex``:
2714998477cSMasatake YAMATO
2724998477cSMasatake YAMATO.. code-block:: c
2734998477cSMasatake YAMATO
2744998477cSMasatake YAMATO	int parent = CORK_NIL;
2754998477cSMasatake YAMATO	...
2764998477cSMasatake YAMATO	parent = makeTagEntry (&e_parent);
2774998477cSMasatake YAMATO
2784998477cSMasatake YAMATO	...
2794998477cSMasatake YAMATO
2804998477cSMasatake YAMATO	tagEntryInfo e_child;
2814998477cSMasatake YAMATO	...
2824998477cSMasatake YAMATO	initTagEntry (&e_child, ...);
2834998477cSMasatake YAMATO	e_child.extensionFields.scopeIndex = parent;    /* setting up forward mapping */
2844998477cSMasatake YAMATO	...
2854998477cSMasatake YAMATO	int child = makeTagEntry (&e_child);
2864998477cSMasatake YAMATO
2874998477cSMasatake YAMATO	registerEntry (child);                          /* setting up reverse mapping */
2884998477cSMasatake YAMATO
2894998477cSMasatake YAMATO``registerEntry`` stores ``child`` to the symbol table of ``parent``.
2904998477cSMasatake YAMATOIf ``scopeIndex`` of ``child`` is ``CORK_NIL``, the ``child`` is stores
2914998477cSMasatake YAMATOto the *toplevel scope*.
2924998477cSMasatake YAMATO
293fe516ceeSMasatake YAMATO``unregisterEntry`` is for clearing (and updating) the reverse mapping
294fe516ceeSMasatake YAMATOof a child. Consider the case you want to change the scope of ``child``
295fe516ceeSMasatake YAMATOfrom ``newParent``.
296fe516ceeSMasatake YAMATO
297fe516ceeSMasatake YAMATO.. code-block:: c
298fe516ceeSMasatake YAMATO
299fe516ceeSMasatake YAMATO	unregisterEntry (child);                         /* delete the reverse mapping. */
300fe516ceeSMasatake YAMATO	tagEntryInfo *e_child = getEntryInCorkQueue (child);
301fe516ceeSMasatake YAMATO	e_child->extensionFields.scopeIndex = newParent; /* update the forward mapping. */
302fe516ceeSMasatake YAMATO	registerEntry (child);                           /* set the new reverse mapping. */
303fe516ceeSMasatake YAMATO
3044998477cSMasatake YAMATO``foreachEntriesInScope`` is the function for traversing all child
3054998477cSMasatake YAMATOtags stored to the parent tag specified with ``corkIndex``.
3064998477cSMasatake YAMATOIf the ``corkIndex`` is ``CORK_NIL``, the children defined (and/or
3074998477cSMasatake YAMATOused) in *toplevel scope*  are traversed.
3084998477cSMasatake YAMATO
3094998477cSMasatake YAMATO.. code-block:: c
3104998477cSMasatake YAMATO
3114998477cSMasatake YAMATO	typedef bool (* entryForeachFunc) (int corkIndex,
3124998477cSMasatake YAMATO									   tagEntryInfo * entry,
3134998477cSMasatake YAMATO									   void * data);
3144998477cSMasatake YAMATO	bool          foreachEntriesInScope (int corkIndex,
3154998477cSMasatake YAMATO										 const char *name, /* or NULL */
3164998477cSMasatake YAMATO										 entryForeachFunc func,
3174998477cSMasatake YAMATO										 void *data);
3184998477cSMasatake YAMATO
3194998477cSMasatake YAMATO``foreachEntriesInScope``  takes a ``foreachEntriesInScope`` typed
3204998477cSMasatake YAMATOcallback function.  ``foreachEntriesInScope`` passes the cork
3214998477cSMasatake YAMATOindex and a pointer for ``tagEntryInfo`` object of children.
3224998477cSMasatake YAMATO
3234998477cSMasatake YAMATO`anyEntryInScope` is a function for finding a child tag stored
3244998477cSMasatake YAMATOto the parent tag specified with ``corkIndex``. It returns
3254998477cSMasatake YAMATOthe cork index for the child tag. If ``corkIndex`` is ``CORK_NIL``,
3264998477cSMasatake YAMATO`anyEntryInScope` finds a tag stored to the toplevel scope.
3274998477cSMasatake YAMATOThe returned child tag has ``name`` as its name as far as ``name``
3284998477cSMasatake YAMATOis not ``NULL``.
3294998477cSMasatake YAMATO
3304998477cSMasatake YAMATO.. code-block:: c
3314998477cSMasatake YAMATO
3324998477cSMasatake YAMATO	int           anyEntryInScope       (int corkIndex,
333*aaaac7eeSMasatake YAMATO										 const char *name,
334*aaaac7eeSMasatake YAMATO										 bool onlyDefinitionTag);
3354998477cSMasatake YAMATO
3364998477cSMasatake YAMATO
3378fc51ccaSHiroo HAYASHI.. _tokeninfo:
3388fc51ccaSHiroo HAYASHI
3398fc51ccaSHiroo HAYASHItokenInfo API
3408fc51ccaSHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3418fc51ccaSHiroo HAYASHI
3428fc51ccaSHiroo HAYASHIIn Exuberant Ctags, a developer can write a parser anyway; only input
3438fc51ccaSHiroo HAYASHIstream and tagEntryInfo data structure is given.
3448fc51ccaSHiroo HAYASHI
3458fc51ccaSHiroo HAYASHIHowever, while maintaining Universal Ctags I (Masatake YAMATO) think
3468fc51ccaSHiroo HAYASHIwe should have a framework for writing parser. Of course the framework
3478fc51ccaSHiroo HAYASHIis optional; you can still write a parser without the framework.
3488fc51ccaSHiroo HAYASHI
3498fc51ccaSHiroo HAYASHITo design a framework, I have studied how @b4n (Colomban Wendling)
3508fc51ccaSHiroo HAYASHIwrites parsers. tokenInfo API is the first fruit of my study.
3518fc51ccaSHiroo HAYASHI
3528fc51ccaSHiroo HAYASHITBW
3538fc51ccaSHiroo HAYASHI
3548fc51ccaSHiroo HAYASHIMultiple parsers
3558fc51ccaSHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
356bde94b5aSMasatake YAMATO
35774db2c55SMasatake YAMATO.. _promiseAPI:
35874db2c55SMasatake YAMATO
359b45a42b3SHiroo HAYASHIGuest parser (promise API)
360338e986cSMasatake YAMATO......................................................................
361b45a42b3SHiroo HAYASHI
362b45a42b3SHiroo HAYASHISee ":ref:`host-guest-parsers`" about the concept of guest parsers.
363338e986cSMasatake YAMATO
364338e986cSMasatake YAMATOBackground and Idea
365b45a42b3SHiroo HAYASHI^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
366338e986cSMasatake YAMATOMore than one programming languages can be used in one input text stream.
367b45a42b3SHiroo HAYASHI*promise API* allows a host parser running a :ref:`guest parser
368b45a42b3SHiroo HAYASHI<host-guest-parsers>` in the specified area of input text stream.
369338e986cSMasatake YAMATO
370338e986cSMasatake YAMATOe.g. Code written in c language (C code) is embedded
371338e986cSMasatake YAMATOin code written in Yacc language (Yacc code). Let's think about this
372338e986cSMasatake YAMATOinput stream.
373338e986cSMasatake YAMATO
374338e986cSMasatake YAMATO.. code-block:: yacc
375338e986cSMasatake YAMATO
376338e986cSMasatake YAMATO   /* foo.y */
377338e986cSMasatake YAMATO    %token
378338e986cSMasatake YAMATO	    END_OF_FILE	0
379338e986cSMasatake YAMATO	    ERROR		255
380338e986cSMasatake YAMATO	    BELL		1
381338e986cSMasatake YAMATO
382338e986cSMasatake YAMATO    %{
383338e986cSMasatake YAMATO    /* C language */
384338e986cSMasatake YAMATO    int counter;
385338e986cSMasatake YAMATO    %}
386338e986cSMasatake YAMATO    %right	EQUALS
387338e986cSMasatake YAMATO    %left	PLUS MINUS
388338e986cSMasatake YAMATO    ...
389338e986cSMasatake YAMATO    %%
390338e986cSMasatake YAMATO    CfgFile		:	CfgEntryList
391338e986cSMasatake YAMATO			    { InterpretConfigs($1); }
392338e986cSMasatake YAMATO		    ;
393338e986cSMasatake YAMATO
394338e986cSMasatake YAMATO    ...
395338e986cSMasatake YAMATO    %%
396338e986cSMasatake YAMATO    int
397338e986cSMasatake YAMATO    yyerror(char *s)
398338e986cSMasatake YAMATO    {
399338e986cSMasatake YAMATO	(void)fprintf(stderr,"%s: line %d of %s\n",s,lineNum,
400338e986cSMasatake YAMATO					    (scanFile?scanFile:"(unknown)"));
401338e986cSMasatake YAMATO	if (scanStr)
402338e986cSMasatake YAMATO	    (void)fprintf(stderr,"last scanned symbol is: %s\n",scanStr);
403338e986cSMasatake YAMATO	return 1;
404338e986cSMasatake YAMATO    }
405338e986cSMasatake YAMATO
40686bcb5c2SHiroo HAYASHIIn the input the area started from ``%{`` to ``%}`` and the area started from
40786bcb5c2SHiroo HAYASHIthe second ``%%`` to the end of file are written in C. Yacc can be called
40886bcb5c2SHiroo HAYASHI*host language*, and C can be called *guest language*.
409338e986cSMasatake YAMATO
410338e986cSMasatake YAMATOCtags may choose the Yacc parser for the input. However, the parser
411338e986cSMasatake YAMATOdoesn't know about C syntax. Implementing C parser in the Yacc parser
412338e986cSMasatake YAMATOis one of approach. However, ctags has already C parser.  The Yacc
413338e986cSMasatake YAMATOparser should utilize the existing C parser. The promise API allows this.
414338e986cSMasatake YAMATO
415b45a42b3SHiroo HAYASHISee also ":ref:`host-guest-parsers`" about more concept and examples of the
416b45a42b3SHiroo HAYASHIguest parser.
41774db2c55SMasatake YAMATO
418338e986cSMasatake YAMATOUsage
419b45a42b3SHiroo HAYASHI^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
420338e986cSMasatake YAMATO
4213cd8570eSHiroo HAYASHISee a commit titled with "`Yacc: run C parser in the areas where code
4223cd8570eSHiroo HAYASHIis written in C <https://github.com/universal-ctags/ctags/commit/757673f>`_".
4233cd8570eSHiroo HAYASHII applied promise API to the Yacc parser.
424338e986cSMasatake YAMATO
42586bcb5c2SHiroo HAYASHIThe parser for host language must track and record the ``start`` and the
42686bcb5c2SHiroo HAYASHI``end`` of a guest language. Pairs of ``line number`` and ``byte offset``
42786bcb5c2SHiroo HAYASHIrepresents the ``start`` and ``end``. When the ``start`` and ``end`` are
42886bcb5c2SHiroo HAYASHIfixed, call ``makePromise`` with (1) the guest parser name, (2) ``start``,
42986bcb5c2SHiroo HAYASHIand (3) ``end``. (This description is a bit simplified the real usage.)
430338e986cSMasatake YAMATO
431338e986cSMasatake YAMATO
432b45a42b3SHiroo HAYASHILet's see the actual code from "`parsers/yacc.c
433b45a42b3SHiroo HAYASHI<https://github.com/universal-ctags/ctags/blob/master/parsers/yacc.c>`_".
434338e986cSMasatake YAMATO
435338e986cSMasatake YAMATO.. code-block:: c
436338e986cSMasatake YAMATO
437338e986cSMasatake YAMATO	struct cStart {
438338e986cSMasatake YAMATO		unsigned long input;
439338e986cSMasatake YAMATO		unsigned long source;
440338e986cSMasatake YAMATO	};
441338e986cSMasatake YAMATO
44286bcb5c2SHiroo HAYASHIBoth fields are for recording ``start``. ``input`` field
44386bcb5c2SHiroo HAYASHIis for recording the value returned from ``getInputLineNumber``.
44486bcb5c2SHiroo HAYASHI``source`` is for ``getSourceLineNumber``. See "`inputFile`_" for the
445338e986cSMasatake YAMATOdifference of the two.
446338e986cSMasatake YAMATO
44786bcb5c2SHiroo HAYASHI``enter_c_prologue`` shown in the next is a function called when ``%{`` is
44886bcb5c2SHiroo HAYASHIfound in the current input text stream. Remember, in yacc syntax, ``%{``
449338e986cSMasatake YAMATOis a marker of C code area.
450338e986cSMasatake YAMATO
451338e986cSMasatake YAMATO.. code-block:: c
452338e986cSMasatake YAMATO
4538ccb7ee9SJiří Techet    static void enter_c_prologue (const char *line CTAGS_ATTR_UNUSED,
4548ccb7ee9SJiří Techet				 const regexMatch *matches CTAGS_ATTR_UNUSED,
4558ccb7ee9SJiří Techet				 unsigned int count CTAGS_ATTR_UNUSED,
456338e986cSMasatake YAMATO				 void *data)
457338e986cSMasatake YAMATO    {
458338e986cSMasatake YAMATO	   struct cStart *cstart = data;
459338e986cSMasatake YAMATO
460338e986cSMasatake YAMATO
461338e986cSMasatake YAMATO	   readLineFromInputFile ();
462338e986cSMasatake YAMATO	   cstart->input  = getInputLineNumber ();
463338e986cSMasatake YAMATO	   cstart->source = getSourceLineNumber ();
464338e986cSMasatake YAMATO    }
465338e986cSMasatake YAMATO
466338e986cSMasatake YAMATO
467338e986cSMasatake YAMATOThe function just records the start line.  It calls
46886bcb5c2SHiroo HAYASHI``readLineFromInputFile`` because the C code may start the next line of
469338e986cSMasatake YAMATOthe line where the marker is.
470338e986cSMasatake YAMATO
47186bcb5c2SHiroo HAYASHI``leave_c_prologue`` shown in the next is a function called when ``%}``,
47286bcb5c2SHiroo HAYASHIthe end marker of C code area, is found in the current input text stream.
473338e986cSMasatake YAMATO
474338e986cSMasatake YAMATO.. code-block:: c
475338e986cSMasatake YAMATO
4768ccb7ee9SJiří Techet    static void leave_c_prologue (const char *line CTAGS_ATTR_UNUSED,
4778ccb7ee9SJiří Techet				 const regexMatch *matches CTAGS_ATTR_UNUSED,
4788ccb7ee9SJiří Techet				 unsigned int count CTAGS_ATTR_UNUSED,
479338e986cSMasatake YAMATO				 void *data)
480338e986cSMasatake YAMATO    {
481338e986cSMasatake YAMATO	   struct cStart *cstart = data;
482338e986cSMasatake YAMATO	   unsigned long c_end;
483338e986cSMasatake YAMATO
484338e986cSMasatake YAMATO	   c_end = getInputLineNumber ();
485338e986cSMasatake YAMATO	   makePromise ("C", cstart->input, 0, c_end, 0, cstart->source);
486338e986cSMasatake YAMATO    }
487338e986cSMasatake YAMATO
488338e986cSMasatake YAMATOAfter recording the line number of the end of the C code area,
48986bcb5c2SHiroo HAYASHI``leave_c_prologue`` calls ``makePromise``.
490338e986cSMasatake YAMATO
49186bcb5c2SHiroo HAYASHIOf course ``"C"`` stands for C language, the name of guest parser.
492338e986cSMasatake YAMATOAvailable parser names can be listed by running ctags with
49386bcb5c2SHiroo HAYASHI``--list-languages`` option. In this example two ``0`` characters are provided as
49495805397SJiří Techetthe 3rd and 5th argument. They are byte offsets of the start and the end of the
49595805397SJiří TechetC language area from the beginning of the line which is 0 in this case. In
49695805397SJiří Techetgeneral, the guest language's section does not have to start at the beginning of
49795805397SJiří Techetthe line in which case the two offsets have to be provided. Compilers reading
49895805397SJiří Techetthe input character by character can obtain the current offset by calling
49986bcb5c2SHiroo HAYASHI``getInputLineOffset()``.
500338e986cSMasatake YAMATO
501338e986cSMasatake YAMATOInternal design
502b45a42b3SHiroo HAYASHI^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
503338e986cSMasatake YAMATO
5047c0944ebSMasatake YAMATO.. figure:: promise.svg
5057c0944ebSMasatake YAMATO	    :scale: 80%
5067c0944ebSMasatake YAMATO
507338e986cSMasatake YAMATOA host parser cannot run a guest parser directly. What the host parser
508338e986cSMasatake YAMATOcan do is just asking the ctags main part scheduling of running the
50986bcb5c2SHiroo HAYASHIguest parser for specified area which defined with the ``start`` and
51086bcb5c2SHiroo HAYASHI``end``. These scheduling requests are called *promises*.
511338e986cSMasatake YAMATO
512338e986cSMasatake YAMATOAfter running the host parser, before closing the input stream, the
513338e986cSMasatake YAMATOctags main part checks the existence of promise(s). If there is, the
514338e986cSMasatake YAMATOmain part makes a sub input stream and run the guest parser specified
515338e986cSMasatake YAMATOin the promise. The sub input stream is made from the original input
516338e986cSMasatake YAMATOstream by narrowing as requested in the promise. The main part
517338e986cSMasatake YAMATOiterates the above process till there is no promise.
518338e986cSMasatake YAMATO
519326d42b3SMasatake YAMATOTheoretically a guest parser can be nested; it can make a promise.
520326d42b3SMasatake YAMATOThe level 2 guest is also just scheduled. (However, I have never
521326d42b3SMasatake YAMATOtested such a nested guest parser).
522338e986cSMasatake YAMATO
523338e986cSMasatake YAMATOWhy not running the guest parser directly from the context of the host
524338e986cSMasatake YAMATOparser? Remember many parsers have their own file static variables. If
525338e986cSMasatake YAMATOa parser is called from the parser, the variables may be crashed.
526338e986cSMasatake YAMATO
527b45a42b3SHiroo HAYASHIAPI for subparser
528c905c114SMasatake YAMATO......................................................................
529c905c114SMasatake YAMATO
530b45a42b3SHiroo HAYASHISee ":ref:`base-sub-parsers`" about the concept of subparser.
531b45a42b3SHiroo HAYASHI
532b45a42b3SHiroo HAYASHI.. note:: Consider using optlib when implementing a subparser. It is much more
533b45a42b3SHiroo HAYASHI	easy and simple. See ":ref:`defining-subparsers`" for details.
534b45a42b3SHiroo HAYASHI
5358fc51ccaSHiroo HAYASHIOutline
536b45a42b3SHiroo HAYASHI^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
537c905c114SMasatake YAMATO
5388fc51ccaSHiroo HAYASHIYou have to work on both sides: a base parser and subparsers.
539c905c114SMasatake YAMATO
5408fc51ccaSHiroo HAYASHIA base parser must define a data structure type (``baseMethodTable``) for
5418fc51ccaSHiroo HAYASHIits subparsers by extending ``struct subparser`` defined in
5428fc51ccaSHiroo HAYASHI``main/subparser.h``.  A subparser defines a variable (``subparser var``)
5438fc51ccaSHiroo HAYASHIhaving type ``baseMethodTable`` by filling its fields and registers
5448fc51ccaSHiroo HAYASHI``subparser var`` to the base parser using dependency API.
545c905c114SMasatake YAMATO
5468fc51ccaSHiroo HAYASHIThe base parser calls functions pointed by ``baseMethodTable`` of
5478fc51ccaSHiroo HAYASHIsubparsers during parsing. A function for probing a higher level
5488fc51ccaSHiroo HAYASHIlanguage may be included in ``baseMethodTable``.  What kind of fields
5498fc51ccaSHiroo HAYASHIshould be included in ``baseMethodTable`` is up to the design of a base
5508fc51ccaSHiroo HAYASHIparser and the requirements of its subparsers. A method for
5518fc51ccaSHiroo HAYASHIprobing is one of them.
552c905c114SMasatake YAMATO
5538fc51ccaSHiroo HAYASHIRegistering a ``subparser var`` to a base parser is enough for the
5548fc51ccaSHiroo HAYASHIbottom up choice. For handling the top down choice (e.g. specifying
5558fc51ccaSHiroo HAYASHI``--language-force=<subparser>`` in a command line), more code is needed.
556c905c114SMasatake YAMATO
5578fc51ccaSHiroo HAYASHIIn the top down choice, the subparser must call ``scheduleRunningBasepaser``,
5588fc51ccaSHiroo HAYASHIdeclared in ``main/subparser.h``, in its ``parser`` method.
5598fc51ccaSHiroo HAYASHIHere, ``parser`` method means a function assigned to the ``parser`` member of
5608fc51ccaSHiroo HAYASHIthe ``parserDefinition`` of the subparser.
5618fc51ccaSHiroo HAYASHI``scheduleRunningBaseparser`` takes an integer argument
5628fc51ccaSHiroo HAYASHIthat specifies the dependency used for registering the ``subparser var``.
5635ab497a3SMasatake YAMATO
5648fc51ccaSHiroo HAYASHIBy extending ``struct subparser`` you can define a type for
5658fc51ccaSHiroo HAYASHIyour subparser. Then make a variable for the type and
5668fc51ccaSHiroo HAYASHIdeclare a dependency on the base parser.
5675ab497a3SMasatake YAMATO
5688fc51ccaSHiroo HAYASHIFields of ``subparser`` type
569b45a42b3SHiroo HAYASHI^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5705ab497a3SMasatake YAMATO
5718fc51ccaSHiroo HAYASHIHere the source code of Autoconf/m4 parsers is referred as an example.
5725ab497a3SMasatake YAMATO
5738fc51ccaSHiroo HAYASHI``main/types.h``:
5745ab497a3SMasatake YAMATO
5758fc51ccaSHiroo HAYASHI.. code-block:: C
5765ab497a3SMasatake YAMATO
5778fc51ccaSHiroo HAYASHI    struct sSubparser;
5788fc51ccaSHiroo HAYASHI    typedef struct sSubparser subparser;
5795ab497a3SMasatake YAMATO
5805ab497a3SMasatake YAMATO
5818fc51ccaSHiroo HAYASHI``main/subparser.h``:
5828fc51ccaSHiroo HAYASHI
5838fc51ccaSHiroo HAYASHI.. code-block:: C
5848fc51ccaSHiroo HAYASHI
5858fc51ccaSHiroo HAYASHI    typedef enum eSubparserRunDirection {
5868fc51ccaSHiroo HAYASHI	    SUBPARSER_BASE_RUNS_SUB = 1 << 0,
5878fc51ccaSHiroo HAYASHI	    SUBPARSER_SUB_RUNS_BASE = 1 << 1,
5888fc51ccaSHiroo HAYASHI	    SUBPARSER_BI_DIRECTION  = SUBPARSER_BASE_RUNS_SUB|SUBPARSER_SUB_RUNS_BASE,
5898fc51ccaSHiroo HAYASHI    } subparserRunDirection;
5908fc51ccaSHiroo HAYASHI
5918fc51ccaSHiroo HAYASHI    struct sSubparser {
5928fc51ccaSHiroo HAYASHI	    ...
5938fc51ccaSHiroo HAYASHI
5948fc51ccaSHiroo HAYASHI	    /* public to the parser */
5958fc51ccaSHiroo HAYASHI	    subparserRunDirection direction;
5968fc51ccaSHiroo HAYASHI
5978fc51ccaSHiroo HAYASHI	    void (* inputStart) (subparser *s);
5988fc51ccaSHiroo HAYASHI	    void (* inputEnd) (subparser *s);
5998fc51ccaSHiroo HAYASHI	    void (* exclusiveSubparserChosenNotify) (subparser *s, void *data);
6008fc51ccaSHiroo HAYASHI    };
6018fc51ccaSHiroo HAYASHI
6028fc51ccaSHiroo HAYASHIA subparser must fill the fields of ``subparser``.
6038fc51ccaSHiroo HAYASHI
604eb56edb2SHiroo HAYASHI``direction`` field specifies how the subparser is called. See
605eb56edb2SHiroo HAYASHI":ref:`multiple_parsers_directions`" in ":ref:`multiple_parsers`" about
606eb56edb2SHiroo HAYASHI*direction flags*, and see ":ref:`optlib_directions`" in ":ref:`optlib`" for
607eb56edb2SHiroo HAYASHIexamples of using the direction flags.
608eb56edb2SHiroo HAYASHI
609eb56edb2SHiroo HAYASHI===========================  ======================
610eb56edb2SHiroo HAYASHI``direction`` field          Direction Flag
611eb56edb2SHiroo HAYASHI===========================  ======================
612eb56edb2SHiroo HAYASHI``SUBPARSER_BASE_RUNS_SUB``  ``shared`` (default)
613eb56edb2SHiroo HAYASHI``SUBPARSER_SUB_RUNS_BASE``  ``dedicated``
614eb56edb2SHiroo HAYASHI``SUBPARSER_BI_DIRECTION``   ``bidirectional``
615eb56edb2SHiroo HAYASHI===========================  ======================
616eb56edb2SHiroo HAYASHI
617eb56edb2SHiroo HAYASHIIf a subparser runs exclusively and is chosen in top down way, set
6188fc51ccaSHiroo HAYASHI``SUBPARSER_SUB_RUNS_BASE`` flag. If a subparser runs coexisting way and
6198fc51ccaSHiroo HAYASHIis chosen in bottom up way, set ``SUBPARSER_BASE_RUNS_SUB``.  Use
6208fc51ccaSHiroo HAYASHI``SUBPARSER_BI_DIRECTION`` if both cases can be considered.
6218fc51ccaSHiroo HAYASHI
6228fc51ccaSHiroo HAYASHISystemdUnit parser runs as a subparser of iniconf base parser.
6238fc51ccaSHiroo HAYASHISystemdUnit parser specifies ``SUBPARSER_SUB_RUNS_BASE`` because
6248fc51ccaSHiroo HAYASHIunit files of systemd have very specific file extensions though
6258fc51ccaSHiroo HAYASHIthey are written in iniconf syntax. Therefore we expect SystemdUnit
6268fc51ccaSHiroo HAYASHIparser is chosen in top down way. The same logic is applicable to
6278fc51ccaSHiroo HAYASHIYumRepo parser.
6288fc51ccaSHiroo HAYASHI
6298fc51ccaSHiroo HAYASHIAutoconf parser specifies ``SUBPARSER_BI_DIRECTION``. For input
6308fc51ccaSHiroo HAYASHIfile having name ``configure.ac``, by pattern matching, Autoconf parser
6318fc51ccaSHiroo HAYASHIis chosen in top down way. In other hand, for file name ``foo.m4``,
6328fc51ccaSHiroo HAYASHIAutoconf parser can be chosen in bottom up way.
6338fc51ccaSHiroo HAYASHI
6348fc51ccaSHiroo HAYASHI.. TODO: Write about SUBPARSER_BASE_RUNS_SUB after implementing python-celery.
6358fc51ccaSHiroo HAYASHI
6368fc51ccaSHiroo HAYASHI``inputStart`` is called before the base parser starting parsing a new input file.
6378fc51ccaSHiroo HAYASHI``inputEnd`` is called after the base parser finishing parsing the input file.
6388fc51ccaSHiroo HAYASHIUniversal Ctags main part calls these methods. Therefore, a base parser doesn't
6398fc51ccaSHiroo HAYASHIhave to call them.
6408fc51ccaSHiroo HAYASHI
6418fc51ccaSHiroo HAYASHI``exclusiveSubparserChosenNotify`` is called when a parser is chosen
6428fc51ccaSHiroo HAYASHIas an exclusive parser. Calling this method is a job of a base parser.
6438fc51ccaSHiroo HAYASHI
6448fc51ccaSHiroo HAYASHI
6458fc51ccaSHiroo HAYASHIExtending ``subparser`` type
646b45a42b3SHiroo HAYASHI^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6478fc51ccaSHiroo HAYASHI
6488fc51ccaSHiroo HAYASHIThe m4 parser extends ``subparser`` type like following:
6498fc51ccaSHiroo HAYASHI
6508fc51ccaSHiroo HAYASHI``parsers/m4.h``:
6518fc51ccaSHiroo HAYASHI
6528fc51ccaSHiroo HAYASHI.. code-block:: C
6538fc51ccaSHiroo HAYASHI
6548fc51ccaSHiroo HAYASHI    typedef struct sM4Subparser m4Subparser;
6558fc51ccaSHiroo HAYASHI    struct sM4Subparser {
6568fc51ccaSHiroo HAYASHI	    subparser subparser;
6578fc51ccaSHiroo HAYASHI
6588fc51ccaSHiroo HAYASHI	    bool (* probeLanguage) (m4Subparser *m4, const char* token);
6598fc51ccaSHiroo HAYASHI
6608fc51ccaSHiroo HAYASHI	    /* return value: Cork index */
6618fc51ccaSHiroo HAYASHI	    int  (* newMacroNotify) (m4Subparser *m4, const char* token);
6628fc51ccaSHiroo HAYASHI
6638fc51ccaSHiroo HAYASHI	    bool (* doesLineCommentStart)   (m4Subparser *m4, int c, const char *token);
6648fc51ccaSHiroo HAYASHI	    bool (* doesStringLiteralStart) (m4Subparser *m4, int c);
6658fc51ccaSHiroo HAYASHI    };
6668fc51ccaSHiroo HAYASHI
6678fc51ccaSHiroo HAYASHI
6688fc51ccaSHiroo HAYASHIPut ``subparser`` as the first member of the extended struct (here sM4Subparser).
6698fc51ccaSHiroo HAYASHIIn addition the first field, 4 methods are defined in the extended struct.
6708fc51ccaSHiroo HAYASHI
6718fc51ccaSHiroo HAYASHITill choosing a subparser for the current input file, the m4 parser calls
6728fc51ccaSHiroo HAYASHI``probeLanguage`` method of its subparsers each time when find a token
6738fc51ccaSHiroo HAYASHIin the input file. A subparser returns ``true`` if it recognizes the
6748fc51ccaSHiroo HAYASHIinput file is for the itself by analyzing tokens passed from the
6758fc51ccaSHiroo HAYASHIbase parser.
6768fc51ccaSHiroo HAYASHI
6778fc51ccaSHiroo HAYASHI``parsers/autoconf.c``:
6788fc51ccaSHiroo HAYASHI
6798fc51ccaSHiroo HAYASHI.. code-block:: C
6808fc51ccaSHiroo HAYASHI
6818fc51ccaSHiroo HAYASHI    extern parserDefinition* AutoconfParser (void)
6825ab497a3SMasatake YAMATO    {
6838fc51ccaSHiroo HAYASHI	    static const char *const patterns [] = { "configure.in", NULL };
6848fc51ccaSHiroo HAYASHI	    static const char *const extensions [] = { "ac", NULL };
6858fc51ccaSHiroo HAYASHI	    parserDefinition* const def = parserNew("Autoconf");
6868fc51ccaSHiroo HAYASHI
6878fc51ccaSHiroo HAYASHI	    static m4Subparser autoconfSubparser = {
6888fc51ccaSHiroo HAYASHI		    .subparser = {
6898fc51ccaSHiroo HAYASHI			    .direction = SUBPARSER_BI_DIRECTION,
6908fc51ccaSHiroo HAYASHI			    .exclusiveSubparserChosenNotify = exclusiveSubparserChosenCallback,
6918fc51ccaSHiroo HAYASHI		    },
6928fc51ccaSHiroo HAYASHI		    .probeLanguage  = probeLanguage,
6938fc51ccaSHiroo HAYASHI		    .newMacroNotify = newMacroCallback,
6948fc51ccaSHiroo HAYASHI		    .doesLineCommentStart = doesLineCommentStart,
6958fc51ccaSHiroo HAYASHI		    .doesStringLiteralStart = doesStringLiteralStart,
6968fc51ccaSHiroo HAYASHI	    };
6978fc51ccaSHiroo HAYASHI
6988fc51ccaSHiroo HAYASHI``probeLanguage`` function defined in ``autoconf.c`` is connected to
6998fc51ccaSHiroo HAYASHIthe ``probeLanguage`` member of ``autoconfSubparser``. The ``probeLanguage`` function
7008fc51ccaSHiroo HAYASHIof Autoconf is very simple:
7018fc51ccaSHiroo HAYASHI
7028fc51ccaSHiroo HAYASHI``parsers/autoconf.c``:
7038fc51ccaSHiroo HAYASHI
7048fc51ccaSHiroo HAYASHI.. code-block:: C
7058fc51ccaSHiroo HAYASHI
7068fc51ccaSHiroo HAYASHI    static bool probeLanguage (m4Subparser *m4, const char* token)
7078fc51ccaSHiroo HAYASHI    {
7088fc51ccaSHiroo HAYASHI	    return strncmp (token, "m4_", 3) == 0
7098fc51ccaSHiroo HAYASHI		    || strncmp (token, "AC_", 3) == 0
7108fc51ccaSHiroo HAYASHI		    || strncmp (token, "AM_", 3) == 0
7118fc51ccaSHiroo HAYASHI		    || strncmp (token, "AS_", 3) == 0
7128fc51ccaSHiroo HAYASHI		    || strncmp (token, "AH_", 3) == 0
7138fc51ccaSHiroo HAYASHI		    ;
7145ab497a3SMasatake YAMATO    }
7155ab497a3SMasatake YAMATO
7168fc51ccaSHiroo HAYASHIThis function checks the prefix of passed tokens. If known
7178fc51ccaSHiroo HAYASHIprefix is found, Autoconf assumes this is an Autoconf input
7188fc51ccaSHiroo HAYASHIand returns ``true``.
7195ab497a3SMasatake YAMATO
7208fc51ccaSHiroo HAYASHI``parsers/m4.c``:
7215ab497a3SMasatake YAMATO
7228fc51ccaSHiroo HAYASHI.. code-block:: C
7235ab497a3SMasatake YAMATO
7248fc51ccaSHiroo HAYASHI		if (m4tmp->probeLanguage
7258fc51ccaSHiroo HAYASHI			&& m4tmp->probeLanguage (m4tmp, token))
7268fc51ccaSHiroo HAYASHI		{
7278fc51ccaSHiroo HAYASHI			chooseExclusiveSubparser ((m4Subparser *)tmp, NULL);
7288fc51ccaSHiroo HAYASHI			m4found = m4tmp;
7298fc51ccaSHiroo HAYASHI		}
7305ab497a3SMasatake YAMATO
7318fc51ccaSHiroo HAYASHIThe m4 parsers calls ``probeLanguage`` function of a subparser. If ``true``
7328fc51ccaSHiroo HAYASHIis returned ``chooseExclusiveSubparser`` function which is defined
7338fc51ccaSHiroo HAYASHIin the main part. ``chooseExclusiveSubparser`` calls
7348fc51ccaSHiroo HAYASHI``exclusiveSubparserChosenNotify`` method of the chosen subparser.
7355ab497a3SMasatake YAMATO
7368fc51ccaSHiroo HAYASHIThe method is implemented in Autoconf subparser like following:
7375ab497a3SMasatake YAMATO
7388fc51ccaSHiroo HAYASHI``parsers/autoconf.c``:
7395ab497a3SMasatake YAMATO
7408fc51ccaSHiroo HAYASHI.. code-block:: C
7415ab497a3SMasatake YAMATO
7428fc51ccaSHiroo HAYASHI    static void exclusiveSubparserChosenCallback (subparser *s, void *data)
7438fc51ccaSHiroo HAYASHI    {
7448fc51ccaSHiroo HAYASHI	    setM4Quotes ('[', ']');
7458fc51ccaSHiroo HAYASHI    }
7465ab497a3SMasatake YAMATO
7478fc51ccaSHiroo HAYASHIIt changes quote characters of the m4 parser.
7488fc51ccaSHiroo HAYASHI
7498fc51ccaSHiroo HAYASHI
7508fc51ccaSHiroo HAYASHIMaking a tag in a subparser
751b45a42b3SHiroo HAYASHI^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7528fc51ccaSHiroo HAYASHI
7538fc51ccaSHiroo HAYASHIVia calling callback functions defined in subparsers, their base parser
7548fc51ccaSHiroo HAYASHIgives chance to them making tag entries.
7558fc51ccaSHiroo HAYASHI
7568fc51ccaSHiroo HAYASHIThe m4 parser calls ``newMacroNotify`` method when it finds an m4 macro is used.
7578fc51ccaSHiroo HAYASHIThe Autoconf parser connects ``newMacroCallback`` function defined in ``parser/autoconf.c``.
7588fc51ccaSHiroo HAYASHI
7598fc51ccaSHiroo HAYASHI
7608fc51ccaSHiroo HAYASHI``parsers/autoconf.c``:
7618fc51ccaSHiroo HAYASHI
7628fc51ccaSHiroo HAYASHI
7638fc51ccaSHiroo HAYASHI.. code-block:: C
7648fc51ccaSHiroo HAYASHI
7658fc51ccaSHiroo HAYASHI    static int newMacroCallback (m4Subparser *m4, const char* token)
7668fc51ccaSHiroo HAYASHI    {
7678fc51ccaSHiroo HAYASHI	    int keyword;
7688fc51ccaSHiroo HAYASHI	    int index = CORK_NIL;
7698fc51ccaSHiroo HAYASHI
7708fc51ccaSHiroo HAYASHI	    keyword = lookupKeyword (token, getInputLanguage ());
7718fc51ccaSHiroo HAYASHI
7728fc51ccaSHiroo HAYASHI	    /* TODO:
7738fc51ccaSHiroo HAYASHI	       AH_VERBATIM
7748fc51ccaSHiroo HAYASHI	     */
7758fc51ccaSHiroo HAYASHI	    switch (keyword)
7768fc51ccaSHiroo HAYASHI	    {
7778fc51ccaSHiroo HAYASHI	    case KEYWORD_NONE:
7788fc51ccaSHiroo HAYASHI		    break;
7798fc51ccaSHiroo HAYASHI	    case KEYWORD_init:
7808fc51ccaSHiroo HAYASHI		    index = makeAutoconfTag (PACKAGE_KIND);
7818fc51ccaSHiroo HAYASHI		    break;
7828fc51ccaSHiroo HAYASHI
7835ab497a3SMasatake YAMATO    ...
7845ab497a3SMasatake YAMATO
7858fc51ccaSHiroo HAYASHI    extern parserDefinition* AutoconfParser (void)
7865ab497a3SMasatake YAMATO    {
7875ab497a3SMasatake YAMATO	    ...
7888fc51ccaSHiroo HAYASHI	    static m4Subparser autoconfSubparser = {
7898fc51ccaSHiroo HAYASHI		    .subparser = {
7908fc51ccaSHiroo HAYASHI			    .direction = SUBPARSER_BI_DIRECTION,
7918fc51ccaSHiroo HAYASHI			    .exclusiveSubparserChosenNotify = exclusiveSubparserChosenCallback,
7928fc51ccaSHiroo HAYASHI		    },
7938fc51ccaSHiroo HAYASHI		    .probeLanguage  = probeLanguage,
7948fc51ccaSHiroo HAYASHI		    .newMacroNotify = newMacroCallback,
7958fc51ccaSHiroo HAYASHI
7968fc51ccaSHiroo HAYASHIIn ``newMacroCallback`` function, the Autoconf parser receives the name of macro
7978fc51ccaSHiroo HAYASHIfound by the base parser and analysis whether the macro is interesting
7988fc51ccaSHiroo HAYASHIin the context of Autoconf language or not. If it is interesting name,
7998fc51ccaSHiroo HAYASHIthe Autoconf parser makes a tag for it.
8008fc51ccaSHiroo HAYASHI
8018fc51ccaSHiroo HAYASHI
8028fc51ccaSHiroo HAYASHICalling methods of subparsers from a base parser
803b45a42b3SHiroo HAYASHI^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8048fc51ccaSHiroo HAYASHI
8058fc51ccaSHiroo HAYASHIA base parser can use ``foreachSubparser`` macro for accessing its
8068fc51ccaSHiroo HAYASHIsubparsers. A base should call ``enterSubparser`` before calling a
8078fc51ccaSHiroo HAYASHImethod of a subparser, and call ``leaveSubparser`` after calling the
8088fc51ccaSHiroo HAYASHImethod. The macro and functions are declare in ``main/subparser.h`` .
8098fc51ccaSHiroo HAYASHI
8108fc51ccaSHiroo HAYASHI
8118fc51ccaSHiroo HAYASHI``parsers/m4.c``:
8128fc51ccaSHiroo HAYASHI
8138fc51ccaSHiroo HAYASHI.. code-block:: C
8148fc51ccaSHiroo HAYASHI
8158fc51ccaSHiroo HAYASHI    static m4Subparser * maySwitchLanguage (const char* token)
8168fc51ccaSHiroo HAYASHI    {
8178fc51ccaSHiroo HAYASHI	    subparser *tmp;
8188fc51ccaSHiroo HAYASHI	    m4Subparser *m4found = NULL;
8198fc51ccaSHiroo HAYASHI
8208fc51ccaSHiroo HAYASHI	    foreachSubparser (tmp, false)
8218fc51ccaSHiroo HAYASHI	    {
8228fc51ccaSHiroo HAYASHI		    m4Subparser *m4tmp = (m4Subparser *)tmp;
8238fc51ccaSHiroo HAYASHI
8248fc51ccaSHiroo HAYASHI		    enterSubparser(tmp);
8258fc51ccaSHiroo HAYASHI		    if (m4tmp->probeLanguage
8268fc51ccaSHiroo HAYASHI			    && m4tmp->probeLanguage (m4tmp, token))
8278fc51ccaSHiroo HAYASHI		    {
8288fc51ccaSHiroo HAYASHI			    chooseExclusiveSubparser (tmp, NULL);
8298fc51ccaSHiroo HAYASHI			    m4found = m4tmp;
8308fc51ccaSHiroo HAYASHI		    }
8318fc51ccaSHiroo HAYASHI		    leaveSubparser();
8328fc51ccaSHiroo HAYASHI
8338fc51ccaSHiroo HAYASHI		    if (m4found)
8348fc51ccaSHiroo HAYASHI			    break;
8358fc51ccaSHiroo HAYASHI	    }
8368fc51ccaSHiroo HAYASHI
8378fc51ccaSHiroo HAYASHI	    return m4found;
8388fc51ccaSHiroo HAYASHI    }
8398fc51ccaSHiroo HAYASHI
8408fc51ccaSHiroo HAYASHI``foreachSubparser`` takes a variable having type ``subparser``.
8418fc51ccaSHiroo HAYASHIFor each iteration, the value for the variable is updated.
8428fc51ccaSHiroo HAYASHI
8438fc51ccaSHiroo HAYASHI``enterSubparser`` takes a variable having type ``subparser``.  With the
8448fc51ccaSHiroo HAYASHIcalling ``enterSubparser``, the current language (the value returned from
8458fc51ccaSHiroo HAYASHI``getInputLanguage``) can be temporary switched to the language specified
8468fc51ccaSHiroo HAYASHIwith the variable. One of the effect of switching is that ``language``
8478fc51ccaSHiroo HAYASHIfield of tags made in the callback function called between
8488fc51ccaSHiroo HAYASHI``enterSubparser`` and ``leaveSubparser`` is adjusted.
8498fc51ccaSHiroo HAYASHI
8508fc51ccaSHiroo HAYASHIRegistering a subparser to its base parser
851b45a42b3SHiroo HAYASHI^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8528fc51ccaSHiroo HAYASHI
8538fc51ccaSHiroo HAYASHIUse ``DEPTYPE_SUBPARSER`` dependency in a subparser for registration.
8548fc51ccaSHiroo HAYASHI
8558fc51ccaSHiroo HAYASHI``parsers/autoconf.c``:
8568fc51ccaSHiroo HAYASHI
8578fc51ccaSHiroo HAYASHI.. code-block:: C
8588fc51ccaSHiroo HAYASHI
8598fc51ccaSHiroo HAYASHI    extern parserDefinition* AutoconfParser (void)
8608fc51ccaSHiroo HAYASHI    {
8618fc51ccaSHiroo HAYASHI	    parserDefinition* const def = parserNew("Autoconf");
8628fc51ccaSHiroo HAYASHI
8638fc51ccaSHiroo HAYASHI	    static m4Subparser autoconfSubparser = {
8648fc51ccaSHiroo HAYASHI		    .subparser = {
8658fc51ccaSHiroo HAYASHI			    .direction = SUBPARSER_BI_DIRECTION,
8668fc51ccaSHiroo HAYASHI			    .exclusiveSubparserChosenNotify = exclusiveSubparserChosenCallback,
8678fc51ccaSHiroo HAYASHI		    },
8688fc51ccaSHiroo HAYASHI		    .probeLanguage  = probeLanguage,
8698fc51ccaSHiroo HAYASHI		    .newMacroNotify = newMacroCallback,
8708fc51ccaSHiroo HAYASHI		    .doesLineCommentStart = doesLineCommentStart,
8718fc51ccaSHiroo HAYASHI		    .doesStringLiteralStart = doesStringLiteralStart,
8728fc51ccaSHiroo HAYASHI	    };
8738fc51ccaSHiroo HAYASHI	    static parserDependency dependencies [] = {
8748fc51ccaSHiroo HAYASHI		    [0] = { DEPTYPE_SUBPARSER, "M4", &autoconfSubparser },
8758fc51ccaSHiroo HAYASHI	    };
8768fc51ccaSHiroo HAYASHI
8778fc51ccaSHiroo HAYASHI	    def->dependencies = dependencies;
8788fc51ccaSHiroo HAYASHI	    def->dependencyCount = ARRAY_SIZE (dependencies);
8798fc51ccaSHiroo HAYASHI
8808fc51ccaSHiroo HAYASHI
8818fc51ccaSHiroo HAYASHI``DEPTYPE_SUBPARSER`` is specified in the 0th element of ``dependencies``
8828fc51ccaSHiroo HAYASHIfunction static variable. In the next a literal string "M4" is
8838fc51ccaSHiroo HAYASHIspecified and ``autoconfSubparser`` follows. The intent of the code is
8848fc51ccaSHiroo HAYASHIregistering ``autoconfSubparser`` subparser definition to a base parser
8858fc51ccaSHiroo HAYASHInamed "M4".
8868fc51ccaSHiroo HAYASHI
8878fc51ccaSHiroo HAYASHI``dependencies`` function static variable must be assigned to
8888fc51ccaSHiroo HAYASHI``dependencies`` fields of a variable of ``parserDefinition``.
8898fc51ccaSHiroo HAYASHIThe main part of Universal Ctags refers the field when
8908fc51ccaSHiroo HAYASHIinitializing parsers.
8918fc51ccaSHiroo HAYASHI
8928fc51ccaSHiroo HAYASHI``[0]`` emphasizes this is "the 0th element". The subparser may refer
8938fc51ccaSHiroo HAYASHIthe index of the array when the subparser calls
8948fc51ccaSHiroo HAYASHI``scheduleRunningBaseparser``.
8958fc51ccaSHiroo HAYASHI
8968fc51ccaSHiroo HAYASHI
8978fc51ccaSHiroo HAYASHIScheduling running the base parser
898b45a42b3SHiroo HAYASHI^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8998fc51ccaSHiroo HAYASHI
9008fc51ccaSHiroo HAYASHIFor the case that a subparser is chosen in top down, the subparser
9018fc51ccaSHiroo HAYASHImust call ``scheduleRunningBaseparser`` in the main ``parser`` method.
9028fc51ccaSHiroo HAYASHI
9038fc51ccaSHiroo HAYASHI``parsers/autoconf.c``:
9048fc51ccaSHiroo HAYASHI
9058fc51ccaSHiroo HAYASHI.. code-block:: C
9068fc51ccaSHiroo HAYASHI
9078fc51ccaSHiroo HAYASHI    static void findAutoconfTags(void)
9088fc51ccaSHiroo HAYASHI    {
9098fc51ccaSHiroo HAYASHI	    scheduleRunningBaseparser (0);
9108fc51ccaSHiroo HAYASHI    }
9118fc51ccaSHiroo HAYASHI
9128fc51ccaSHiroo HAYASHI    extern parserDefinition* AutoconfParser (void)
9138fc51ccaSHiroo HAYASHI    {
9145ab497a3SMasatake YAMATO	    ...
9158fc51ccaSHiroo HAYASHI	    parserDefinition* const def = parserNew("Autoconf");
9168fc51ccaSHiroo HAYASHI	    ...
9178fc51ccaSHiroo HAYASHI	    static parserDependency dependencies [] = {
9188fc51ccaSHiroo HAYASHI		    [0] = { DEPTYPE_SUBPARSER, "M4", &autoconfSubparser },
9198fc51ccaSHiroo HAYASHI	    };
9208fc51ccaSHiroo HAYASHI
9218fc51ccaSHiroo HAYASHI	    def->dependencies = dependencies;
9228fc51ccaSHiroo HAYASHI	    ...
9238fc51ccaSHiroo HAYASHI	    def->parser = findAutoconfTags;
9248fc51ccaSHiroo HAYASHI	    ...
9255ab497a3SMasatake YAMATO	    return def;
9265ab497a3SMasatake YAMATO    }
9275ab497a3SMasatake YAMATO
9288fc51ccaSHiroo HAYASHIA subparser can do nothing actively. A base parser makes its subparser
9298fc51ccaSHiroo HAYASHIwork by calling methods of the subparser.  Therefore a subparser must
9308fc51ccaSHiroo HAYASHIrun its base parser when the subparser is chosen in a top down way,
9318fc51ccaSHiroo HAYASHIThe main part prepares ``scheduleRunningBaseparser`` function for the purpose.
9325ab497a3SMasatake YAMATO
9338fc51ccaSHiroo HAYASHIA subparser should call the function from ``parser`` method of ``parserDefinition``
9348fc51ccaSHiroo HAYASHIof the subparser. ``scheduleRunningBaseparser`` takes an integer. It specifies
9358fc51ccaSHiroo HAYASHIan index of the dependency which is used for registering the subparser.
9365ab497a3SMasatake YAMATO
9375ab497a3SMasatake YAMATO
93831eb7333SHiroo HAYASHIPackCC compiler-compiler
939f7618ddaSHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
940f7618ddaSHiroo HAYASHI
94186bcb5c2SHiroo HAYASHIPackCC is a compiler-compiler; it translates ``.peg`` grammar file to ``.c``
94231eb7333SHiroo HAYASHIfile.  PackCC was originally written by Arihiro Yoshida. Its source
943ae30dd46SJan Dolinarrepository is at https://github.com/arithy/packcc.
944f7618ddaSHiroo HAYASHI
94586bcb5c2SHiroo HAYASHIThe source tree of PackCC is grafted at ``misc/packcc`` directory.
94631eb7333SHiroo HAYASHIBuilding PackCC and ctags are integrated in the build-scripts of
947dccba5efSHiroo HAYASHIUniversal Ctags.
948f7618ddaSHiroo HAYASHI
94931eb7333SHiroo HAYASHIRefer `peg/valink.peg
95031eb7333SHiroo HAYASHI<https://github.com/universal-ctags/ctags/blob/master/peg/varlink.peg>`_ as a
95131eb7333SHiroo HAYASHIsample of a parser using PackCC.
9528fc51ccaSHiroo HAYASHI
9538fc51ccaSHiroo HAYASHIAutomatic parser guessing (TBW)
9548fc51ccaSHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9558fc51ccaSHiroo HAYASHI
9568fc51ccaSHiroo HAYASHIManaging regular expression parsers (TBW)
9578fc51ccaSHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9588fc51ccaSHiroo HAYASHI
959d0109b4eSHiroo HAYASHIGhost kind in regex parser (TBW)
960b45a42b3SHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
961b45a42b3SHiroo HAYASHI
962b45a42b3SHiroo HAYASHI.. TODO: Q: what is the point of documenting this?
963d0109b4eSHiroo HAYASHI	from comment on #2916: I (@masatake) must explain the ghost kind.
964d0109b4eSHiroo HAYASHI	from comment on #2916:
965d0109b4eSHiroo HAYASHI		I (@masatake) found I must explain "placeholder tag". The ghost kind is
966d0109b4eSHiroo HAYASHI		useful for fill the find field of the placeholder tag. I will write about
967d0109b4eSHiroo HAYASHI		the Ghost kind when I write about the placeholder tag. I will write about
968d0109b4eSHiroo HAYASHI		the placeholder tag when I write about Optscript.
969b45a42b3SHiroo HAYASHI
970b45a42b3SHiroo HAYASHI	If a whitespace is used as a kind letter, it is never printed when
971b45a42b3SHiroo HAYASHI	ctags is called with ``--list-kinds`` option.  This kind is
972b45a42b3SHiroo HAYASHI	automatically assigned to an empty name pattern.
973b45a42b3SHiroo HAYASHI
974b45a42b3SHiroo HAYASHI	Normally you don't need to know this.
975