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

optlib: allow users to set fields and check extras defined in a foreign language #3960

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Tmain/flags-fielddef-datatype.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#LETTER NAME ENABLED LANGUAGE JSTYPE FIXED OP DESCRIPTION
- boolfield no FIELDTEST --b no -- a field having boolean value
- boolfield no FIELDTEST --b no rw a field having boolean value
- deffield no FIELDTEST s-- no -- a field that type is not specified
- intfield no FIELDTEST -i- no -- a field having integer value
- strboolfield no FIELDTEST s-b no -- a field having string value or false
- strfield no FIELDTEST s-- no -- a field having string value
- intfield no FIELDTEST -i- no rw a field having integer value
- strboolfield no FIELDTEST s-b no rw a field having string value or false
- strfield no FIELDTEST s-- no rw a field having string value
2 changes: 1 addition & 1 deletion Tmain/list-fielddef-flags.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#LETTER NAME DESCRIPTION
- datatype=TYPE acceaptable datatype of the field ([str]|bool|int|str+bool)
- datatype=TYPE acceaptable datatype of the field (str|bool|int|str+bool)
7 changes: 4 additions & 3 deletions Tmain/list-fields-with-prefix.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,24 @@ x UCTAGSxpath no NONE s-- no -- xpath for
- UCTAGShowImported no Go s-- no -- how the package is imported ("inline" for `.' or "init" for `_')
- UCTAGSpackage yes Go s-- no -- the real package specified by the package name
- UCTAGSpackageName yes Go s-- no -- the name for referring the package
- UCTAGSimplements yes Inko s-- no -- Trait being implemented
- UCTAGSimplements yes Inko s-- no rw Trait being implemented
- UCTAGSassignment yes LdScript s-- no -- how a value is assigned to the symbol
- UCTAGSdefiner yes Lisp s-- no -- the name of the function or macro that defines the unknown/Y-kind object
- UCTAGSsectionMarker no Markdown s-- no -- character used for declaring section(#, ##, =, or -)
- UCTAGSwrapping yes Moose s-- no -- how a wrapper wrapping the method (around, after, or before)
- UCTAGSlangid yes NSIS s-- no -- language identifier specified in (License)LangString commands
- UCTAGScategory yes ObjectiveC s-- no -- category attached to the class
- UCTAGSprotocols yes ObjectiveC s-- no -- protocols that the class (or category) confirms to
- UCTAGShome yes Passwd s-- no -- home directory
- UCTAGSshell yes Passwd s-- no -- login shell
- UCTAGShome yes Passwd s-- no rw home directory
- UCTAGSshell yes Passwd s-- no rw login shell
- UCTAGSdecorators no Python s-- no -- decorators on functions and classes
- UCTAGSnameref yes Python s-- no -- the original name for the tag
- UCTAGSassignmentop no R s-- no -- operator for assignment
- UCTAGSconstructor yes R s-- no -- function used for making value assigned to the nameattr tag
- UCTAGSoverline no ReStructuredText --b no -- whether using overline & underline for declaring section
- UCTAGSsectionMarker no ReStructuredText s-- no -- character used for declaring section
- UCTAGSmixin yes Ruby s-- no -- how the class or module is mixed in (mixin:HOW:MODULE)
- UCTAGSmodule yes SCSS s-- no rw the name of module behind the namespace
- UCTAGSdefiner yes Scheme s-- no -- the name of the function or macro that defines the unknown/Y-kind object
- UCTAGSparameter no SystemVerilog --b no -- parameter whose value can be overridden.
- UCTAGStarget yes Thrift s-- no -- the target language specified at "namespace"
Expand Down
7 changes: 4 additions & 3 deletions Tmain/list-fields.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,24 @@ z kind no NONE s-- no r- [tags output] prepend "kind:" to k/ (or K/) field outpu
- howImported no Go s-- no -- how the package is imported ("inline" for `.' or "init" for `_')
- package yes Go s-- no -- the real package specified by the package name
- packageName yes Go s-- no -- the name for referring the package
- implements yes Inko s-- no -- Trait being implemented
- implements yes Inko s-- no rw Trait being implemented
- assignment yes LdScript s-- no -- how a value is assigned to the symbol
- definer yes Lisp s-- no -- the name of the function or macro that defines the unknown/Y-kind object
- sectionMarker no Markdown s-- no -- character used for declaring section(#, ##, =, or -)
- wrapping yes Moose s-- no -- how a wrapper wrapping the method (around, after, or before)
- langid yes NSIS s-- no -- language identifier specified in (License)LangString commands
- category yes ObjectiveC s-- no -- category attached to the class
- protocols yes ObjectiveC s-- no -- protocols that the class (or category) confirms to
- home yes Passwd s-- no -- home directory
- shell yes Passwd s-- no -- login shell
- home yes Passwd s-- no rw home directory
- shell yes Passwd s-- no rw login shell
- decorators no Python s-- no -- decorators on functions and classes
- nameref yes Python s-- no -- the original name for the tag
- assignmentop no R s-- no -- operator for assignment
- constructor yes R s-- no -- function used for making value assigned to the nameattr tag
- overline no ReStructuredText --b no -- whether using overline & underline for declaring section
- sectionMarker no ReStructuredText s-- no -- character used for declaring section
- mixin yes Ruby s-- no -- how the class or module is mixed in (mixin:HOW:MODULE)
- module yes SCSS s-- no rw the name of module behind the namespace
- definer yes Scheme s-- no -- the name of the function or macro that defines the unknown/Y-kind object
- parameter no SystemVerilog --b no -- parameter whose value can be overridden.
- target yes Thrift s-- no -- the target language specified at "namespace"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public func foo(n, m);
protected func bar(n);
private func baz(n,...);
STR:strset@iamowner
STR:setsetempty@
STR:notset
Y:iamowner2=tagme2
Z:tagme-z@iamowner-z
eset:a
enoset:b
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--langdef=knownz
--kinddef-knownz=m,mark,makers

--_fielddef-knownz=owner,the owner of the markers{datatype=str}

--_fielddef-knownz=len,the length of owner string{datatype=int}
--fields-knownz=+{len}
--_fielddef-knownz=lenplus,the length of owner string + 1{datatype=int}
--fields-knownz=+{lenplus}

--_fielddef-knownz=exported,whether the marker is exported or not{datatype=bool}
--fields-knownz=+{exported}
19 changes: 19 additions & 0 deletions Tmain/parser-specific-fields-for-foreign-lang-in-json.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright: 2025 Masatake YAMATO
# License: GPL-2

. ../utils.sh

CTAGS=$1

V=
# V=valgrind

is_feature_available "${CTAGS}" json

echo "# output: json"
${V} ${CTAGS} --options=NONE --options=./knownz.ctags --sort=no --options=./unknownx.ctags \
--fields=+l \
--fields-unknownx=+'{protection}{signature}' \
--fields-knownz=+'{owner}' \
--output-format=json \
-o - input.unknownx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ctags: Notice: No options will be read from files or environment
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# output: json
{"_type": "tag", "name": "foo", "path": "input.unknownx", "pattern": "/^public func foo(n, m);$/", "language": "unknownx", "kind": "func", "protection": "public ", "signature": "(n, m)"}
{"_type": "tag", "name": "bar", "path": "input.unknownx", "pattern": "/^protected func bar(n);$/", "language": "unknownx", "kind": "func", "protection": "protected ", "signature": "(n)"}
{"_type": "tag", "name": "baz", "path": "input.unknownx", "pattern": "/^private func baz(n,...);$/", "language": "unknownx", "kind": "func", "protection": "private ", "signature": "(n,...)"}
{"_type": "tag", "name": "strset", "path": "input.unknownx", "pattern": "/^STR:strset@iamowner$/", "language": "knownz", "kind": "mark", "owner": "iamowner"}
{"_type": "tag", "name": "setsetempty", "path": "input.unknownx", "pattern": "/^STR:setsetempty@$/", "language": "knownz", "kind": "mark", "owner": ""}
{"_type": "tag", "name": "notset", "path": "input.unknownx", "pattern": "/^STR:notset$/", "language": "knownz", "kind": "mark"}
{"_type": "tag", "name": "tagme2", "path": "input.unknownx", "pattern": "/^Y:iamowner2=tagme2$/", "language": "knownz", "kind": "mark", "owner": "iamowner2"}
{"_type": "tag", "name": "tagme-z", "path": "input.unknownx", "pattern": "/^Z:tagme-z@iamowner-z$/", "language": "knownz", "kind": "mark", "owner": "iamowner-z", "len": 10, "lenplus": 11}
{"_type": "tag", "name": "a", "path": "input.unknownx", "pattern": "/^eset:a$/", "language": "knownz", "kind": "mark", "exported": true}
{"_type": "tag", "name": "b", "path": "input.unknownx", "pattern": "/^enoset:b$/", "language": "knownz", "kind": "mark"}
{"_type": "tag", "name": "9_exported", "path": "input.unknownx", "pattern": "/^enoset:b$/", "language": "knownz", "kind": "mark"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--langdef=unknownx{_foreignLanguage=knownz}
--kinddef-unknownx=f,func,functions
--map-unknownx=+.unknownx

--_fielddef-unknownx=protection,protections
--_fielddef-unknownx=signature,signatures

--_prelude-unknownx={{
/exported false def
}}

--regex-unknownx=/^((public|protected|private) +)?func ([^\(]+)\((.*)\)/\3/f/{_field=protection:\1}{_field=signature:(\4)}
--regex-unknownx=/^STR:([a-z]+)@([a-z]+)/\1/m/{_language=knownz}{_field=owner:\2}
--regex-unknownx=/^STR:([a-z]+)@$/\1/m/{_language=knownz}{_field=owner:}
--regex-unknownx=/^STR:([a-z]+)$/\1/m/{_language=knownz}
--regex-unknownx=/^Y:([a-z0-9]+)=([a-z0-9]+)/\2/m/{_field=owner:\1}{_language=knownz}
--regex-unknownx=/^Z:([-a-z]+)@([-a-z]+)/\1/m/{_language=knownz}{{
. \2 knownz.owner:
. :knownz.owner {
. exch length knownz.len:
} if
. :knownz.len {
1 add
. exch knownz.lenplus:
} if
}}

--regex-unknownx=/^eset:([-a-z]+)/\1/m/{_language=knownz}{{
/exported . def
. true knownz.exported:
}}

--regex-unknownx=/^enoset:([-a-z]+)/\1/m/{_language=knownz}{{
. false knownz.exported:
exported :knownz.exported and {
mark exported 0 string cvs (_exported) _buildstring
/knownz
/mark
1@ _foreigntag _commit pop
} if
}}
13 changes: 12 additions & 1 deletion Tmain/parser-specific-fields-for-foreign-lang.d/input.unknownx
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
public func foo(n, m);
protected func bar(n);
private func baz(n,...);
X:tagme@iamowner
STR:strset@iamowner
STR:setsetempty@
STR:notset
Y:iamowner2=tagme2
Z:tagme-z@iamowner-z
eset:a
enoset:b

stb:o
stb:p-
stb:q.something string
x0:O
x1:P
13 changes: 12 additions & 1 deletion Tmain/parser-specific-fields-for-foreign-lang.d/knownz.ctags
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
--langdef=knownz
--kinddef-knownz=m,mark,makers

--_fielddef-knownz=owner,the owner of the markers
--_fielddef-knownz=owner,the owner of the markers{datatype=str}

--_fielddef-knownz=len,the length of owner string{datatype=int}
--fields-knownz=+{len}
--_fielddef-knownz=lenplus,the length of owner string + 1{datatype=int}
--fields-knownz=+{lenplus}

--_fielddef-knownz=exported,whether the marker is exported or not{datatype=bool}
--fields-knownz=+{exported}

--_fielddef-knownz=stb,string or false{datatype=str+bool}
--fields-knownz=+{stb}
11 changes: 10 additions & 1 deletion Tmain/parser-specific-fields-for-foreign-lang.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ CTAGS=$1
V=
# V=valgrind

${V} ${CTAGS} --options=NONE --options=./knownz.ctags --options=./unknownx.ctags \
echo "# output: tags"
${V} ${CTAGS} --options=NONE --options=./knownz.ctags --sort=no --options=./unknownx.ctags \
--fields=+l \
--fields-unknownx=+'{protection}{signature}' \
--fields-knownz=+'{owner}' \
-o - input.unknownx

echo "# output: xref"
${V} ${CTAGS} --options=NONE --options=./knownz.ctags --sort=no --options=./unknownx.ctags \
--fields=+l \
--fields-unknownx=+'{protection}{signature}' \
--fields-knownz=+'{owner}' \
-x --_xformat="%N %l / owner:%{knownz.owner},len:%{knownz.len},lenplus:%{knownz.lenplus},exported:%{knownz.exported},stb:%{knownz.stb} / %{unknownx.protection}%{unknownx.signature}" \
-o - input.unknownx
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
ctags: Notice: No options will be read from files or environment
/not-set
false
(something string)
# Setting a string to a bool field
true
true
# Setting a string to a int field
true
1
ctags: Notice: No options will be read from files or environment
/not-set
false
(something string)
# Setting a string to a bool field
true
true
# Setting a string to a int field
true
1
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# output: tags
foo input.unknownx /^public func foo(n, m);$/;" f language:unknownx protection:public signature:(n, m)
bar input.unknownx /^protected func bar(n);$/;" f language:unknownx protection:protected signature:(n)
baz input.unknownx /^private func baz(n,...);$/;" f language:unknownx protection:private signature:(n,...)
foo input.unknownx /^public func foo(n, m);$/;" f language:unknownx protection:public signature:(n, m)
tagme input.unknownx /^X:tagme@iamowner$/;" m language:knownz owner:iamowner
strset input.unknownx /^STR:strset@iamowner$/;" m language:knownz owner:iamowner
setsetempty input.unknownx /^STR:setsetempty@$/;" m language:knownz owner:
notset input.unknownx /^STR:notset$/;" m language:knownz
tagme2 input.unknownx /^Y:iamowner2=tagme2$/;" m language:knownz owner:iamowner2
tagme-z input.unknownx /^Z:tagme-z@iamowner-z$/;" m language:knownz owner:iamowner-z len:10 lenplus:11
a input.unknownx /^eset:a$/;" m language:knownz exported:
b input.unknownx /^enoset:b$/;" m language:knownz
9_exported input.unknownx /^enoset:b$/;" m language:knownz
o input.unknownx /^stb:o$/;" m language:knownz
p input.unknownx /^stb:p-$/;" m language:knownz stb:
q input.unknownx /^stb:q.something string$/;" m language:knownz stb:something string
O input.unknownx /^x0:O$/;" m language:knownz exported:
P input.unknownx /^x1:P$/;" m language:knownz len:1
# output: xref
foo unknownx / owner:,len:,lenplus:,exported:-,stb: / public (n, m)
bar unknownx / owner:,len:,lenplus:,exported:-,stb: / protected (n)
baz unknownx / owner:,len:,lenplus:,exported:-,stb: / private (n,...)
strset knownz / owner:iamowner,len:,lenplus:,exported:-,stb: /
setsetempty knownz / owner:,len:,lenplus:,exported:-,stb: /
notset knownz / owner:,len:,lenplus:,exported:-,stb: /
tagme2 knownz / owner:iamowner2,len:,lenplus:,exported:-,stb: /
tagme-z knownz / owner:iamowner-z,len:10,lenplus:11,exported:-,stb: /
a knownz / owner:,len:,lenplus:,exported:exported,stb: /
b knownz / owner:,len:,lenplus:,exported:-,stb: /
9_exported knownz / owner:,len:,lenplus:,exported:-,stb: /
o knownz / owner:,len:,lenplus:,exported:-,stb: /
p knownz / owner:,len:,lenplus:,exported:-,stb:- /
q knownz / owner:,len:,lenplus:,exported:-,stb:something string /
O knownz / owner:,len:,lenplus:,exported:exported,stb: /
P knownz / owner:,len:1,lenplus:,exported:-,stb: /
66 changes: 65 additions & 1 deletion Tmain/parser-specific-fields-for-foreign-lang.d/unknownx.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,70 @@
--_fielddef-unknownx=protection,protections
--_fielddef-unknownx=signature,signatures

--_prelude-unknownx={{
/exported false def
}}

--regex-unknownx=/^((public|protected|private) +)?func ([^\(]+)\((.*)\)/\3/f/{_field=protection:\1}{_field=signature:(\4)}
--regex-unknownx=/^X:([a-z]+)@([a-z]+)/\1/m/{_language=knownz}{_field=owner:\2}
--regex-unknownx=/^STR:([a-z]+)@([a-z]+)/\1/m/{_language=knownz}{_field=owner:\2}
--regex-unknownx=/^STR:([a-z]+)@$/\1/m/{_language=knownz}{_field=owner:}
--regex-unknownx=/^STR:([a-z]+)$/\1/m/{_language=knownz}
--regex-unknownx=/^Y:([a-z0-9]+)=([a-z0-9]+)/\2/m/{_field=owner:\1}{_language=knownz}
--regex-unknownx=/^Z:([-a-z]+)@([-a-z]+)/\1/m/{_language=knownz}{{
. \2 knownz.owner:
. :knownz.owner {
. exch length knownz.len:
} if
. :knownz.len {
1 add
. exch knownz.lenplus:
} if
}}

--regex-unknownx=/^eset:([-a-z]+)/\1/m/{_language=knownz}{{
/exported . def
. true knownz.exported:
}}

--regex-unknownx=/^enoset:([-a-z]+)/\1/m/{_language=knownz}{{
. false knownz.exported:
exported :knownz.exported and {
mark exported 0 string cvs (_exported) _buildstring
/knownz
/mark
1@ _foreigntag _commit pop
} if
}}

--regex-unknownx=/^stb:([a-z])$/\1/m/{_language=knownz}{{
. :knownz.stb {
==
} {
/not-set ==
} ifelse
}}
--regex-unknownx=/^stb:([a-z])-$/\1/m/{_language=knownz}{_field=stb:}{{
. :knownz.stb {
==
} {
/not-set ==
} ifelse
}}
--regex-unknownx=/^stb:([a-z])\.(.*)$/\1/m/{_language=knownz}{_field=stb:\2}{{
. :knownz.stb {
==
} {
/not-set ==
} ifelse
}}

--regex-unknownx=/^x0:([a-zA-Z])$/\1/m/{_language=knownz}{_field=exported:alpha}{{
(# Setting a string to a bool field) =
. :knownz.exported pstack clear
}}

# Setting string to a int field
--regex-unknownx=/^x1:([a-zA-Z])$/\1/m/{_language=knownz}{_field=len:alpha}{{
(# Setting a string to a int field) =
. :knownz.len pstack clear
}}
8 changes: 4 additions & 4 deletions Units/parser-scss.r/use.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
X/y input.scss /^@use "X\/y";$/;" M roles:used
y input.scss /^@use "X\/y";$/;" n roles:def
y input.scss /^@use "X\/y";$/;" n roles:def module:X/y
Z input.scss /^@use "Z";$/;" M roles:used
Z input.scss /^@use "Z";$/;" n roles:def
Z input.scss /^@use "Z";$/;" n roles:def module:Z
A input.scss /^@use "A" as NS;$/;" M roles:used
NS input.scss /^@use "A" as NS;$/;" n roles:def
NS input.scss /^@use "A" as NS;$/;" n roles:def module:A
B/ input.scss /^@use "B\/";$/;" M roles:used
C/d/e input.scss /^@use 'C\/d\/e';$/;" M roles:used
e input.scss /^@use 'C\/d\/e';$/;" n roles:def
e input.scss /^@use 'C\/d\/e';$/;" n roles:def module:C/d/e
P/q input.scss /^@use 'P\/q' as *;$/;" M roles:used
1 change: 1 addition & 0 deletions docs/man/ctags-lang-scss.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Change since "0.0"

* New kind ``module`` and new role ``used`` of the ``module`` kind
* New kind ``namespace``
* New field ``module``

SEE ALSO
--------
Expand Down
Loading
Loading