Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dsl: extend #/../ operator to be able to extract a matched group in the pattern #3768

Merged

Conversation

masatake
Copy link
Member

@masatake masatake commented Jul 6, 2023

(#/..(...).../ string group) returns nth GROUP of the pattern
match. If the STRING doesn't match to the pattern, "", an empty string
is returned.

(#/..(...).../ string group fallback) does the same as
(#/..(...).../ string group) when matching. The expression returns
FALLBACK unless matching.

This extension is useful for generating C code with readtags.

An exapmle session:

  $ cat /tmp/bar.c
  enum {
    good_cat, bad_dog, bad_cat, good_dog,
  };
  $ ./ctags -o - /tmp/bar.c --extras=-p
  __anon764ae3fa0103    /tmp/bar.c      /^enum {$/;"    g       file:
  bad_cat       /tmp/bar.c      /^  good_cat, bad_dog, bad_cat, good_dog,$/;"   e       enum:__anon764ae3fa0103 file:
  bad_dog       /tmp/bar.c      /^  good_cat, bad_dog, bad_cat, good_dog,$/;"   e       enum:__anon764ae3fa0103 file:
  good_cat      /tmp/bar.c      /^  good_cat, bad_dog, bad_cat, good_dog,$/;"   e       enum:__anon764ae3fa0103 file:
  good_dog      /tmp/bar.c      /^  good_cat, bad_dog, bad_cat, good_dog,$/;"   e       enum:__anon764ae3fa0103 file:
  $ ./ctags -o - /tmp/bar.c | ./readtags -t - -F '(list (#/(good_|bad_)(.*)/ $name 2 "bird, the fallback") #t)' -l
  bird, the fallback
  cat
  dog
  cat
  dog
  • consider the case if a wrong group number is given
  • add a test case for the above item
  • write this to ctags-client-tools.rst.in

@codecov
Copy link

codecov bot commented Jul 6, 2023

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (c134547) 85.02% compared to head (3b59095) 85.05%.

Files Patch % Lines
dsl/dsl.c 60.00% 12 Missing ⚠️
dsl/es.c 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3768      +/-   ##
==========================================
+ Coverage   85.02%   85.05%   +0.02%     
==========================================
  Files         228      228              
  Lines       53901    53941      +40     
==========================================
+ Hits        45832    45880      +48     
+ Misses       8069     8061       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@masatake masatake added this to the 6.1 milestone Dec 9, 2023
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
…tching

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
…he pattern

(#/..(...).../ string group) returns nth GROUP of the pattern
match. If the STRING doesn't match to the pattern, "", an empty string
is returned.

(#/..(...).../ string group fallback) does the same as
(#/..(...).../ string group) when matching. The expression returns
FALLBACK unless matching.

This extension is useful for generating C code with readtags.

An exapmle session:

  $ cat /tmp/bar.c
  enum {
    good_cat, bad_dog, bad_cat, good_dog,
  };
  $ ./ctags -o - /tmp/bar.c --extras=-p
  __anon764ae3fa0103	/tmp/bar.c	/^enum {$/;"	g	file:
  bad_cat	/tmp/bar.c	/^  good_cat, bad_dog, bad_cat, good_dog,$/;"	e	enum:__anon764ae3fa0103	file:
  bad_dog	/tmp/bar.c	/^  good_cat, bad_dog, bad_cat, good_dog,$/;"	e	enum:__anon764ae3fa0103	file:
  good_cat	/tmp/bar.c	/^  good_cat, bad_dog, bad_cat, good_dog,$/;"	e	enum:__anon764ae3fa0103	file:
  good_dog	/tmp/bar.c	/^  good_cat, bad_dog, bad_cat, good_dog,$/;"	e	enum:__anon764ae3fa0103	file:
  $ ./ctags -o - /tmp/bar.c | ./readtags -t - -F '(list (#/(good_|bad_)(.*)/ $name 2 "bird, the fallback") #t)' -l
  cat
  dog
  cat
  dog

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
@masatake masatake force-pushed the readtags--regex-group-extraction branch from 90a8b5f to 3b59095 Compare December 9, 2023 19:53
@masatake masatake merged commit e9afc80 into universal-ctags:master Dec 9, 2023
43 of 46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant