### Building and Installing Universal Ctags with Autotools Source: https://github.com/universal-ctags/ctags/blob/master/README.md This snippet outlines the standard procedure for building and installing Universal Ctags from its source repository using Autotools. It covers cloning the Git repository, preparing the build environment with `autogen.sh`, configuring the installation path (defaulting to `/usr/local` but customizable with `--prefix`), compiling the source code using `make`, and finally installing the compiled binaries. GNU make is assumed as the `make` command. ```Shell git clone https://github.com/universal-ctags/ctags.git cd ctags ./autogen.sh ./configure # use --prefix=/where/you/want to override installation directory, defaults to /usr/local make make install # may require extra privileges depending on where to install ``` -------------------------------- ### C Example for Kernel Thread Creation with kthread_run Source: https://github.com/universal-ctags/ctags/blob/master/docs/man/ctags-optlib.7.rst This C code snippet, extracted from the Linux kernel, illustrates the usage of the `kthread_run` function to create and start a kernel thread. Specifically, it shows how the `kswapd` kernel thread is initialized, providing a concrete example for subsequent ctags parsing demonstrations. ```C void kswapd_run(int nid) { /* ... */ pgdat->kswapd = kthread_run(kswapd, pgdat, "kswapd%d", nid); /* ... */ ``` -------------------------------- ### Example Output of Man Page Test Execution Source: https://github.com/universal-ctags/ctags/blob/master/docs/testing-parser.rst This console output displays a typical run of the `make man-test` command. It shows the progress of testing examples across various language-specific man pages (Julia, Python, Verilog), indicating which test cases passed and concluding with an 'OK' status if all tests are successful. ```console $ make man-test RUN man-test # Run test cases in ./man/ctags-lang-julia.7.rst.in ``` ./man/ctags-lang-julia.7.rst.in[0]:75...passed ./man/ctags-lang-julia.7.rst.in[1]:93...passed ``` # Run test cases in ./man/ctags-lang-python.7.rst.in ``` ./man/ctags-lang-python.7.rst.in[0]:116...passed ./man/ctags-lang-python.7.rst.in[1]:133...passed ./man/ctags-lang-python.7.rst.in[2]:154...passed ./man/ctags-lang-python.7.rst.in[3]:170...passed ./man/ctags-lang-python.7.rst.in[4]:187...passed ./man/ctags-lang-python.7.rst.in[5]:230...passed ``` # Run test cases in ./man/ctags-lang-verilog.7.rst.in ``` ./man/ctags-lang-verilog.7.rst.in[0]:51...passed ``` OK ``` -------------------------------- ### Example Output of Running All Unit Tests Source: https://github.com/universal-ctags/ctags/blob/master/docs/testing-parser.rst This snippet shows a typical output when running all unit tests. It lists each test case, its associated language, and its status (e.g., 'passed'). ```Shell $ make units Category: ROOT ------------------------------------------------------------------------- Testing 1795612.js as JavaScript passed Testing 1850914.js as JavaScript passed Testing 1878155.js as JavaScript passed Testing 1880687.js as JavaScript passed Testing 2023624.js as JavaScript passed Testing 3184782.sql as SQL passed ... ``` -------------------------------- ### Example Tags File (output.tags) Source: https://github.com/universal-ctags/ctags/blob/master/docs/man/readtags.1.rst This snippet provides an example `tags` file (`output.tags`) that serves as input for subsequent `readtags` formatting examples. It contains various tag entries including macros, functions, and their associated metadata like file, line, type, and signature. ```tags M input.c 4;" macro file: N input.c 3;" macro file: bar input.c 11;" f typeref:typename:void file: signature:(char ** argv,int * r) foo input.c 6;" f typeref:typename:int file: signature:(int v) main input.c 16;" f typeref:typename:int signature:(int argc,char ** argv) ``` -------------------------------- ### Configuring and Installing libreadtags (CMake Standalone) Source: https://github.com/universal-ctags/ctags/blob/master/libreadtags/README.md This snippet demonstrates how to configure and install libreadtags as a standalone CMake project. It prepares a release build with shared libraries and then installs the compiled library and header files to the system's default installation path (e.g., `/usr/local`) using `sudo`. ```shell mkdir build cmake -DCMAKE_BUILD_TYPE=Release -DLIBREADTAGS_BUILD_SHARED=ON -S . -B build sudo cmake --build build --target install ``` -------------------------------- ### Running Man Page Tests with Make Source: https://github.com/universal-ctags/ctags/blob/master/docs/testing-parser.rst This console command executes the `man-test` target, which is designed to test code examples embedded within Universal Ctags' language-specific man pages. It automates the validation of these examples against the ctags utility. ```console $ make man-test ``` -------------------------------- ### Executing Scheme with `begin` and True Initial Condition Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/readtags-qualifier-begin.d/stdout-expected.txt Similar to the previous example, this `begin` form starts with `#t` (true). It then prints `$name` and `$line`, and finally returns `#f` (false). This demonstrates how the final expression determines the overall result of the `begin` block. ```Scheme (begin #t (print $name) (print $line) #f) ``` -------------------------------- ### Executing Scheme with `begin0` and False Initial Condition Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/readtags-qualifier-begin.d/stdout-expected.txt This `begin0` example starts with `#f` (false). It prints `$name` and `$line`, but the block's return value will be `#f`, as `begin0` returns the value of its first expression, regardless of subsequent evaluations. ```Scheme (begin0 #f (print $name) (print $line) #t) ``` -------------------------------- ### Installing uncrustify Code Beautifier (Bash) Source: https://github.com/universal-ctags/ctags/blob/master/misc/packcc/tests/README.md This snippet outlines the process to install `uncrustify`, a code beautifier, from its Git repository. It clones the repository, creates a build directory, configures the build with CMake, compiles the source code, and then installs it system-wide using `sudo`. ```bash git clone https://github.com/uncrustify/uncrustify && cd uncrustify && mkdir -p build && cd build && cmake .. && make && sudo make install ``` -------------------------------- ### Installing bats-core Testing Framework (Bash) Source: https://github.com/universal-ctags/ctags/blob/master/misc/packcc/tests/README.md This snippet demonstrates how to install `bats-core`, a Bash Automated Testing System, from its tarball. It involves downloading the archive, extracting it, navigating into the directory, and running the installation script with superuser privileges to install it globally. ```bash curl -L -o bats-core-1.2.1.tar.gz https://github.com/bats-core/bats-core/archive/v1.2.1.tar.gz && tar zxvf bats-core-1.2.1.tar.gz && cd bats-core-1.2.1 && sudo ./install.sh /usr/local ``` -------------------------------- ### Python Man Page Test Case Example (ReStructuredText) Source: https://github.com/universal-ctags/ctags/blob/master/docs/testing-parser.rst This ReStructuredText snippet provides a concrete example of a Python test case embedded in a man page. It defines an `input.py` file with a simple `import` statement, specifies the `ctags` options to be used, and details the expected `tags` output for the imported module `X0`. ```ReStructuredText "input.py" .. code-block:: Python import X0 "output.tags" with "--options=NONE -o - --extras=+r --fields=+rzK input.py" .. code-block:: tags X0 input.py /^import X0$/;" kind:module roles:imported ``` -------------------------------- ### Hello World in Python Source: https://github.com/universal-ctags/ctags/blob/master/docs/optscript.rst This snippet provides a comparative 'hello, world' example in Python, illustrating the standard way to print a string in Python for users familiar with the language. ```console >>> print ('hello, world') hello, world ``` -------------------------------- ### Displaying Help for `misc/review` Utility (Console) Source: https://github.com/universal-ctags/ctags/blob/master/docs/testing-parser.rst This command invokes the `misc/review` utility with the `--help` flag to display its usage instructions. The output details various subcommands like `list` and `inspect`, along with options such as `-b` for known bug cases, providing a comprehensive guide for reviewing test results. ```Console misc/review --help Usage: misc/review help|--help|-h show this message misc/review [list] [-b] list failed Units and Tmain -b list .b (known bug) marked cases misc/review inspect [-b] inspect difference interactively -b inspect .b (known bug) marked cases ``` -------------------------------- ### Hello World in Optscript Source: https://github.com/universal-ctags/ctags/blob/master/docs/optscript.rst This snippet shows a basic 'hello, world' example in Optscript, demonstrating how to push a string literal onto the stack and print it using the '=' operator. ```console OPT> (hello, world) = hello, world ``` -------------------------------- ### Defining Basic C Functions (Test 1.2 & 1.3) Source: https://github.com/universal-ctags/ctags/blob/master/Units/parser-restructuredtext.r/code-blocks.d/input.rst This snippet defines two additional C functions, `test1_2` and `test1_3`, similar to the previous examples. They demonstrate basic function structure, accepting no parameters and returning an integer 0. ```C int test1_2(void) { return 0; } int test1_3(void) { return 0; } ``` -------------------------------- ### Example DocC API Documentation Input Source: https://github.com/universal-ctags/ctags/blob/master/docs/optlib.rst This snippet provides an example of an input.docC file, which represents an imaginary documentation language for C API libraries. It defines two functions, 'compress' and 'decompress', complete with their signatures and descriptive text, illustrating the format of a DocC input file. ```DocC - function: compress(const char *plain_text, enum algorithm alg) => char * Compress a C string PLAING_TEXT with the algorithm specified with ALG. - function: decompress(const char *compressed_byteseq) => char * Decompress a byte sequence compressed by compress(). ``` -------------------------------- ### Python `__main__` Entry Point Example Source: https://github.com/universal-ctags/ctags/blob/master/docs/optlib.rst This Python snippet illustrates the common idiom for defining code that executes only when the script is run directly. It is used as an example to demonstrate how ctags can conditionally generate tags based on 'extra' flags. ```python if __name__ == '__main__': do_something() ``` -------------------------------- ### Running All Unit Tests with Make Source: https://github.com/universal-ctags/ctags/blob/master/docs/testing-parser.rst This command executes all available unit tests for the universal-ctags project. The results are reported line by line, indicating the status of each test case. ```Shell $ make units ``` -------------------------------- ### Common ctags Execution Examples Source: https://github.com/universal-ctags/ctags/blob/master/docs/man/ctags.1.rst These examples demonstrate common ways to run `ctags` without specific options. `ctags *` processes all recognized source files in the current directory, while `ctags -R` recursively processes files from the current directory downwards. ```Shell ctags * ctags -R ``` -------------------------------- ### Generating Tags with Absolute Input Paths (Duplicate Example) Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/readtags-canonicalize-input-names.d/stdout-expected.txt Another example of a tags file generated with `ctags -A -l`, confirming the behavior of outputting absolute paths for all source files. This output is identical to the previous absolute path examples. ```Tags File a_fn\t/tmp/abc/xyz/a.c\nb_fn\t/tmp/abc/b.c\nc_fn\t/tmp/abc/c.c\nd_fn\t/tmp/d.c\ne_fn\t/tmp/e.c\nf_fn\t/f.c\ng_fn\t/g.c\nh_fn\t/h.c\ni_fn\t/i.c\nj_fn\t/j.c\nk_fn\t/k.c\nl_fn\t/tmp/abc/l.c\nm_fn\t/tmp/abc/m.c\nn_fn\t/tmp/abc/n.c\no_fn\t/tmp/abc/o.c\np_fn\t/tmp/xyz/p.c\nq_fn\t/tmp/xyz/q.c\nr_fn\t/r.c\ns_fn\t/s.c\nt_fn\t/t.c\nu_fn\t/tmp/u.c\nv_fn\t/tmp/abc/v.c\nw_fn\t/abc/w.c ``` -------------------------------- ### Enabling Header Local and System Roles After Global Disablement ({header} kind) Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/list-roles.d/stdout-expected.txt Similar to the previous example, this configuration enables 'local' and 'system' roles for the 'header' kind after a global disablement, using the alternative '{header}' notation. ```Ctags Configuration KIND(L/N) NAME ENABLED DESCRIPTION d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef off undefined f/function foreigndecl off declared in foreign languages h/header local on local header h/header system on system header s/struct foreigndecl off declared in foreign languages ``` -------------------------------- ### Generating Tags with Canonicalized Input (Duplicate Example) Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/readtags-canonicalize-input-names.d/stdout-expected.txt Another example of a tags file generated with `ctags -C -l`, reinforcing the behavior of canonicalizing input paths. This output is identical to the first example, showing consistent path resolution. ```Tags File a_fn\txyz/a.c\nb_fn\tb.c\nc_fn\tc.c\nd_fn\t/tmp/d.c\ne_fn\t/tmp/e.c\nf_fn\t/f.c\ng_fn\t/g.c\nh_fn\t/h.c\ni_fn\t/i.c\nj_fn\t/j.c\nk_fn\t/k.c\nl_fn\tl.c\nm_fn\tm.c\nn_fn\tn.c\no_fn\to.c\np_fn\t/tmp/xyz/p.c\nq_fn\t/tmp/xyz/q.c\nr_fn\t/r.c\ns_fn\t/s.c\nt_fn\t/t.c\nu_fn\t/tmp/u.c\nv_fn\t/tmp/abc/v.c\nw_fn\t/abc/w.c ``` -------------------------------- ### Running Tinst Installation Tests Source: https://github.com/universal-ctags/ctags/blob/master/docs/testing-ctags.rst This command executes the `Tinst` target, which is specifically designed to test the results of the `make install` process, verifying the correct installation of ctags components. ```shell $ make tinst ``` -------------------------------- ### Adding Numbers in Optscript Source: https://github.com/universal-ctags/ctags/blob/master/docs/optscript.rst This example demonstrates basic arithmetic addition in Optscript, where numbers are pushed onto the stack and then the 'add' operator consumes them to produce the sum. ```console OPT> 2 3 add = 5 ``` -------------------------------- ### Installing Dependencies on Fedora Systems Source: https://github.com/universal-ctags/ctags/blob/master/docs/autotools.rst This command installs the required build tools and libraries for Universal Ctags on Fedora systems using `dnf`. Essential dependencies include `gcc`, `make`, `pkgconfig`, `autoconf`, `automake`, `python3-docutils`, `libseccomp-devel`, `jansson-devel`, `libyaml-devel`, and `libxml2-devel`. ```console $ sudo dnf install \ gcc make \ pkgconfig autoconf automake \ python3-docutils \ libseccomp-devel \ jansson-devel \ libyaml-devel \ libxml2-devel ``` -------------------------------- ### Installing Xcode Command Line Tools on macOS Source: https://github.com/universal-ctags/ctags/blob/master/docs/osx.rst This command installs the essential command-line tools for Xcode, including compilers and build utilities, which are a prerequisite for building ctags on macOS. It provides a lightweight alternative to installing the full Xcode distribution. ```Shell xcode-select --install ``` -------------------------------- ### Disabling Header Local and System Roles ({header} kind) Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/list-roles.d/stdout-expected.txt Similar to the previous example, this snippet shows disabling 'local' and 'system' roles for the 'header' kind, illustrating an alternative notation for specifying the kind. ```Ctags Configuration KIND(L/N) NAME ENABLED DESCRIPTION d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined f/function foreigndecl on declared in foreign languages h/header local off local header h/header system off system header s/struct foreigndecl on declared in foreign languages ``` -------------------------------- ### Installing Dependencies on Debian-based Systems Source: https://github.com/universal-ctags/ctags/blob/master/docs/autotools.rst This command installs the necessary build tools and libraries for Universal Ctags on Debian and Ubuntu systems using `apt`. Key dependencies include `gcc`, `make`, `pkg-config`, `autoconf`, `automake`, `python3-docutils`, `libseccomp-dev`, `libjansson-dev`, `libyaml-dev`, and `libxml2-dev`. ```console $ sudo apt install \ gcc make \ pkg-config autoconf automake \ python3-docutils \ libseccomp-dev \ libjansson-dev \ libyaml-dev \ libxml2-dev ``` -------------------------------- ### Example Input File for Multi-Table Regex Source: https://github.com/universal-ctags/ctags/blob/master/docs/optlib.rst This Java-like input file (`input.x`) demonstrates a scenario with block comments and variable declarations. It serves as an example to illustrate the challenges of parsing with traditional regex (like `--regex-` or `--mline-regex-`) and highlights the need for advanced multi-table regex features in ctags to correctly identify tags while ignoring commented sections. ```java /* BLOCK COMMENT var dont_capture_me; */ var a /* ANOTHER BLOCK COMMENT */, b; ``` -------------------------------- ### Examples of Ctags Regex Options with Long Flags Source: https://github.com/universal-ctags/ctags/blob/master/docs/optlib.rst Provides practical examples of using `--regex-` options with various long flags such as `{icase}`, `{exclusive}`, and `{scope=push}`. These examples demonstrate how to define custom tag patterns for different languages (Pod, Foo, Man, Gdbinit) and control matching behavior. ```ctags --regex-Pod=/^=head1[ \t]+(.+)/\1/c/ --regex-Foo=/set=[^;]+/\1/v/{icase} --regex-Man=/^\.TH[[:space:]]{1,}"([^"]{1,})".*/\1/t/{exclusive}{icase}{scope=push} --regex-Gdbinit=/^#//{exclusive} ``` -------------------------------- ### Defining Basic C Functions (Test 1.0 & 1.1) Source: https://github.com/universal-ctags/ctags/blob/master/Units/parser-restructuredtext.r/code-blocks.d/input.rst This snippet defines two simple C functions, `test1_0` and `test1_1`, both of which take no arguments and return an integer value of 0. These functions serve as basic examples of C function declarations and definitions. ```C int test1_0(void) { return 0; } int test1_1(void) { return 0; } ``` -------------------------------- ### Running Multiple Specific Unit Tests Source: https://github.com/universal-ctags/ctags/blob/master/docs/testing-parser.rst This command demonstrates how to execute multiple specific unit tests by providing a comma-separated list of test case names to the `UNITS` variable. ```Shell $ make units UNITS=vim-command,bug1856363.py ``` -------------------------------- ### Running Optscript Interpreter Source: https://github.com/universal-ctags/ctags/blob/master/docs/optscript.rst This snippet demonstrates how to launch the Optscript interpreter from the command line, showing the initial prompt 'OPT>' that indicates the interpreter is ready for input. ```console $ ./optsript OPT> ``` -------------------------------- ### Traditional Vi Tags File Examples Source: https://github.com/universal-ctags/ctags/blob/master/docs/man/tags.5.rst These examples demonstrate the content of a traditional Vi tags file. The first line points to the `main` function in `main.c` using a search pattern. The second line points to `DEBUG` in `defines.c` by line number. This format is fully compatible with older Vi versions. ```Tags File Format main main.c /^main(argc, argv)$/ DEBUG defines.c 89 ``` -------------------------------- ### Defining Shell Function x Source: https://github.com/universal-ctags/ctags/blob/master/Units/parser-markdown.r/simple-markdown.d/input.md This snippet defines a shell function named `x` that prints 'Hello, World!' to the standard output. It demonstrates basic shell function declaration and the `echo` command. ```sh # A COMMENT LINE in SHELL SYNTAX function x { echo 'Hello, World!' } ``` -------------------------------- ### Defining Variables in Optscript Source: https://github.com/universal-ctags/ctags/blob/master/docs/optscript.rst This example illustrates how to define and use variables in Optscript using the '/' prefix for names and the 'def' operator for assignment, followed by an arithmetic operation. ```console OPT> /x 2 def OPT> /y 3 def OPT> x y add = 5 ``` -------------------------------- ### Setting up Visual Studio Developer Command Prompt Source: https://github.com/universal-ctags/ctags/blob/master/docs/windows.rst This snippet demonstrates how to initialize the Visual Studio Developer Command Prompt from a standard Command Prompt by calling the `vcvarsall.bat` script. This setup is crucial for accessing Visual Studio's command-line tools like `nmake` and `msbuild` for building projects. The `x64` argument specifies the target architecture for the build environment. ```Batch call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64 ``` -------------------------------- ### ReStructuredText Line Continuation Example (Interpreted) Source: https://github.com/universal-ctags/ctags/blob/master/docs/testing-parser.rst This ReStructuredText snippet illustrates the result of interpreting a line continuation. The backslash and newline from the previous example are removed, and the subsequent line's content is appended, with its leading whitespace preserved, forming a single logical line. ```ReStructuredText .. code-block:: tags very long line ``` -------------------------------- ### Defining Unacceptable Ctags Parameters Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/lregex-kind-name.d/stdout-expected.txt These examples illustrate invalid `param` directive configurations in ctags. They highlight restrictions on parameter names, specifically disallowing names that start with a digit (e.g., '0name') or contain spaces (e.g., 'na me'). Such configurations will be rejected by ctags. ```Ctags Configuration param: |(.)|\1|x,0name| ``` ```Ctags Configuration param: |(.)|\1|x,0name,documents| ``` ```Ctags Configuration param: |(.)|\1|x,0name,0documents| ``` ```Ctags Configuration param: |(.)|\1|x,0name,doc uments| ``` ```Ctags Configuration param: |(.)|\1|x,na me| ``` ```Ctags Configuration param: |(.)|\1|x,na me,documents| ``` ```Ctags Configuration param: |(.)|\1|x,na me,0documents| ``` ```Ctags Configuration param: |(.)|\1|x,na me,doc uments| ``` -------------------------------- ### Building Universal Ctags with Autotools Source: https://github.com/universal-ctags/ctags/blob/master/docs/autotools.rst This snippet outlines the standard build process for Universal Ctags using Autotools. It involves cloning the repository, running `autogen.sh` to prepare the build system, configuring with an optional prefix, and then compiling and installing the software. Dependencies like `autoconf`, `automake`, and `pkg-config` are prerequisites. ```console $ git clone https://github.com/universal-ctags/ctags.git $ cd ctags $ ./autogen.sh $ ./configure --prefix=/where/you/want # defaults to /usr/local $ make $ make install # may require extra privileges depending on where to install ``` -------------------------------- ### Defining Acceptable Ctags Parameters Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/lregex-kind-name.d/stdout-expected.txt These examples demonstrate valid `param` directive configurations in ctags. They show how to define parameters with alphanumeric names, including those starting with letters and containing numbers, and how to include additional attributes like 'documents' or '0documents' or 'doc uments'. ```Ctags Configuration param: |(.)|\1|x,name| ``` ```Ctags Configuration param: |(.)|\1|x,name,documents| ``` ```Ctags Configuration param: |(.)|\1|x,name,0documents| ``` ```Ctags Configuration param: |(.)|\1|x,name,doc uments| ``` ```Ctags Configuration param: |(.)|\1|x,name0| ``` ```Ctags Configuration param: |(.)|\1|x,name0,documents| ``` ```Ctags Configuration param: |(.)|\1|x,name0,0documents| ``` ```Ctags Configuration param: |(.)|\1|x,name0,doc uments| ``` -------------------------------- ### List Tags Starting with 'myvar' and Print All Fields using readtags (Console) Source: https://github.com/universal-ctags/ctags/blob/master/docs/man/readtags.1.rst This command lists tags starting with 'myvar' and prints all available fields for each matching tag. The '-p' option specifies prefix matching, and '-ne' ensures all fields are displayed. ```console $ readtags -p -ne - myvar ``` -------------------------------- ### Storing Annotations in GDScript Source: https://github.com/universal-ctags/ctags/blob/master/docs/man/ctags-lang-gdscript.7.rst Demonstrates how GDScript annotations, starting with '@', are stored by the Universal Ctags parser in the 'annotations' field. This example shows `@export` for a variable and `@master` for a function. ```GDScript @export var s = "Hello" @master func f(msg): print(msg) ``` -------------------------------- ### Executing Expect Command (Tcl) Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/clear-aliases.d/stdout-expected.txt This snippet demonstrates the execution of the `expect` command, a powerful tool used for automating interactive applications and scripts, typically within a Tcl environment. ```Tcl expect ``` -------------------------------- ### Building Global Project Tag File with Ctags Source: https://github.com/universal-ctags/ctags/blob/master/old-docs/website/faq.html This command sequence navigates to the project root directory (`~/project`) and then executes `ctags` to build a global tag file. The `--file-scope=no` option excludes static tags, and `-R` recursively processes all files in descendant directories, creating a comprehensive tag file for the entire project. ```sh cd ~/project ctags --file-scope=no -R ``` -------------------------------- ### Demonstrating Default and Overridden `validator` Files Source: https://github.com/universal-ctags/ctags/blob/master/docs/testing-parser.rst This example illustrates how `validator` files define default validators for a category and how these can be overridden by `validator` files in subdirectories. It shows `puppet` as the default for `parser-puppetManifest.r` and `KNOWN-INVALIDATION` overriding it for `puppet-append.d`. ```Shell $ cat Units/parser-puppetManifest.r/validator puppet # cat Units/parser-puppetManifest.r/puppet-append.d/validator KNOWN-INVALIDATION ``` -------------------------------- ### Git Commit Message Example with Multiple Prefixes Source: https://github.com/universal-ctags/ctags/blob/master/docs/contributions.rst This git commit message demonstrates how to combine multiple prefixes with a comma when a change affects various parts of the source tree. The example shows a commit introducing a helper function that impacts `main`, `Flex`, `JavaScript`, and `SQL` parsers, and is also categorized as a `refactor` type change. ```git commit 64a05963c108af4b7832a2215006ff5cafcaaebb Author: Masatake YAMATO Date: Tue Mar 19 12:19:37 2019 +0900 main,Flex,JavaScript,SQL,refactor: introduce a helper function to skip two character sequence ... ``` -------------------------------- ### Defining a Basic Function in C Source: https://github.com/universal-ctags/ctags/blob/master/Units/parser-markdown.r/c-guest.d/input.md This snippet shows the basic syntax for defining a function in C. It declares a function named 'foo' that takes no arguments (void) and returns an integer. ```C int foo(void) { ``` -------------------------------- ### PCRE2 Non-Greedy Matching Example Source: https://github.com/universal-ctags/ctags/blob/master/docs/optlib.rst Demonstrates a non-greedy regular expression pattern using PCRE2 syntax. This pattern `foo.*?bar` will match the shortest possible string starting with 'foo' and ending with 'bar', contrasting with greedy matching behavior. ```ctags foo.*?bar ``` -------------------------------- ### Compiling AST Builder for Tiny-C on Windows with Visual Studio Source: https://github.com/universal-ctags/ctags/blob/master/misc/packcc/examples/ast-tinyc/README.md This snippet provides commands to compile the AST builder on Windows using Visual Studio Build Tools. It involves navigating to the project directory, creating a `build` directory, configuring with CMake, and then building the project using `MSBuild`. The `PACKCC` option specifies the path to the `packcc` command, which can be omitted if `packcc` is in the system's PATH. ```Shell cd \path\to\this_directory mkdir build cd build cmake -DPACKCC=\path\to\packcc .. MSBuild ALL_BUILD.vcxproj ``` -------------------------------- ### Building Universal Ctags with NMake Source: https://github.com/universal-ctags/ctags/blob/master/docs/windows.rst This command initiates a basic build of Universal Ctags using NMake and the `mk_mvc.mak` makefile. This is the simplest way to compile the project once the Visual Studio Developer Command Prompt is set up, requiring Visual Studio 2019 or later. ```Batch nmake -f mk_mvc.mak ``` -------------------------------- ### Viewing a `validator` File for a Test Case Source: https://github.com/universal-ctags/ctags/blob/master/docs/testing-parser.rst This command displays the content of a `validator` file, which specifies the external tool to be used for validating input files within a specific `Units` test directory. In this example, it shows the validator configured for `simple-json.d`. ```Shell $ cat Units/simple-json.d/validator ``` -------------------------------- ### List Tags Starting with 'mymethod' using readtags (Console) Source: https://github.com/universal-ctags/ctags/blob/master/docs/man/readtags.1.rst This command lists all tags from the 'tags' file that begin with 'mymethod'. The '-p' option ensures that only tags with the specified prefix are returned. ```console $ readtags -p - mymethod ``` -------------------------------- ### Configuring Library Build Type and Installation (CMake) Source: https://github.com/universal-ctags/ctags/blob/master/libreadtags/CMakeLists.txt This snippet conditionally builds the `readtags` library as either shared or static based on the `LIBREADTAGS_BUILD_SHARED` option. It sets target properties like `VERSION` and `SOVERSION` for shared libraries and defines installation paths for the library and its public header. An alias target `universal-ctags::readtags` is also created, and include directories are set. ```CMake if (LIBREADTAGS_BUILD_SHARED) message(STATUS "Building shared library") add_library(${PROJECT_NAME} SHARED readtags.c) set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${BUILD_VERSION} SOVERSION ${API_VERSION} PUBLIC_HEADER readtags.h ) install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib PUBLIC_HEADER DESTINATION include ) else () message(STATUS "Building static library") add_library(${PROJECT_NAME} STATIC readtags.c) install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION lib PUBLIC_HEADER DESTINATION include ) endif () add_library(universal-ctags::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) ``` -------------------------------- ### Generating AST for Valid C Code with Universal Ctags Source: https://github.com/universal-ctags/ctags/blob/master/misc/packcc/examples/ast-tinyc/README.md This command executes the `ast` tool from the Universal Ctags project to generate and print the Abstract Syntax Tree (AST) for a valid C source file, `example2.c`. It demonstrates the tool's capability to parse C code and represent its structure hierarchically. ```Shell ./ast ../inputs/example2.c ``` -------------------------------- ### ReStructuredText Line Continuation Example (Original) Source: https://github.com/universal-ctags/ctags/blob/master/docs/testing-parser.rst This ReStructuredText snippet shows how a backslash at the end of a line within a `tags` code block indicates line continuation. The subsequent newline and leading whitespace on the next line are ignored, effectively joining the lines. ```ReStructuredText .. code-block:: tags very long\ line ``` -------------------------------- ### Entering Comment State from Toplevel in Ctags Source: https://github.com/universal-ctags/ctags/blob/master/docs/optlib.rst This snippet shows the specific regex rules within the 'toplevel' table for handling the start of a block comment. The first rule matches '/*' and uses {tenter=comment} to push the current table ('toplevel') onto the stack and transition to the 'comment' table. The second rule matches any single character ('.') to advance the parser if no comment start is found. ```ctags --_mtable-regex-X=toplevel/\/\*//{tenter=comment} --_mtable-regex-X=toplevel/.// ``` -------------------------------- ### Starting Universal Ctags in Interactive Mode (Shell) Source: https://github.com/universal-ctags/ctags/blob/master/docs/interactive-mode.rst This example shows how to initiate Universal Ctags in interactive mode using the `--_interactive` flag. Upon startup, ctags emits a JSON object to stdout containing its program name and version, signaling the readiness of the interactive loop. ```Shell $ ctags --_interactive {"_type": "program", "name": "Universal Ctags", "version": "0.0.0"} ``` -------------------------------- ### Defining Sections and Key-Value Pairs in TOML Source: https://github.com/universal-ctags/ctags/blob/master/Units/parser-toml.r/run-as-guest-with-bom.d/input.md This TOML snippet defines two sections, `[g]` and `[m]`, each containing a single key-value pair. Section `[g]` assigns the string '/' to key 'a', and section `[m]` assigns an empty string to key 'b'. ```TOML [g] a = "/" [m] b = "" ``` -------------------------------- ### Validating JSON Input Files with `make validate-input` and `jq` Source: https://github.com/universal-ctags/ctags/blob/master/docs/testing-parser.rst This command validates test input files within the `Units` framework using specified external validators. In this example, it validates `simple-json.d/input.json` using the `jq` validator. The `VALIDATORS` variable accepts a comma-separated list of validators to run. ```Shell $ make validate-input VALIDATORS=jq ... Category: parser-json.r ------------------------------------------------------------ simple-json.d/input.json with jq valid Summary ------------------------------------------------------------ #valid: 1 #invalid: 0 #skipped (known invalidation) 0 #skipped (validator unavailable) 0 ``` -------------------------------- ### Building Global Tag File with Absolute Paths for `vi` Source: https://github.com/universal-ctags/ctags/blob/master/old-docs/website/faq.html This command sequence is an alternative to Step 2, specifically for `vi` users who require absolute paths in their tag files. It navigates to the project root and then executes `ctags --file-scope=no -R`, but crucially appends `` `pwd` `` to ensure that file paths within the generated tag file are absolute, making them correctly interpreted by standard `vi`. ```sh cd ~/project ctags --file-scope=no -R `pwd` ``` -------------------------------- ### Compiling AST Builder for Tiny-C on Unix-like OS Source: https://github.com/universal-ctags/ctags/blob/master/misc/packcc/examples/ast-tinyc/README.md This snippet provides commands to compile the AST builder on Unix-like operating systems using CMake and Make. It creates a `build` directory, configures the project with CMake, and then builds it using Make. The `PACKCC` option specifies the path to the `packcc` command, which can be omitted if `packcc` is in the system's PATH. ```Shell cd /path/to/this_directory mkdir build cd build cmake -DPACKCC=/path/to/packcc .. make ``` -------------------------------- ### Compiling AST Builder for Tiny-C on Windows with MinGW-w64 Source: https://github.com/universal-ctags/ctags/blob/master/misc/packcc/examples/ast-tinyc/README.md This snippet provides commands to compile the AST builder on Windows using MinGW-w64. It involves navigating to the project directory, creating a `build` directory, configuring with CMake using the 'MSYS Makefiles' generator, and then building the project using Make. The `PACKCC` option specifies the path to the `packcc` command, which can be omitted if `packcc` is in the system's PATH. ```Shell cd /path/to/this_directory mkdir build cd build cmake -G "MSYS Makefiles" -DPACKCC=/path/to/packcc .. make ``` -------------------------------- ### Example Pseudo-Tag: TAG_PROGRAM_NAME Source: https://github.com/universal-ctags/ctags/blob/master/docs/man/ctags-client-tools.7.rst Demonstrates the format of a basic pseudo-tag within a tags file. `!_TAG_PROGRAM_NAME` identifies the generator of the tags file, with 'Universal Ctags' as its value and '/Derived from Exuberant Ctags/' as a description. ```Text !_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/ ``` -------------------------------- ### Defining Procedures in Optscript Source: https://github.com/universal-ctags/ctags/blob/master/docs/optscript.rst This example demonstrates how to define a simple procedure (function) in Optscript using curly braces for the code block and the 'def' operator, then calling it with an argument. ```console OPT> /add5_and_print { 5 add = } def OPT> 4 add5_and_print 9 ``` -------------------------------- ### Building Universal Ctags with PEG Optimizer (pegof) Source: https://github.com/universal-ctags/ctags/blob/master/docs/autotools.rst This snippet illustrates the process of building Universal Ctags with the `pegof` PEG grammar optimizer. It involves verifying the presence and path of `ctags` and `pegof` directories, navigating into the `ctags` directory, and then running the `./configure` script with the `--with-pegof` option pointing to the `pegof` executable, followed by `make`. ```Shell ls -d ctags pegof ls -l pegof/build/pegof cd ctags ./configure --with-pegof=../pegof/build/pegof make ``` -------------------------------- ### Building AST Project with CMake Source: https://github.com/universal-ctags/ctags/blob/master/misc/packcc/examples/ast-tinyc/CMakeLists.txt This CMake script configures the build for an 'ast' executable. It specifies the minimum CMake version, defines the project, locates the `packcc` tool, and sets up a custom command to generate `parser.c` and `parser.h` from `parser.peg`. Finally, it defines the executable, sets C99 compliance, and includes necessary directories for compilation. ```CMake cmake_minimum_required(VERSION 3.2) project(ast) set(PACKCC packcc CACHE FILEPATH "Specify file path of packcc command.") add_custom_command( OUTPUT parser.c parser.h COMMAND ${PACKCC} ARGS -o parser ${CMAKE_CURRENT_SOURCE_DIR}/parser.peg DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/parser.peg VERBATIM ) add_executable(ast main.c parser.c system.c utility.c) target_compile_features(ast PRIVATE c_std_99) target_include_directories(ast BEFORE PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) ``` -------------------------------- ### C Structure and Function Prototype Definition Source: https://github.com/universal-ctags/ctags/blob/master/docs/reporting.rst Defines a `struct point` with integer members `x` and `y`, and declares a function `make_point` that returns a pointer to `struct point`. This snippet serves as an example input file (`foo.h`) to illustrate how Universal Ctags processes C code and the impact of default kind settings on tag generation. ```C struct point { int x, y; }; struct point *make_point(int x0, int y0); ``` -------------------------------- ### Building libreadtags with Autotools Source: https://github.com/universal-ctags/ctags/blob/master/libreadtags/README.md This snippet demonstrates the standard steps to build libreadtags using GNU Autotools. It first runs `autogen.sh` if present to generate build system files, then configures the project for compilation, and finally executes `make` to compile the library. ```shell test -e autogen.sh && ./autogen.sh ./configure make ``` -------------------------------- ### Example Input for 'single' Language Parser (C) Source: https://github.com/universal-ctags/ctags/blob/master/docs/optlib.rst This C code snippet demonstrates an input file for the `single` language parser. It contains a `main` function enclosed within `BEGIN_C<...>` and `>END_C` markers, which the `single` parser is configured to extract and pass to the C guest parser. ```C BEGIN_CEND_C ``` -------------------------------- ### Configuring, Building, and Testing libreadtags (CMake Standalone) Source: https://github.com/universal-ctags/ctags/blob/master/libreadtags/README.md This snippet outlines the process to configure, build, and run tests for libreadtags as a standalone CMake project. It sets up a release build with shared libraries, compiles the entire project, and then executes the CTest suite within the build directory. ```shell mkdir build cmake -DCMAKE_BUILD_TYPE=Release -DLIBREADTAGS_BUILD_SHARED=ON -S . -B build cmake --build build ctest --test-dir build ``` -------------------------------- ### Defining Acceptable Kind Names for ctags --regex-x Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/lregex-kind-name.d/stderr-expected.txt This snippet demonstrates various acceptable formats for defining kind names using the --regex-x option in ctags. Kind names must start with an alphabetic character but can contain alphanumeric characters, including digits, and can be followed by additional tags. These examples show valid combinations of kind names and optional tag fields. ```ctags configuration param: |(.)|\1|x,name| ``` ```ctags configuration param: |(.)|\1|x,name,documents| ``` ```ctags configuration param: |(.)|\1|x,name,0documents| ``` ```ctags configuration param: |(.)|\1|x,name,doc uments| ``` ```ctags configuration param: |(.)|\1|x,name0| ``` ```ctags configuration param: |(.)|\1|x,name0,documents| ``` ```ctags configuration param: |(.)|\1|x,name0,0documents| ``` ```ctags configuration param: |(.)|\1|x,name0,doc uments| ``` -------------------------------- ### Installing Universal Ctags via Homebrew on macOS Source: https://github.com/universal-ctags/ctags/blob/master/docs/osx.rst These shell commands facilitate the installation of Universal Ctags using Homebrew on macOS. The first command adds the official Universal Ctags tap, while the second command installs the latest development version from the head of the repository, as no stable releases are currently available. ```Shell brew tap universal-ctags/universal-ctags brew install --HEAD universal-ctags ``` -------------------------------- ### Automake/Make Parser Combination Example Source: https://github.com/universal-ctags/ctags/blob/master/docs/running-multi-parsers.rst This Make snippet illustrates how Automake-specific macros like `bin_PROGRAMS` are defined. While `bin_PROGRAMS` is a simple macro to the Make parser, the Automake parser recognizes `ctags` as a 'Program' kind, demonstrating how subparsers can extract more specific semantic information. ```Make bin_PROGRAMS = ctags ctags_CPPFLAGS = \ -I. \ -I$(srcdir) \ -I$(srcdir)/main ``` -------------------------------- ### Example Standard Markdown Code Block Source: https://github.com/universal-ctags/ctags/blob/master/docs/man/ctags-lang-rmarkdown.7.rst This snippet provides a concrete example of a standard Markdown code block, specifically demonstrating how to specify 'r' as the language for the code within the block. ```Markdown ```r ... ``` ``` -------------------------------- ### Listing Supported Ctags Roles for Verilog Source: https://github.com/universal-ctags/ctags/blob/master/docs/man/ctags-lang-verilog.7.rst Similar to the SystemVerilog example, this command lists the supported roles for the Verilog language in ctags, confirming that `m/module` is also a supported role for declaring instances in Verilog. ```console $ ./ctags --list-roles=Verilog #KIND(L/N) NAME ENABLED DESCRIPTION m/module decl on declaring instances ``` -------------------------------- ### Defining Unacceptable Kind Names (Starts with Non-Alphabetic) for ctags --regex-x Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/lregex-kind-name.d/stderr-expected.txt This snippet illustrates kind name definitions that are rejected by ctags due to starting with a non-alphabetic character (specifically, a digit). The accompanying error message 'A kind name doesn't start with an alphabetical character' indicates this violation. This highlights the requirement for kind names to begin with a letter. ```ctags configuration param: |(.)|\1|x,0name| ctags: A kind name doesn't start with an alphabetical character: '0name' in "--regex-x" option ``` ```ctags configuration param: |(.)|\1|x,0name,documents| ctags: A kind name doesn't start with an alphabetical character: '0name' in "--regex-x" option ``` ```ctags configuration param: |(.)|\1|x,0name,0documents| ctags: A kind name doesn't start with an alphabetical character: '0name' in "--regex-x" option ``` ```ctags configuration param: |(.)|\1|x,0name,doc uments| ctags: A kind name doesn't start with an alphabetical character: '0name' in "--regex-x" option ``` -------------------------------- ### Example Language-Specific Pseudo-Tag: TAG_KIND_DESCRIPTION!C Source: https://github.com/universal-ctags/ctags/blob/master/docs/man/ctags-client-tools.7.rst Illustrates a pseudo-tag extended with a language suffix (`!C`) to provide language-specific information. This example indicates that the 'function' kind for the C language is enabled, described as 'function definitions'. ```Text !_TAG_KIND_DESCRIPTION!C f,function /function definitions/ ``` -------------------------------- ### JSON Output Including Only Pattern Field Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/fixed-field-handling.d/stdout-expected.txt Example JSON output for a tag when only the 'pattern' field is explicitly included using `--fields=P`, showing just the regular expression pattern. ```JSON {"_type": "tag", "pattern": "/^void main(void) {}$/"} ``` -------------------------------- ### JSON Output Excluding Pattern Field Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/fixed-field-handling.d/stdout-expected.txt Example JSON output for a tag when the 'pattern' field is excluded using `--fields=-P`, displaying name, path, typeref, and kind. ```JSON {"_type": "tag", "name": "main", "path": "input.c", "typeref": "typename:void", "kind": "function"} ``` -------------------------------- ### Building Universal Ctags with NMake and Iconv Support Source: https://github.com/universal-ctags/ctags/blob/master/docs/windows.rst This command builds Universal Ctags using NMake, enabling iconv support. It requires specifying `WITH_ICONV=yes` to activate the feature and `ICONV_DIR` to point to the directory containing the iconv library, allowing for character encoding conversion capabilities. ```Batch nmake -f mk_mvc.mak WITH_ICONV=yes ICONV_DIR=path/to/iconvlib ``` -------------------------------- ### JSON Output Including Only Name Field Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/fixed-field-handling.d/stdout-expected.txt Example JSON output for a tag when only the 'name' field is explicitly included using `--fields=N`, resulting in a minimal tag object. ```JSON {"_type": "tag", "name": "main"} ``` -------------------------------- ### Handling C Prologue Exit and Promise Creation in Yacc Parser (C) Source: https://github.com/universal-ctags/ctags/blob/master/docs/internal.rst The `leave_c_prologue` function is called when the `%} `marker, signifying the end of a C code block, is found. It retrieves the current input line number as `c_end` and then invokes `makePromise`. This function schedules a guest parser (identified as 'C' for C language) to process the C code area, using the recorded start line (`cstart->input`), the end line (`c_end`), and source line (`cstart->source`), with byte offsets set to 0 for this example. ```C static void leave_c_prologue (const char *line CTAGS_ATTR_UNUSED, const regexMatch *matches CTAGS_ATTR_UNUSED, unsigned int count CTAGS_ATTR_UNUSED, void *data) { struct cStart *cstart = data; unsigned long c_end; c_end = getInputLineNumber (); makePromise ("C", cstart->input, 0, c_end, 0, cstart->source); } ``` -------------------------------- ### Man Page Test Execution Logic (Shell) Source: https://github.com/universal-ctags/ctags/blob/master/docs/testing-parser.rst This console script demonstrates the underlying shell commands executed by the `make man-test` target for each test case. It involves creating input and expected output files, running `ctags` with specified options, and then comparing the actual output with the expected output using `diff`. ```console $ echo > input. $ echo > output.tags $ ctags > actual.tags $ diff output.tags actual.tags ``` -------------------------------- ### JSON Output Including Only Input File Field Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/fixed-field-handling.d/stdout-expected.txt Example JSON output for a tag when only the 'input' (file path) field is explicitly included using `--fields=F`, showing just the path. ```JSON {"_type": "tag", "path": "input.c"} ``` -------------------------------- ### Defining Application-Level Constructs in Scheme Source: https://github.com/universal-ctags/ctags/blob/master/docs/running-multi-parsers.rst This Scheme code snippet demonstrates how an application defines its domain-specific concepts using Scheme's syntax. It shows the definition of a hash table (`agent-tables`), a class (``), and a macro (`define-agent`) to create application-level agents. The `define-agent` macro simplifies the creation of agent instances, associating them with rights and responsibilities. ```Scheme (define agent-tables (make-hash-table)) (define-class () ((rights :init-keyword :rights) (responsibilities :init-keyword :responsibilities))) (define-macro (define-agent name rights responsibilities) `(hash-table-put! agent-tables ',name (make :rights ',rights :responsibilities ',responsibilities))) (define-agent Bond (kill ...) ...) (define-agent Bourne ...) ``` -------------------------------- ### Ctags Description Starting with Curly Brace Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/kinddef.d/stdout-expected.txt Defines a kind 'x' where the description starts directly with an opening curly brace '{'. This tests the parser's robustness when the description begins with a special character in Ctags. ```Ctags Definition x kind yes no 0 NONE { ``` -------------------------------- ### CTags Description Starting with Curly Brace Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/broken-extradef.d/stdout-expected.txt This entry tests a description field that directly starts with an opening curly brace `{`. It defines an 'extra' field for the 'IMAGINARY' language with 'no' enabled status and a description that is just `{`. ```CTags Configuration - extra no IMAGINARY no { ``` -------------------------------- ### Enabling All Header Roles After Kind-Specific Disablement Source: https://github.com/universal-ctags/ctags/blob/master/Tmain/list-roles.d/stdout-expected.txt This configuration shows how to enable all roles for header kinds ('local' and 'system') after an implied prior disablement of all roles for that specific kind, restoring full header functionality. ```Ctags Configuration KIND(L/N) NAME ENABLED DESCRIPTION d/macro condition off used in part of #if/#ifdef/#elif conditions d/macro undef on undefined f/function foreigndecl on declared in foreign languages h/header local on local header h/header system on system header s/struct foreigndecl on declared in foreign languages ``` -------------------------------- ### Preparing Files for MSBuild (VS2013) Source: https://github.com/universal-ctags/ctags/blob/master/docs/windows.rst These commands copy necessary configuration and gnulib header files to their proper locations before initiating a build with MSBuild, specifically for Visual Studio 2013 projects. ```CMD copy win32\config_mvc.h config.h copy win32\gnulib_h\langinfo.h gnulib copy win32\gnulib_h\fnmatch.h gnulib ```