.\" Man page generated from reStructuredText. . .TH CTAGS-OPTLIB 7 "" "0.0.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\-universal\fP [options] [file(s)] \fBetags\fP [options] [file(s)] .fi .sp .SH DESCRIPTION .sp \fBExuberant\-ctags\fP, the ancestor of \fBUniversal\-ctags\fP, has provided the way to define a new parser from command line. Universal\-ctags extends and refines this feature. \fBoptlib 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. Following options are for defining (or customizing) a parser: .INDENT 0.0 .IP \(bu 2 \fB\-\-langdef=\fP .IP \(bu 2 \fB\-\-kinddef\-=\fP .IP \(bu 2 \fB\-\-map\-=\fP .IP \(bu 2 \fB\-\-regex\-=\fP .UNINDENT .sp Following options are for controlling loading parser definition: .INDENT 0.0 .IP \(bu 2 \fB\-\-optlib\-dir=[+]directory\fP .IP \(bu 2 \fB\-\-options=file|directory\fP .IP \(bu 2 \fB\-\-options\-maybe=pathname\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\-universal 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=pathname\fP, \fB\-\-options\-maybe=pathname\fP, and \fB\-\-optlib\-dir=[+]directory\fP are for loading optlib files you need occasionally. See "COMMAND LINE INTERFACE" 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 ".ctags" 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=msg\fP and \fB\-\-_force\-quit=[num]\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=name\fP option. \fINAME\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\-=[+|\-]extension|pattern\fP\&. .IP 4. 3 Define kinds .sp Use \fB\-\-kinddef\-=letter,name,description\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\-=/regexp/replacement/[kind\-spec/][flags]\fP option. .sp As \fIKIND\-SPEC\fP, you can use the one\-letter flag defined with \fB\-\-kinddef\-=letter,name,description\fP option. .UNINDENT .SH EXAMPLE .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 .SH OPTIONS .INDENT 0.0 .TP .B \fB\-\-langdef=name\fP Defines a new user\-defined language, \fIname\fP, to be parsed with regular expressions. Once defined, name may be used in other options taking language names. .INDENT 7.0 .TP .B \fIname\fP must consist of alphanumeric characters, "#", or "+" (\(aq[a\-zA\-Z0\-9#+]+\(aq). The graph characters other than "#" and "+" are disallowed (or reserved). Some of them (\(aq[\-=:{.]\(aq) are disallowed because they can make the command line parser of ctags\-universal confused. The rest of them are just reserved for future extending ctags\-universal. .sp "all" is an exception. "all" as \fIname\fP is not acceptable. It is a reserved word. See the description of \fB\-\-kinds\-=[+|\-]kinds|*\fP option in ctags(1) about how the reserved word is used. .UNINDENT .sp The names of built\-in parsers are capitalized. When ctags\-universal evaluates an option in a command line, and chooses a parser, ctags\-universal 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\-universal 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\-\-list\-regex\-flags\fP Lists the flags that can be used in \fB\-\-regex\-\fP option. .TP .B \fB\-\-kinddef\-=letter,name,description\fP Define a kind for \fI\fP\&. Be not confused this with \fB\-\-kinds\-\fP\&. .sp \fIletter\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 \fIname\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 \fIname\fP\&. It has been reserved for representing a file since Exuberant\-ctags. .sp Note that using a number character in a \fIname\fP violates the version 2 of tags file format though ctags\-universal accepts it. For more detail, see tags(5). .sp \fIdescription\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 \fIletter\fP, \fIname\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 \fIletter\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 \fIletter\fP is used as value in the "kind" extension field in tags output. .sp The \fIname\fP surrounded by braces can be used as an argument for \fB\-\-kind\-\fP option. If \fBK\fP field is enabled, the \fIname\fP is used as value in the "kind" extension field in tags output. .sp The \fIdescription\fP and \fIletter\fP are listed in \fB\-\-list\-kinds\fP output. All three elements of kind\-spec are listed in \fB\-\-list\-kinds\-full\fP output. Don\(aqt use braces in the \fIdescription\fP\&. They will be used meta characters in the future. .TP .B \fB\-\-regex\-=/regexp/replacement/[kind\-spec/][flags]\fP The /regexp/replacement/ pair defines a regular expression replacement pattern, similar in style to sed substitution commands, 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). The regular expression, regexp, 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\&. When a matching line is found, a tag will be generated for the name defined by \fIreplacement\fP, which generally will contain the special back\-references \fB\e1\fP through \fB\e9\fP to refer to matching sub\-expression groups within regexp. The \fB/\fP 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 (\fB\e\fP) 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 flags, regexp is interpreted as a Posix extended regular expression. The \fIreplacement\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. An optional kind specifier for tags matching regexp may follow \fIreplacement\fP, which will determine what kind of tag is reported in the "kind" extension field (see tags(5)). .sp \fIkind\-spec\fP has two forms: one\-letter form and full form. The one\-letter form assumes using \fB\-\-regex\-\fP option with \fB\-\-kinddef\-\fP option. The \fIkind\-spec\fP in \fB\-\-regex\-\fP option just refers a letter defined with \fB\-\-kinddef\-\fP\&. This form is recommended in Universal\-ctags. .sp The full form of \fIkind\-spec\fP is in the form of a single \fIletter\fP, a comma, a \fIname\fP, a comma, a \fIdescription\fP\&. See the description of \fB\-\-kinddef\-=letter,name,description\fP option about how the elements are used. .sp Either the kind \fIname\fP and/or the \fIdescription\fP can be omitted. However, unless the \fIletter\fP is not defined with \fB\-\-kinddef\-\fP option, omitting is not recommended in Universal\-ctags. The omitting form is supported only for keeping the compatibility with Exuberant\-ctags. Supporting the omitting form will be removed from Universal\-ctags in the future. If kind\-spec is omitted, it defaults to "r,regex". .sp About \fIflag\fP, see "Flags for \fB\-\-regex\-\fP option". .sp For more information on the regular expressions used by ctags\-universal, see either the regex(5,7) man page, or the GNU info documentation for regex (e.g. "info regex"). .TP .B \fB\-\-_echo=msg\fP Print \fImsg\fP to the standard error stream. This is helpful to understand (and debug) optlib loading feature of Universal\-ctags. .TP .B \fB\-\-_force\-quit=[num]\fP Exits immediately when this option is processed. If \fInum\fP is used as exit status. The default is 0. This is helpful to debug optlib loading feature of Universal\-ctags. .UNINDENT .SH FLAGS FOR --REGEX- OPTION .sp You can specify more than one flag at the end of \fB\-\-regex\-\fP to control how Universal\-ctags uses the pattern. .sp Exuberant\-ctags uses a \fIletter\fP to represent a flag. In Universal\-ctags, a \fIname\fP surrounded by braces (name form) can be used in addition to \fIletter\fP\&. The name form makes a user reading an optlib file easier. 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\-universal attaches the tag at the top to the tag captured with \fB\-\-regex\-\fP as the value for the \fBscope:\fP field. .sp ctags\-universal 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 \fIreplacement\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\-universal 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\-universal attaches the line number of the match to the \fBend:\fP field of the named tag. .sp ctags\-universal 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 .SH MORE EXAMPLES .sp Four things, an input source file, an optlib file, a command line invoking ctags, and output makes an example. .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 ("input.srb"): .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 "Example" with \fBclass\fP kind, "methodA", and "methodB" with \fBmethod\fP kind. "methodA" and "methodB" should have "Example" as their scope. \fBend:\fP fields of each tag should have proper values. .sp optlib file ("sub\-ruby.ctags"): .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 \-\-options=NONE \-\-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(5,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. .