Skip to content

Commit 123588e

Browse files
authored
Merge pull request #3960 from masatake/main--foreign-fields
optlib: allow users to set fields and check extras defined in a foreign language
2 parents 23c6e36 + d87078d commit 123588e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1007
-99
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#LETTER NAME ENABLED LANGUAGE JSTYPE FIXED OP DESCRIPTION
2-
- boolfield no FIELDTEST --b no -- a field having boolean value
2+
- boolfield no FIELDTEST --b no rw a field having boolean value
33
- deffield no FIELDTEST s-- no -- a field that type is not specified
4-
- intfield no FIELDTEST -i- no -- a field having integer value
5-
- strboolfield no FIELDTEST s-b no -- a field having string value or false
6-
- strfield no FIELDTEST s-- no -- a field having string value
4+
- intfield no FIELDTEST -i- no rw a field having integer value
5+
- strboolfield no FIELDTEST s-b no rw a field having string value or false
6+
- strfield no FIELDTEST s-- no rw a field having string value
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#LETTER NAME DESCRIPTION
2-
- datatype=TYPE acceaptable datatype of the field ([str]|bool|int|str+bool)
2+
- datatype=TYPE acceaptable datatype of the field (str|bool|int|str+bool)

Tmain/list-fields-with-prefix.d/stdout-expected.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,24 @@ x UCTAGSxpath no NONE s-- no -- xpath for
3131
- UCTAGShowImported no Go s-- no -- how the package is imported ("inline" for `.' or "init" for `_')
3232
- UCTAGSpackage yes Go s-- no -- the real package specified by the package name
3333
- UCTAGSpackageName yes Go s-- no -- the name for referring the package
34-
- UCTAGSimplements yes Inko s-- no -- Trait being implemented
34+
- UCTAGSimplements yes Inko s-- no rw Trait being implemented
3535
- UCTAGSassignment yes LdScript s-- no -- how a value is assigned to the symbol
3636
- UCTAGSdefiner yes Lisp s-- no -- the name of the function or macro that defines the unknown/Y-kind object
3737
- UCTAGSsectionMarker no Markdown s-- no -- character used for declaring section(#, ##, =, or -)
3838
- UCTAGSwrapping yes Moose s-- no -- how a wrapper wrapping the method (around, after, or before)
3939
- UCTAGSlangid yes NSIS s-- no -- language identifier specified in (License)LangString commands
4040
- UCTAGScategory yes ObjectiveC s-- no -- category attached to the class
4141
- UCTAGSprotocols yes ObjectiveC s-- no -- protocols that the class (or category) confirms to
42-
- UCTAGShome yes Passwd s-- no -- home directory
43-
- UCTAGSshell yes Passwd s-- no -- login shell
42+
- UCTAGShome yes Passwd s-- no rw home directory
43+
- UCTAGSshell yes Passwd s-- no rw login shell
4444
- UCTAGSdecorators no Python s-- no -- decorators on functions and classes
4545
- UCTAGSnameref yes Python s-- no -- the original name for the tag
4646
- UCTAGSassignmentop no R s-- no -- operator for assignment
4747
- UCTAGSconstructor yes R s-- no -- function used for making value assigned to the nameattr tag
4848
- UCTAGSoverline no ReStructuredText --b no -- whether using overline & underline for declaring section
4949
- UCTAGSsectionMarker no ReStructuredText s-- no -- character used for declaring section
5050
- UCTAGSmixin yes Ruby s-- no -- how the class or module is mixed in (mixin:HOW:MODULE)
51+
- UCTAGSmodule yes SCSS s-- no rw the name of module behind the namespace
5152
- UCTAGSdefiner yes Scheme s-- no -- the name of the function or macro that defines the unknown/Y-kind object
5253
- UCTAGSparameter no SystemVerilog --b no -- parameter whose value can be overridden.
5354
- UCTAGStarget yes Thrift s-- no -- the target language specified at "namespace"

Tmain/list-fields.d/stdout-expected.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,24 @@ z kind no NONE s-- no r- [tags output] prepend "kind:" to k/ (or K/) field outpu
4949
- howImported no Go s-- no -- how the package is imported ("inline" for `.' or "init" for `_')
5050
- package yes Go s-- no -- the real package specified by the package name
5151
- packageName yes Go s-- no -- the name for referring the package
52-
- implements yes Inko s-- no -- Trait being implemented
52+
- implements yes Inko s-- no rw Trait being implemented
5353
- assignment yes LdScript s-- no -- how a value is assigned to the symbol
5454
- definer yes Lisp s-- no -- the name of the function or macro that defines the unknown/Y-kind object
5555
- sectionMarker no Markdown s-- no -- character used for declaring section(#, ##, =, or -)
5656
- wrapping yes Moose s-- no -- how a wrapper wrapping the method (around, after, or before)
5757
- langid yes NSIS s-- no -- language identifier specified in (License)LangString commands
5858
- category yes ObjectiveC s-- no -- category attached to the class
5959
- protocols yes ObjectiveC s-- no -- protocols that the class (or category) confirms to
60-
- home yes Passwd s-- no -- home directory
61-
- shell yes Passwd s-- no -- login shell
60+
- home yes Passwd s-- no rw home directory
61+
- shell yes Passwd s-- no rw login shell
6262
- decorators no Python s-- no -- decorators on functions and classes
6363
- nameref yes Python s-- no -- the original name for the tag
6464
- assignmentop no R s-- no -- operator for assignment
6565
- constructor yes R s-- no -- function used for making value assigned to the nameattr tag
6666
- overline no ReStructuredText --b no -- whether using overline & underline for declaring section
6767
- sectionMarker no ReStructuredText s-- no -- character used for declaring section
6868
- mixin yes Ruby s-- no -- how the class or module is mixed in (mixin:HOW:MODULE)
69+
- module yes SCSS s-- no rw the name of module behind the namespace
6970
- definer yes Scheme s-- no -- the name of the function or macro that defines the unknown/Y-kind object
7071
- parameter no SystemVerilog --b no -- parameter whose value can be overridden.
7172
- target yes Thrift s-- no -- the target language specified at "namespace"

Tmain/optscript.d/error-undefined-if-if.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ top| |bottom
44
Execution stack:
55
top| a {a} --if-- {true {a} if} --if-- |bottom
66
Dictionary stack:
7-
top| -dict:1- -dict:89- |bottom
7+
top| -dict:1- -dict:91- |bottom

Tmain/optscript.d/error-undefined-if.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ top| |bottom
44
Execution stack:
55
top| a {a} --if-- |bottom
66
Dictionary stack:
7-
top| -dict:1- -dict:89- |bottom
7+
top| -dict:1- -dict:91- |bottom
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public func foo(n, m);
2+
protected func bar(n);
3+
private func baz(n,...);
4+
STR:strset@iamowner
5+
STR:setsetempty@
6+
STR:notset
7+
Y:iamowner2=tagme2
8+
Z:tagme-z@iamowner-z
9+
eset:a
10+
enoset:b
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--langdef=knownz
2+
--kinddef-knownz=m,mark,makers
3+
4+
--_fielddef-knownz=owner,the owner of the markers{datatype=str}
5+
6+
--_fielddef-knownz=len,the length of owner string{datatype=int}
7+
--fields-knownz=+{len}
8+
--_fielddef-knownz=lenplus,the length of owner string + 1{datatype=int}
9+
--fields-knownz=+{lenplus}
10+
11+
--_fielddef-knownz=exported,whether the marker is exported or not{datatype=bool}
12+
--fields-knownz=+{exported}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright: 2025 Masatake YAMATO
2+
# License: GPL-2
3+
4+
. ../utils.sh
5+
6+
CTAGS=$1
7+
8+
V=
9+
# V=valgrind
10+
11+
is_feature_available "${CTAGS}" json
12+
13+
echo "# output: json"
14+
${V} ${CTAGS} --options=NONE --options=./knownz.ctags --sort=no --options=./unknownx.ctags \
15+
--fields=+l \
16+
--fields-unknownx=+'{protection}{signature}' \
17+
--fields-knownz=+'{owner}' \
18+
--output-format=json \
19+
-o - input.unknownx
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ctags: Notice: No options will be read from files or environment
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# output: json
2+
{"_type": "tag", "name": "foo", "path": "input.unknownx", "pattern": "/^public func foo(n, m);$/", "language": "unknownx", "kind": "func", "protection": "public ", "signature": "(n, m)"}
3+
{"_type": "tag", "name": "bar", "path": "input.unknownx", "pattern": "/^protected func bar(n);$/", "language": "unknownx", "kind": "func", "protection": "protected ", "signature": "(n)"}
4+
{"_type": "tag", "name": "baz", "path": "input.unknownx", "pattern": "/^private func baz(n,...);$/", "language": "unknownx", "kind": "func", "protection": "private ", "signature": "(n,...)"}
5+
{"_type": "tag", "name": "strset", "path": "input.unknownx", "pattern": "/^STR:strset@iamowner$/", "language": "knownz", "kind": "mark", "owner": "iamowner"}
6+
{"_type": "tag", "name": "setsetempty", "path": "input.unknownx", "pattern": "/^STR:setsetempty@$/", "language": "knownz", "kind": "mark", "owner": ""}
7+
{"_type": "tag", "name": "notset", "path": "input.unknownx", "pattern": "/^STR:notset$/", "language": "knownz", "kind": "mark"}
8+
{"_type": "tag", "name": "tagme2", "path": "input.unknownx", "pattern": "/^Y:iamowner2=tagme2$/", "language": "knownz", "kind": "mark", "owner": "iamowner2"}
9+
{"_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}
10+
{"_type": "tag", "name": "a", "path": "input.unknownx", "pattern": "/^eset:a$/", "language": "knownz", "kind": "mark", "exported": true}
11+
{"_type": "tag", "name": "b", "path": "input.unknownx", "pattern": "/^enoset:b$/", "language": "knownz", "kind": "mark"}
12+
{"_type": "tag", "name": "9_exported", "path": "input.unknownx", "pattern": "/^enoset:b$/", "language": "knownz", "kind": "mark"}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--langdef=unknownx{_foreignLanguage=knownz}
2+
--kinddef-unknownx=f,func,functions
3+
--map-unknownx=+.unknownx
4+
5+
--_fielddef-unknownx=protection,protections
6+
--_fielddef-unknownx=signature,signatures
7+
8+
--_prelude-unknownx={{
9+
/exported false def
10+
}}
11+
12+
--regex-unknownx=/^((public|protected|private) +)?func ([^\(]+)\((.*)\)/\3/f/{_field=protection:\1}{_field=signature:(\4)}
13+
--regex-unknownx=/^STR:([a-z]+)@([a-z]+)/\1/m/{_language=knownz}{_field=owner:\2}
14+
--regex-unknownx=/^STR:([a-z]+)@$/\1/m/{_language=knownz}{_field=owner:}
15+
--regex-unknownx=/^STR:([a-z]+)$/\1/m/{_language=knownz}
16+
--regex-unknownx=/^Y:([a-z0-9]+)=([a-z0-9]+)/\2/m/{_field=owner:\1}{_language=knownz}
17+
--regex-unknownx=/^Z:([-a-z]+)@([-a-z]+)/\1/m/{_language=knownz}{{
18+
. \2 knownz.owner:
19+
. :knownz.owner {
20+
. exch length knownz.len:
21+
} if
22+
. :knownz.len {
23+
1 add
24+
. exch knownz.lenplus:
25+
} if
26+
}}
27+
28+
--regex-unknownx=/^eset:([-a-z]+)/\1/m/{_language=knownz}{{
29+
/exported . def
30+
. true knownz.exported:
31+
}}
32+
33+
--regex-unknownx=/^enoset:([-a-z]+)/\1/m/{_language=knownz}{{
34+
. false knownz.exported:
35+
exported :knownz.exported and {
36+
mark exported 0 string cvs (_exported) _buildstring
37+
/knownz
38+
/mark
39+
1@ _foreigntag _commit pop
40+
} if
41+
}}
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
public func foo(n, m);
22
protected func bar(n);
33
private func baz(n,...);
4-
X:tagme@iamowner
4+
STR:strset@iamowner
5+
STR:setsetempty@
6+
STR:notset
57
Y:iamowner2=tagme2
8+
Z:tagme-z@iamowner-z
9+
eset:a
10+
enoset:b
11+
12+
stb:o
13+
stb:p-
14+
stb:q.something string
15+
x0:O
16+
x1:P
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
--langdef=knownz
22
--kinddef-knownz=m,mark,makers
33

4-
--_fielddef-knownz=owner,the owner of the markers
4+
--_fielddef-knownz=owner,the owner of the markers{datatype=str}
5+
6+
--_fielddef-knownz=len,the length of owner string{datatype=int}
7+
--fields-knownz=+{len}
8+
--_fielddef-knownz=lenplus,the length of owner string + 1{datatype=int}
9+
--fields-knownz=+{lenplus}
10+
11+
--_fielddef-knownz=exported,whether the marker is exported or not{datatype=bool}
12+
--fields-knownz=+{exported}
13+
14+
--_fielddef-knownz=stb,string or false{datatype=str+bool}
15+
--fields-knownz=+{stb}

Tmain/parser-specific-fields-for-foreign-lang.d/run.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ CTAGS=$1
88
V=
99
# V=valgrind
1010

11-
${V} ${CTAGS} --options=NONE --options=./knownz.ctags --options=./unknownx.ctags \
11+
echo "# output: tags"
12+
${V} ${CTAGS} --options=NONE --options=./knownz.ctags --sort=no --options=./unknownx.ctags \
1213
--fields=+l \
1314
--fields-unknownx=+'{protection}{signature}' \
1415
--fields-knownz=+'{owner}' \
1516
-o - input.unknownx
17+
18+
echo "# output: xref"
19+
${V} ${CTAGS} --options=NONE --options=./knownz.ctags --sort=no --options=./unknownx.ctags \
20+
--fields=+l \
21+
--fields-unknownx=+'{protection}{signature}' \
22+
--fields-knownz=+'{owner}' \
23+
-x --_xformat="%N %l / owner:%{knownz.owner},len:%{knownz.len},lenplus:%{knownz.lenplus},exported:%{knownz.exported},stb:%{knownz.stb} / %{unknownx.protection}%{unknownx.signature}" \
24+
-o - input.unknownx
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
11
ctags: Notice: No options will be read from files or environment
2+
/not-set
3+
false
4+
(something string)
5+
# Setting a string to a bool field
6+
true
7+
true
8+
# Setting a string to a int field
9+
true
10+
1
11+
ctags: Notice: No options will be read from files or environment
12+
/not-set
13+
false
14+
(something string)
15+
# Setting a string to a bool field
16+
true
17+
true
18+
# Setting a string to a int field
19+
true
20+
1
Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
1+
# output: tags
2+
foo input.unknownx /^public func foo(n, m);$/;" f language:unknownx protection:public signature:(n, m)
13
bar input.unknownx /^protected func bar(n);$/;" f language:unknownx protection:protected signature:(n)
24
baz input.unknownx /^private func baz(n,...);$/;" f language:unknownx protection:private signature:(n,...)
3-
foo input.unknownx /^public func foo(n, m);$/;" f language:unknownx protection:public signature:(n, m)
4-
tagme input.unknownx /^X:tagme@iamowner$/;" m language:knownz owner:iamowner
5+
strset input.unknownx /^STR:strset@iamowner$/;" m language:knownz owner:iamowner
6+
setsetempty input.unknownx /^STR:setsetempty@$/;" m language:knownz owner:
7+
notset input.unknownx /^STR:notset$/;" m language:knownz
58
tagme2 input.unknownx /^Y:iamowner2=tagme2$/;" m language:knownz owner:iamowner2
9+
tagme-z input.unknownx /^Z:tagme-z@iamowner-z$/;" m language:knownz owner:iamowner-z len:10 lenplus:11
10+
a input.unknownx /^eset:a$/;" m language:knownz exported:
11+
b input.unknownx /^enoset:b$/;" m language:knownz
12+
9_exported input.unknownx /^enoset:b$/;" m language:knownz
13+
o input.unknownx /^stb:o$/;" m language:knownz
14+
p input.unknownx /^stb:p-$/;" m language:knownz stb:
15+
q input.unknownx /^stb:q.something string$/;" m language:knownz stb:something string
16+
O input.unknownx /^x0:O$/;" m language:knownz exported:
17+
P input.unknownx /^x1:P$/;" m language:knownz len:1
18+
# output: xref
19+
foo unknownx / owner:,len:,lenplus:,exported:-,stb: / public (n, m)
20+
bar unknownx / owner:,len:,lenplus:,exported:-,stb: / protected (n)
21+
baz unknownx / owner:,len:,lenplus:,exported:-,stb: / private (n,...)
22+
strset knownz / owner:iamowner,len:,lenplus:,exported:-,stb: /
23+
setsetempty knownz / owner:,len:,lenplus:,exported:-,stb: /
24+
notset knownz / owner:,len:,lenplus:,exported:-,stb: /
25+
tagme2 knownz / owner:iamowner2,len:,lenplus:,exported:-,stb: /
26+
tagme-z knownz / owner:iamowner-z,len:10,lenplus:11,exported:-,stb: /
27+
a knownz / owner:,len:,lenplus:,exported:exported,stb: /
28+
b knownz / owner:,len:,lenplus:,exported:-,stb: /
29+
9_exported knownz / owner:,len:,lenplus:,exported:-,stb: /
30+
o knownz / owner:,len:,lenplus:,exported:-,stb: /
31+
p knownz / owner:,len:,lenplus:,exported:-,stb:- /
32+
q knownz / owner:,len:,lenplus:,exported:-,stb:something string /
33+
O knownz / owner:,len:,lenplus:,exported:exported,stb: /
34+
P knownz / owner:,len:1,lenplus:,exported:-,stb: /

Tmain/parser-specific-fields-for-foreign-lang.d/unknownx.ctags

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,70 @@
55
--_fielddef-unknownx=protection,protections
66
--_fielddef-unknownx=signature,signatures
77

8+
--_prelude-unknownx={{
9+
/exported false def
10+
}}
11+
812
--regex-unknownx=/^((public|protected|private) +)?func ([^\(]+)\((.*)\)/\3/f/{_field=protection:\1}{_field=signature:(\4)}
9-
--regex-unknownx=/^X:([a-z]+)@([a-z]+)/\1/m/{_language=knownz}{_field=owner:\2}
13+
--regex-unknownx=/^STR:([a-z]+)@([a-z]+)/\1/m/{_language=knownz}{_field=owner:\2}
14+
--regex-unknownx=/^STR:([a-z]+)@$/\1/m/{_language=knownz}{_field=owner:}
15+
--regex-unknownx=/^STR:([a-z]+)$/\1/m/{_language=knownz}
1016
--regex-unknownx=/^Y:([a-z0-9]+)=([a-z0-9]+)/\2/m/{_field=owner:\1}{_language=knownz}
17+
--regex-unknownx=/^Z:([-a-z]+)@([-a-z]+)/\1/m/{_language=knownz}{{
18+
. \2 knownz.owner:
19+
. :knownz.owner {
20+
. exch length knownz.len:
21+
} if
22+
. :knownz.len {
23+
1 add
24+
. exch knownz.lenplus:
25+
} if
26+
}}
27+
28+
--regex-unknownx=/^eset:([-a-z]+)/\1/m/{_language=knownz}{{
29+
/exported . def
30+
. true knownz.exported:
31+
}}
32+
33+
--regex-unknownx=/^enoset:([-a-z]+)/\1/m/{_language=knownz}{{
34+
. false knownz.exported:
35+
exported :knownz.exported and {
36+
mark exported 0 string cvs (_exported) _buildstring
37+
/knownz
38+
/mark
39+
1@ _foreigntag _commit pop
40+
} if
41+
}}
42+
43+
--regex-unknownx=/^stb:([a-z])$/\1/m/{_language=knownz}{{
44+
. :knownz.stb {
45+
==
46+
} {
47+
/not-set ==
48+
} ifelse
49+
}}
50+
--regex-unknownx=/^stb:([a-z])-$/\1/m/{_language=knownz}{_field=stb:}{{
51+
. :knownz.stb {
52+
==
53+
} {
54+
/not-set ==
55+
} ifelse
56+
}}
57+
--regex-unknownx=/^stb:([a-z])\.(.*)$/\1/m/{_language=knownz}{_field=stb:\2}{{
58+
. :knownz.stb {
59+
==
60+
} {
61+
/not-set ==
62+
} ifelse
63+
}}
64+
65+
--regex-unknownx=/^x0:([a-zA-Z])$/\1/m/{_language=knownz}{_field=exported:alpha}{{
66+
(# Setting a string to a bool field) =
67+
. :knownz.exported pstack clear
68+
}}
69+
70+
# Setting string to a int field
71+
--regex-unknownx=/^x1:([a-zA-Z])$/\1/m/{_language=knownz}{_field=len:alpha}{{
72+
(# Setting a string to a int field) =
73+
. :knownz.len pstack clear
74+
}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

0 commit comments

Comments
 (0)