.\" Man page generated from reStructuredText. . .TH CTAGS-OPTLIB 7 "" "5.9.0" "Universal Ctags" .SH NAME ctags-optlib \- Universal Ctags parser definition language . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .SH SYNOPSIS .nf \fBctags\fP [options] [file(s)] \fBetags\fP [options] [file(s)] .fi .sp .SH DESCRIPTION .sp \fIExuberant Ctags\fP, the ancestor of \fIUniversal Ctags\fP, has provided the way to define a new parser from command line. Universal Ctags extends and refines this feature. \fIoptlib parser\fP is the name for such parser in Universal Ctags. "opt" intends a parser is defined with combination of command line options. "lib" intends an optlib parser can be more than ad\-hoc personal configuration. .sp This man page is for people who want to define an optlib parser. The readers should read ctags(1) of Universal Ctags first. .sp Following options are for defining (or customizing) a parser: .INDENT 0.0 .IP \(bu 2 \fB\-\-langdef=\fP .IP \(bu 2 \fB\-\-map\-=[+|\-]|\fP .IP \(bu 2 \fB\-\-kinddef\-=,,\fP .IP \(bu 2 \fB\-\-regex\-=////[]\fP .IP \(bu 2 \fB\-\-mline\-regex\-=////[]\fP .UNINDENT .sp Following options are for controlling loading parser definition: .INDENT 0.0 .IP \(bu 2 \fB\-\-options=\fP .IP \(bu 2 \fB\-\-options\-maybe=\fP .IP \(bu 2 \fB\-\-optlib\-dir=[+]\fP .UNINDENT .sp The design of options and notations for defining a parser in Exuberant Ctags may focus on reducing the number of typing by user. Reducing the number of typing is important for users who want to define (or customize) a parser quickly. .sp On the other hand, the design in Universal Ctags focuses on maintainability. The notation of Universal Ctags is redundant than that of Exuberant Ctags; the newly introduced kind should be declared explicitly, (long) names are approved than one\-letter flags specifying kinds, and naming rules are stricter. .sp This man page explains only stable options and flags. Universal Ctags also introduces experimental options and flags which have names starting with \fB_\fP\&. For documentation on these options and flags, visit Universal Ctags web site at \fI\%https://ctags.io/\fP\&. .SS Storing a parser definition to a file .sp Though it is possible to define a parser from command line, you don\(aqt want to type the same command line each time when you need the parser. You can store options for defining a parser into a file. .sp ctags loads files (preload files) listed in "FILES" section of ctags(1) at program starting up. You can put your parser definition needed usually to the files. .sp \fB\-\-options=\fP, \fB\-\-options\-maybe=\fP, and \fB\-\-optlib\-dir=[+]\fP are for loading optlib files you need occasionally. See "Option File Options" section of ctags(1) for these options. .sp As explained in "FILES" section of ctags(1), options for defining a parser listed line by line in an optlib file. Prefixed white spaces are ignored. A line starting with \(aq#\(aq is treated as a comment. Escaping shell meta character is not needed. .sp Use \fB\&.ctags\fP as file extension for optlib file. You can define multiple parsers in an optlib file but it is better to make a file for each parser definition. .sp \fB\-\-_echo=\fP and \fB\-\-_force\-quit=\fP options are for debugging optlib parser. .SS Overview for defining a parser .INDENT 0.0 .IP 1. 3 Design the parser .sp You need know both the target language and the ctags\(aq concepts (definition, reference, kind, role, field, extra). About the concepts, ctags(1) of Universal Ctags may help you. .IP 2. 3 Give a name to the parser .sp Use \fB\-\-langdef=\fP option. \fI\fP is referred as \fI\fP in the later steps. .IP 3. 3 Give a file pattern or file extension for activating the parser .sp Use \fB\-\-map\-=[+|\-]|\fP\&. .IP 4. 3 Define kinds .sp Use \fB\-\-kinddef\-=,,\fP option. Universal Ctags introduces this option. Exuberant Ctags doesn\(aqt have. In Exuberant Ctags, a kind is defined as a side effect of specifying \fB\-\-regex\-=\fP option. So user doesn\(aqt have a chance to recognize how important the definition of kind. .IP 5. 3 Define patterns .sp Use \fB\-\-regex\-=////[]\fP option for a single\-line regular expression. You can also use \fB\-\-mline\-regex\-=////[]\fP option for a multi\-line regular expression. .sp As \fI\fP, you can use the one\-letter flag defined with \fB\-\-kinddef\-=,,\fP option. .UNINDENT .SH OPTIONS .INDENT 0.0 .TP .B \fB\-\-langdef=\fP Defines a new user\-defined language, \fI\fP, to be parsed with regular expressions. Once defined, \fI\fP may be used in other options taking language names. .sp \fI\fP must consist of alphanumeric characters, \(aq\fB#\fP\(aq, or \(aq\fB+\fP\(aq (\(aq[a\-zA\-Z0\-9#+]+\(aq). The graph characters other than \(aq\fB#\fP\(aq and \(aq\fB+\fP\(aq are disallowed (or reserved). Some of them (\fB[\-=:{.]\fP) are disallowed because they can make the command line parser of ctags confused. The rest of them are just reserved for future extending ctags. .sp \fBall\fP is an exception. \fBall\fP as \fI\fP is not acceptable. It is a reserved word. See the description of \fB\-\-kinds\-(|all)=[+|\-](|*)\fP option in ctags(1) about how the reserved word is used. .sp The names of built\-in parsers are capitalized. When ctags evaluates an option in a command line, and chooses a parser, ctags uses the names of parsers in a case\-insensitive way. Therefore, giving a name started from a lowercase character doesn\(aqt help you to avoid the parser name confliction. However, in a tags file, ctags prints parser names in a case\-sensitive way; it prints a parser name as specified in \fB\-\-langdef=\fP option. Therefore, we recommend you to give a name started from a lowercase character to your private optlib parser. With this convention, people can know where a tag entry in a tag file comes from a built\-in parser or a private optlib parser. .TP .B \fB\-\-kinddef\-=,,\fP Define a kind for \fI\fP\&. Be not confused this with \fB\-\-kinds\-\fP\&. .sp \fI\fP must be an alphabetical character (\(aq[a\-zA\-EG\-Z]\(aq) other than "F". "F" has been reserved for representing a file since Exuberant Ctags. .sp \fI\fP must start with an alphabetic character, and the rest must be alphanumeric (\(aq[a\-zA\-Z][a\-zA\-Z0\-9]*\(aq). Do not use "file" as \fI\fP\&. It has been reserved for representing a file since Exuberant Ctags. .sp Note that using a number character in a \fI\fP violates the version 2 of tags file format though ctags accepts it. For more detail, see tags(5). .sp \fI\fP comes from any printable ASCII characters. The exception is \fB{\fP and \fB\e\fP\&. \fB{\fP is reserved for adding flags this option in the future. So put \fB\e\fP before \fB{\fP to include \fB{\fP to a description. To include \fB\e\fP itself to a description, put \fB\e\fP before \fB\e\fP\&. .sp Both \fI\fP, \fI\fP and their combination must be unique in a \fI\fP\&. .sp This option is newly introduced in Universal Ctags. This option reduces the typing defining a regex pattern with \fB\-\-regex\-=\fP, and keeps the consistency of kind definitions in a language. .sp The \fI\fP can be used as an argument for \fB\-\-kinds\-\fP option to enable or disable the kind. Unless \fBK\fP field is enabled, the \fI\fP is used as value in the "kind" extension field in tags output. .sp The \fI\fP surrounded by braces can be used as an argument for \fB\-\-kind\-\fP option. If \fBK\fP field is enabled, the \fI\fP is used as value in the "kind" extension field in tags output. .sp The \fI\fP and \fI\fP are listed in \fB\-\-list\-kinds\fP output. All three elements of the kind\-spec are listed in \fB\-\-list\-kinds\-full\fP output. Don\(aqt use braces in the \fI\fP\&. They will be used meta characters in the future. .TP .B \fB\-\-regex\-=////[]\fP Define a single\-line regular expression. .sp The \fI///\fP pair defines a regular expression replacement pattern, similar in style to \fBsed\fP substitution commands, \fBs/regexp/replacement/\fP, with which to generate tags from source files mapped to the named language, \fI\fP, (case\-insensitive; either a built\-in or user\-defined language). .sp The regular expression, \fI\fP, defines an extended regular expression (roughly that used by egrep(1)), which is used to locate a single source line containing a tag and may specify tab characters using \fB\et\fP\&. .sp When a matching line is found, a tag will be generated for the name defined by \fI\fP, which generally will contain the special back\-references \fB\e1\fP through \fB\e9\fP to refer to matching sub\-expression groups within \fI\fP\&. .sp The \(aq\fB/\fP\(aq separator characters shown in the parameter to the option can actually be replaced by any character. Note that whichever separator character is used will have to be escaped with a backslash (\(aq\fB\e\fP\(aq) character wherever it is used in the parameter as something other than a separator. The regular expression defined by this option is added to the current list of regular expressions for the specified language unless the parameter is omitted, in which case the current list is cleared. .sp Unless modified by \fI\fP, \fI\fP is interpreted as a POSIX extended regular expression. The \fI\fP should expand for all matching lines to a non\-empty string of characters, or a warning message will be reported unless \fB{placeholder}\fP regex flag is specified. .sp A kind specifier (\fI\fP) for tags matching regexp may follow \fI\fP, which will determine what kind of tag is reported in the \fBkind\fP extension field (see tags(5)). .sp \fI\fP has two forms: \fIone\-letter form\fP and \fIfull form\fP\&. .sp The one\-letter form in the form of \fB\fP\&. It just refers a kind \fI\fP defined with \fB\-\-kinddef\-\fP\&. This form is recommended in Universal Ctags. .sp The full form of \fI\fP is in the form of \fB,,\fP\&. Either the kind \fI\fP and/or the \fI\fP can be omitted. See the description of \fB\-\-kinddef\-=,,\fP option about the elements. .sp The full form is supported only for keeping the compatibility with Exuberant Ctags which does not have \fB\-\-kinddef\-\fP option. Supporting the form will be removed from Universal Ctags in the future. .\" MEMO: the following line is commented out .\" If ** is omitted, it defaults to ``r,regex``. . .sp About \fI\fP, see "FLAGS FOR \fB\-\-regex\-\fP OPTION". .sp For more information on the regular expressions used by ctags, see either the regex(5,7) man page, or the GNU info documentation for regex (e.g. "\fBinfo regex\fP"). .TP .B \fB\-\-list\-regex\-flags\fP Lists the flags that can be used in \fB\-\-regex\-\fP option. .TP .B \fB\-\-list\-mline\-regex\-flags\fP Lists the flags that can be used in \fB\-\-mline\-regex\-\fP option. .TP .B \fB\-\-mline\-regex\-=////[]\fP Define a multi\-line regular expression. .sp This option is similar to \fB\-\-regex\-\fP option except the pattern is applied to the whole file’s contents, not line by line. .TP .B \fB\-\-_echo=\fP Print \fI\fP to the standard error stream. This is helpful to understand (and debug) optlib loading feature of Universal Ctags. .TP .B \fB\-\-_force\-quit[=]\fP Exits immediately when this option is processed. If \fI\fP is used as exit status. The default is 0. This is helpful to debug optlib loading feature of Universal Ctags. .UNINDENT .SS FLAGS FOR \fB\-\-regex\-\fP OPTION .sp You can specify more than one flag, \fB|{}\fP, at the end of \fB\-\-regex\-\fP to control how Universal Ctags uses the pattern. .sp Exuberant Ctags uses a \fI\fP to represent a flag. In Universal Ctags, a \fI\fP surrounded by braces (name form) can be used in addition to \fI\fP\&. The name form makes a user reading an optlib file easier. .sp The most of all flags newly added in Universal Ctags don\(aqt have the one\-letter representation. All of them have only the name representation. \fB\-\-list\-regex\-flags\fP lists all the flags. .INDENT 0.0 .TP .B \fBbasic\fP (one\-letter form \fBb\fP) The pattern is interpreted as a POSIX basic regular expression. .TP .B \fBexclusive\fP (one\-letter form \fBx\fP) Skip testing the other patterns if a line is matched to this pattern. This is useful to avoid using CPU to parse line comments. .TP .B \fBextend\fP (one\-letter form \fBe\fP) The pattern is interpreted as a POSIX extended regular expression (default). .TP .B \fBicase\fP (one\-letter form \fBi\fP) The regular expression is to be applied in a case\-insensitive manner. .TP .B \fBplaceholder\fP Don\(aqt emit a tag captured with a regex pattern. The replacement can be an empty string. See the following description of \fBscope=...\fP flag about how this is useful. .UNINDENT .sp \fBscope=(ref|push|pop|clear|set)\fP .INDENT 0.0 .INDENT 3.5 Specify what to do with the internal scope stack. .sp A parser programmed with \fB\-\-regex\-\fP has a stack (scope stack) internally. You can use it for tracking scope information. The \fBscope=...\fP flag is for manipulating and utilizing the scope stack. .sp If \fB{scope=push}\fP is specified, a tag captured with \fB\-\-regex\-\fP is pushed to the stack. \fB{scope=push}\fP implies \fB{scope=ref}\fP\&. .sp You can fill the scope field of captured tag with \fB{scope=ref}\fP\&. If \fB{scope=ref}\fP flag is given, ctags attaches the tag at the top to the tag captured with \fB\-\-regex\-\fP as the value for the \fBscope:\fP field. .sp ctags pops the tag at the top of the stack when \fB\-\-regex\-\fP with \fB{scope=pop}\fP is matched to the input line. .sp Specifying \fB{scope=clear}\fP removes all the tags in the scope. Specifying \fB{scope=set}\fP removes all the tags in the scope, and then pushes the captured tag as \fB{scope=push}\fP does. .sp In some cases, you may want to use \fB\-\-regex\-\fP only for its side effects: using it only to manipulate the stack but not for capturing a tag. In such a case, make \fI\fP component of \fB\-\-regex\-\fP option empty while specifying \fB{placeholder}\fP as a regex flag. For example, a non\-named tag can be put on the stack by giving a regex flag "\fB{scope=push}{placeholder}\fP". .sp You may wonder what happens if a regex pattern with \fB{scope=ref}\fP flag matches an input line but the stack is empty, or a non\-named tag is at the top. If the regex pattern contains a \fB{scope=ref}\fP flag and the stack is empty, the \fB{scope=ref}\fP flag is ignored and nothing is attached to the \fBscope:\fP field. .sp If the top of the stack contains an unnamed tag, ctags searches deeper into the stack to find the top\-most named tag. If it reaches the bottom of the stack without finding a named tag, the \fB{scope=ref}\fP flag is ignored and nothing is attached to the \fBscope:\fP field. .sp When a named tag on the stack is popped or cleared as the side effect of a pattern matching, ctags attaches the line number of the match to the \fBend:\fP field of the named tag. .sp ctags clears all of the tags on the stack when it reaches the end of the input source file. The line number of the end is attached to the \fBend:\fP field of the cleared tags. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B \fBwarning=\fP print the given \fI\fP at WARNING level .TP .B \fBfatal=\fP print the given \fI\fP and exit .UNINDENT .SH EXAMPLES .SS Perl Pod .sp This is the definition (pod.ctags) used in ctags for parsing Pod (\fI\%https://perldoc.perl.org/perlpod.html\fP) file. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C \-\-langdef=pod \-\-map\-pod=+.pod \-\-kinddef\-pod=c,chapter,chapters \-\-kinddef\-pod=s,section,sections \-\-kinddef\-pod=S,subsection,subsections \-\-kinddef\-pod=t,subsubsection,subsubsections \-\-regex\-pod=/^=head1[ \et]+(.+)/\e1/c/ \-\-regex\-pod=/^=head2[ \et]+(.+)/\e1/s/ \-\-regex\-pod=/^=head3[ \et]+(.+)/\e1/S/ \-\-regex\-pod=/^=head4[ \et]+(.+)/\e1/t/ .ft P .fi .UNINDENT .UNINDENT .SS Using scope regex flags .sp Let\(aqs think about writing a parser for a very small subset of the Ruby language. .sp input source file (\fBinput.srb\fP): .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C class Example def methodA puts "in class_method" end def methodB puts "in class_method" end end .ft P .fi .UNINDENT .UNINDENT .sp The parser for the input should capture \fBExample\fP with \fBclass\fP kind, \fBmethodA\fP, and \fBmethodB\fP with \fBmethod\fP kind. \fBmethodA\fP and \fBmethodB\fP should have \fBExample\fP as their scope. \fBend:\fP fields of each tag should have proper values. .sp optlib file (\fBsub\-ruby.ctags\fP): .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C \-\-langdef=subRuby \-\-map\-subRuby=.srb \-\-kinddef\-subRuby=c,class,classes \-\-kinddef\-subRuby=m,method,methods \-\-regex\-subRuby=/^class[ \et]+([a\-zA\-Z][a\-zA\-Z0\-9]+)/\e1/c/{scope=push} \-\-regex\-subRuby=/^end///{scope=pop}{placeholder} \-\-regex\-subRuby=/^[ \et]+def[ \et]+([a\-zA\-Z][a\-zA\-Z0\-9_]+)/\e1/m/{scope=push} \-\-regex\-subRuby=/^[ \et]+end///{scope=pop}{placeholder} .ft P .fi .UNINDENT .UNINDENT .sp command line and output: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ ctags \-\-quiet \-\-fields=+eK \e \-\-options=./sub\-ruby.ctags \-o \- input.srb Example input.srb /^class Example$/;" class end:8 methodA input.srb /^ def methodA$/;" method class:Example end:4 methodB input.srb /^ def methodB$/;" method class:Example end:7 .ft P .fi .UNINDENT .UNINDENT .SH SEE ALSO .sp The official Universal Ctags web site at: .sp \fI\%https://ctags.io/\fP .sp ctags(1), tags(5), regex(3), regex(7), egrep(1) .SH AUTHOR .sp Universal Ctags project \fI\%https://ctags.io/\fP (This man page partially derived from ctags(1) of Executable\-ctags) .sp Darren Hiebert <\fI\%dhiebert@users.sourceforge.net\fP> \fI\%http://DarrenHiebert.com/\fP .\" Generated by docutils manpage writer. .