Reputation: 1
I have a simple XML
-like filetype in which I have two kinds of tags. First, we find the Block tags, then inside them the in-lines.
A simplified example text is like the following
messing.dan
<B=003>/introduction/changelog.html
& Changelog &
------------------
Built with Sphinx using a theme provided by Read the Docs .
</B>
=====================
<B=004>/introduction/executingScripts.html
& Executing Scripts &
<I=1>
-----------------------
<I=2><I=3>
Installing scripts in the Scripts menu
</B>
=========================
As you can see, the in-lines are always nested inside . I ultimately want to parse both and , adding to the the scoping of which are they nested to
So following these examples I have
[Capturing variables in sequences] (https://docs.ctags.io/en/latest/optlib.html#capturing-variables-in-a-sequence) Example 3
dan.ctags
--langdef=dantags
--langmap=dantags:.dan
--kinddef-dantags=i,inline,inlines
--_tabledef-dantags=toplevel
--_tabledef-dantags=blocktab
--_tabledef-dantags=inlinetab
--_mtable-regex-dantags=toplevel/^<B=([a-zA-Z0-9]+)>.*\n/\1/b/{tenter=blocktab}
--_mtable-regex-dantags=toplevel/.//
--_mtable-regex-dantags=blocktab/<\/B>//{tleave}
--_mtable-regex-dantags=blocktab/<I=([a-zA-Z0-9]+)>/\1/i/
--_mtable-regex-dantags=blocktab/.//
Yet all I get in my file is just the first been parsed, that's it.
Upvotes: 0
Views: 14
Reputation: 1300
scope=
mtable-regex-flag may help you.
Ctags uses an internal stack to track scope.
Specify {scope=push}
when entering a scope.
Specify {scope=pop}
when leaving a scope.
Specify {scope=ref}
for assigning the scope at the top of the stack to a newly created tag. See also scope= in https://docs.ctags.io/en/latest/man/ctags-optlib.7.html
$ cat input.dan
<B=003>/introduction/changelog.html
& Changelog &
------------------
Built with Sphinx using a theme provided by Read the Docs .
</B>
=====================
<B=004>/introduction/executingScripts.html
& Executing Scripts &
<I=1>
-----------------------
<I=2><I=3>
Installing scripts in the Scripts menu
</B>
=========================
$ cat dan.ctags
--langdef=dantags
--map-dantags=.dan
--kinddef-dantags=b,block,blocks
--kinddef-dantags=i,inline,inlines
--_tabledef-dantags=toplevel
--_tabledef-dantags=blocktab
--_mtable-regex-dantags=toplevel/^<B=([a-zA-Z0-9]+)>[^\n]*\n/\1/b/{tenter=blocktab}{scope=push}
--_mtable-regex-dantags=toplevel/.//
--_mtable-regex-dantags=blocktab/<\/B>//{tleave}{scope=pop}
--_mtable-regex-dantags=blocktab/<I=([a-zA-Z0-9]+)>/\1/i/{scope=ref}
--_mtable-regex-dantags=blocktab/.//
$ ctags --options=NONE -o - --options=/tmp/dan.ctags /tmp/input.dan
ctags: Notice: No options will be read from files or environment
003 /tmp/input.dan /^<B=003>\/introduction\/changelog.html$/;" b
004 /tmp/input.dan /^<B=004>\/introduction\/executingScripts.html$/;" b
1 /tmp/input.dan /^<I=1>$/;" i block:004
2 /tmp/input.dan /^<I=2><I=3>$/;" i block:004
3 /tmp/input.dan /^<I=2><I=3>$/;" i block:004
What I changed from the original version.
[^\n]
instead of .
in the first regex in toplevel
table not for consuming whole the file contents{scope=...}
flagsblock
kind explicitlyinlinetab
because it is not used--map-<LANG>
option instead of --langmap
option--verbose
option is helpful to see how ctags consumes the input.
Upvotes: 0