universal-ctags / ctags

A maintained ctags implementation
https://ctags.io
GNU General Public License v2.0
6.39k stars 618 forks source link

Tags with whitespace \s on a character class not been recognised #3938

Closed freddieventura closed 4 months ago

freddieventura commented 4 months ago
$ ctags --version
Universal Ctags 6.1.0(b44fba3), Copyright (C) 2015-2023 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Jan 24 2024, 05:50:37
  URL: https://ctags.io/
  Output version: 0.0
  Optional compiled features: +wildcards, +regex, +gnulib_regex, +iconv, +option-directory, +xpath, +json, +interactive, +yaml, +packcc, +optscript

I have the following ruleset

$ cat aidan.ctags
--langdef=aidantags
--langmap=aidantags:.aidan
--kinddef-aidantags=t,topic,topics
--kinddef-aidantags=p,property,properties
--kinddef-aidantags=m,method,methods
--regex-aidantags=/^#\s([A-Za-z0-9\s]*)\s#$/\1/t/

For a text file that simplified looks like this

 © Copyright 2013 Adobe Systems Incorporated. Revision  91df9514 .

Built with Sphinx using a theme provided by Read the Docs .
# TextFont #
 _____         _   _____           _    
|_   _|____  _| |_|  ___|__  _ __ | |_  
  | |/ _ \ \/ / __| |_ / _ \| '_ \| __| 
  | |  __/>  <| |_|  _| (_) | | | | |_  
  |_|\___/_/\_\\__|_|  \___/|_| |_|\__| 

TextFont

-   Properties
    -   TextFont.family
    -   TextFont.name
    -   TextFont.parent
    -   TextFont.style
    -   TextFont.typename
-   Example
    -   Setting the font of text
-   
-   TextFont
-   Edit on GitHub

------------------------------------------------------------------------

(...)
Built with Sphinx using a theme provided by Read the Docs .
# Dynamic Objects #
 ____                              _         ___  _     _           _        
|  _ \ _   _ _ __   __ _ _ __ ___ (_) ___   / _ \| |__ (_) ___  ___| |_ ___  
| | | | | | | '_ \ / _` | '_ ` _ \| |/ __| | | | | '_ \| |/ _ \/ __| __/ __| 
| |_| | |_| | | | | (_| | | | | | | | (__  | |_| | |_) | |  __/ (__| |_\__ \ 
|____/ \__, |_| |_|\__,_|_| |_| |_|_|\___|  \___/|_.__// |\___|\___|\__|___/ 
       |___/                                         |__/                    
Dynamic Objects
-   
-   Dynamic Objects
-   Edit on GitHub

------------------------------------------------------------------------

Dynamic Objects #

I am trying to match those tags that I have created for each topic entry ^# \s\w*\s#$

But some of them are multiword , so I need to have a custom character class such as [A-Za-z\s]

Upon using that configuration I can get is

$ ctags --options=NONE --options=./aidan.ctags -f ./tags head.aidan
ctags: Notice: No options will be read from files or environment
$ cat tags
!_TAG_EXTRA_DESCRIPTION anonymous       /Include tags for non-named objects like lambda/
!_TAG_EXTRA_DESCRIPTION fileScope       /Include tags of file scope/
!_TAG_EXTRA_DESCRIPTION pseudo  /Include pseudo tags/
!_TAG_EXTRA_DESCRIPTION subparser       /Include tags generated by subparsers/
!_TAG_FIELD_DESCRIPTION epoch   /the last modified time of the input file (only for F\/file kind tag)/
!_TAG_FIELD_DESCRIPTION file    /File-restricted scoping/
!_TAG_FIELD_DESCRIPTION input   /input file/
!_TAG_FIELD_DESCRIPTION name    /tag name/
!_TAG_FIELD_DESCRIPTION pattern /pattern/
!_TAG_FIELD_DESCRIPTION typeref /Type and name of a variable or typedef/
!_TAG_FILE_FORMAT       2       /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED       1       /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_KIND_DESCRIPTION!aidantags        m,method        /methods/
!_TAG_KIND_DESCRIPTION!aidantags        p,property      /properties/
!_TAG_KIND_DESCRIPTION!aidantags        t,topic /topics/
!_TAG_OUTPUT_EXCMD      mixed   /number, pattern, mixed, or combineV2/
!_TAG_OUTPUT_FILESEP    slash   /slash or backslash/
!_TAG_OUTPUT_MODE       u-ctags /u-ctags or e-ctags/
!_TAG_OUTPUT_VERSION    0.0     /current.age/
!_TAG_PARSER_VERSION!aidantags  0.0     /current.age/
!_TAG_PATTERN_LENGTH_LIMIT      96      /0 for no limit/
!_TAG_PROC_CWD  /home/fakuve/baul-documents/vim-dan/ai/ //
!_TAG_PROGRAM_AUTHOR    Universal Ctags Team    //
!_TAG_PROGRAM_NAME      Universal Ctags /Derived from Exuberant Ctags/
!_TAG_PROGRAM_URL       https://ctags.io/       /official site/
!_TAG_PROGRAM_VERSION   6.1.0   /b44fba3/
TextFont        head.aidan      /^# TextFont #$/;"      t

Is not matching against those multiword tags , despite this regex been correct (I have used it on regex101.com and it works

Should you want to check against the actual file

curl https://termbin.com/a345

masatake commented 4 months ago

In ctags, [\s] matches \ or s. For matching whitespace, use [ \t] or [[:space:]]. So the option should be:

--regex-aidantags=/^#\s([A-Za-z0-9[:space:]]*)\s#$/\1/t/

(the pattern had a typo. edited).

freddieventura commented 4 months ago

Thank you , it worked