diff --git a/components/prism-csharp.js b/components/prism-csharp.js index 87547ce795..b20f86d4d6 100644 --- a/components/prism-csharp.js +++ b/components/prism-csharp.js @@ -47,7 +47,7 @@ typeDeclaration: 'class enum interface record struct', // contextual keywords // ("var" and "dynamic" are missing because they are used like types) - contextual: 'add alias and ascending async await by descending from(?=\\s*(?:\\w|$)) get global group into init(?=\\s*;) join let nameof not notnull on or orderby partial remove select set unmanaged value when where', + contextual: 'add alias and ascending async await by descending from(?=\\s*(?:\\w|$)) get global group into init(?=\\s*;) join let nameof not notnull on or orderby partial remove select set unmanaged value when where with(?=\\s*{)', // all other keywords other: 'abstract as base break case catch checked const continue default delegate do else event explicit extern finally fixed for foreach goto if implicit in internal is lock namespace new null operator out override params private protected public readonly ref return sealed sizeof stackalloc static switch this throw try typeof unchecked unsafe using virtual volatile while yield' }; @@ -158,7 +158,7 @@ { // Variable, field and parameter declaration // (Foo bar, Bar baz, Foo[,,] bay, Foo> bax) - pattern: re(/\b<<0>>(?=\s+(?!<<1>>)<<2>>(?:\s*[=,;:{)\]]|\s+(?:in|when)\b))/.source, [typeExpression, nonContextualKeywords, name]), + pattern: re(/\b<<0>>(?=\s+(?!<<1>>|with\s*\{)<<2>>(?:\s*[=,;:{)\]]|\s+(?:in|when)\b))/.source, [typeExpression, nonContextualKeywords, name]), inside: typeInside } ], @@ -239,18 +239,24 @@ // class Foo : Bar, IList // where F : Bar, IList pattern: re( - /\b((?:<<0>>\s+<<1>>|where\s+<<2>>)\s*:\s*)(?:<<3>>|<<4>>)(?:\s*,\s*(?:<<3>>|<<4>>))*(?=\s*(?:where|[{;]|=>|$))/.source, - [typeDeclarationKeywords, genericName, name, typeExpression, keywords.source] + /\b((?:<<0>>\s+<<1>>|record\s+<<1>>\s*<<5>>|where\s+<<2>>)\s*:\s*)(?:<<3>>|<<4>>|<<1>>\s*<<5>>|<<6>>)(?:\s*,\s*(?:<<3>>|<<4>>|<<6>>))*(?=\s*(?:where|[{;]|=>|$))/.source, + [typeDeclarationKeywords, genericName, name, typeExpression, keywords.source, nestedRound, /\bnew\s*\(\s*\)/.source] ), lookbehind: true, inside: { + 'record-arguments': { + pattern: re(/(^(?!new\s*\()<<0>>\s*)<<1>>/.source, [genericName, nestedRound]), + lookbehind: true, + greedy: true, + inside: Prism.languages.csharp + }, 'keyword': keywords, 'class-name': { pattern: RegExp(typeExpression), greedy: true, inside: typeInside }, - 'punctuation': /,/ + 'punctuation': /[,()]/ } }, 'preprocessor': { diff --git a/components/prism-csharp.min.js b/components/prism-csharp.min.js index 650c0e7778..f691792318 100644 --- a/components/prism-csharp.min.js +++ b/components/prism-csharp.min.js @@ -1 +1 @@ -!function(s){function a(e,s){return e.replace(/<<(\d+)>>/g,function(e,n){return"(?:"+s[+n]+")"})}function t(e,n,s){return RegExp(a(e,n),s||"")}function e(e,n){for(var s=0;s>/g,function(){return"(?:"+e+")"});return e.replace(/<>/g,"[^\\s\\S]")}var n="bool byte char decimal double dynamic float int long object sbyte short string uint ulong ushort var void",i="class enum interface record struct",r="add alias and ascending async await by descending from(?=\\s*(?:\\w|$)) get global group into init(?=\\s*;) join let nameof not notnull on or orderby partial remove select set unmanaged value when where",o="abstract as base break case catch checked const continue default delegate do else event explicit extern finally fixed for foreach goto if implicit in internal is lock namespace new null operator out override params private protected public readonly ref return sealed sizeof stackalloc static switch this throw try typeof unchecked unsafe using virtual volatile while yield";function l(e){return"\\b(?:"+e.trim().replace(/ /g,"|")+")\\b"}var d=l(i),p=RegExp(l(n+" "+i+" "+r+" "+o)),c=l(i+" "+r+" "+o),u=l(n+" "+i+" "+o),g=e("<(?:[^<>;=+\\-*/%&|^]|<>)*>",2),b=e("\\((?:[^()]|<>)*\\)",2),h="@?\\b[A-Za-z_]\\w*\\b",f=a("<<0>>(?:\\s*<<1>>)?",[h,g]),m=a("(?!<<0>>)<<1>>(?:\\s*\\.\\s*<<1>>)*",[c,f]),k="\\[\\s*(?:,\\s*)*\\]",y=a("<<0>>(?:\\s*(?:\\?\\s*)?<<1>>)*(?:\\s*\\?)?",[m,k]),w=a("(?:<<0>>|<<1>>)(?:\\s*(?:\\?\\s*)?<<2>>)*(?:\\s*\\?)?",[a("\\(<<0>>+(?:,<<0>>+)+\\)",[a("[^,()<>[\\];=+\\-*/%&|^]|<<0>>|<<1>>|<<2>>",[g,b,k])]),m,k]),v={keyword:p,punctuation:/[<>()?,.:[\]]/},x="'(?:[^\r\n'\\\\]|\\\\.|\\\\[Uux][\\da-fA-F]{1,8})'",$='"(?:\\\\.|[^\\\\"\r\n])*"';s.languages.csharp=s.languages.extend("clike",{string:[{pattern:t("(^|[^$\\\\])<<0>>",['@"(?:""|\\\\[^]|[^\\\\"])*"(?!")']),lookbehind:!0,greedy:!0},{pattern:t("(^|[^@$\\\\])<<0>>",[$]),lookbehind:!0,greedy:!0},{pattern:RegExp(x),greedy:!0,alias:"character"}],"class-name":[{pattern:t("(\\busing\\s+static\\s+)<<0>>(?=\\s*;)",[m]),lookbehind:!0,inside:v},{pattern:t("(\\busing\\s+<<0>>\\s*=\\s*)<<1>>(?=\\s*;)",[h,w]),lookbehind:!0,inside:v},{pattern:t("(\\busing\\s+)<<0>>(?=\\s*=)",[h]),lookbehind:!0},{pattern:t("(\\b<<0>>\\s+)<<1>>",[d,f]),lookbehind:!0,inside:v},{pattern:t("(\\bcatch\\s*\\(\\s*)<<0>>",[m]),lookbehind:!0,inside:v},{pattern:t("(\\bwhere\\s+)<<0>>",[h]),lookbehind:!0},{pattern:t("(\\b(?:is(?:\\s+not)?|as)\\s+)<<0>>",[y]),lookbehind:!0,inside:v},{pattern:t("\\b<<0>>(?=\\s+(?!<<1>>)<<2>>(?:\\s*[=,;:{)\\]]|\\s+(?:in|when)\\b))",[w,u,h]),inside:v}],keyword:p,number:/(?:\b0(?:x[\da-f_]*[\da-f]|b[01_]*[01])|(?:\B\.\d+(?:_+\d+)*|\b\d+(?:_+\d+)*(?:\.\d+(?:_+\d+)*)?)(?:e[-+]?\d+(?:_+\d+)*)?)(?:ul|lu|[dflmu])?\b/i,operator:/>>=?|<<=?|[-=]>|([-+&|])\1|~|\?\?=?|[-+*/%&|^!=<>]=?/,punctuation:/\?\.?|::|[{}[\];(),.:]/}),s.languages.insertBefore("csharp","number",{range:{pattern:/\.\./,alias:"operator"}}),s.languages.insertBefore("csharp","punctuation",{"named-parameter":{pattern:t("([(,]\\s*)<<0>>(?=\\s*:)",[h]),lookbehind:!0,alias:"punctuation"}}),s.languages.insertBefore("csharp","class-name",{namespace:{pattern:t("(\\b(?:namespace|using)\\s+)<<0>>(?:\\s*\\.\\s*<<0>>)*(?=\\s*[;{])",[h]),lookbehind:!0,inside:{punctuation:/\./}},"type-expression":{pattern:t("(\\b(?:default|typeof|sizeof)\\s*\\(\\s*(?!\\s))(?:[^()\\s]|\\s(?!\\s)|<<0>>)*(?=\\s*\\))",[b]),lookbehind:!0,alias:"class-name",inside:v},"return-type":{pattern:t("<<0>>(?=\\s+(?:<<1>>\\s*(?:=>|[({]|\\.\\s*this\\s*\\[)|this\\s*\\[))",[w,m]),inside:v,alias:"class-name"},"constructor-invocation":{pattern:t("(\\bnew\\s+)<<0>>(?=\\s*[[({])",[w]),lookbehind:!0,inside:v,alias:"class-name"},"generic-method":{pattern:t("<<0>>\\s*<<1>>(?=\\s*\\()",[h,g]),inside:{function:t("^<<0>>",[h]),generic:{pattern:RegExp(g),alias:"class-name",inside:v}}},"type-list":{pattern:t("\\b((?:<<0>>\\s+<<1>>|where\\s+<<2>>)\\s*:\\s*)(?:<<3>>|<<4>>)(?:\\s*,\\s*(?:<<3>>|<<4>>))*(?=\\s*(?:where|[{;]|=>|$))",[d,f,h,w,p.source]),lookbehind:!0,inside:{keyword:p,"class-name":{pattern:RegExp(w),greedy:!0,inside:v},punctuation:/,/}},preprocessor:{pattern:/(^[\t ]*)#.*/m,lookbehind:!0,alias:"property",inside:{directive:{pattern:/(#)\b(?:define|elif|else|endif|endregion|error|if|line|nullable|pragma|region|undef|warning)\b/,lookbehind:!0,alias:"keyword"}}}});var _=$+"|"+x,B=a("/(?![*/])|//[^\r\n]*[\r\n]|/\\*(?:[^*]|\\*(?!/))*\\*/|<<0>>",[_]),E=e(a("[^\"'/()]|<<0>>|\\(<>*\\)",[B]),2),R="\\b(?:assembly|event|field|method|module|param|property|return|type)\\b",P=a("<<0>>(?:\\s*\\(<<1>>*\\))?",[m,E]);s.languages.insertBefore("csharp","class-name",{attribute:{pattern:t("((?:^|[^\\s\\w>)?])\\s*\\[\\s*)(?:<<0>>\\s*:\\s*)?<<1>>(?:\\s*,\\s*<<1>>)*(?=\\s*\\])",[R,P]),lookbehind:!0,greedy:!0,inside:{target:{pattern:t("^<<0>>(?=\\s*:)",[R]),alias:"keyword"},"attribute-arguments":{pattern:t("\\(<<0>>*\\)",[E]),inside:s.languages.csharp},"class-name":{pattern:RegExp(m),inside:{punctuation:/\./}},punctuation:/[:,]/}}});var z=":[^}\r\n]+",S=e(a("[^\"'/()]|<<0>>|\\(<>*\\)",[B]),2),j=a("\\{(?!\\{)(?:(?![}:])<<0>>)*<<1>>?\\}",[S,z]),A=e(a("[^\"'/()]|/(?!\\*)|/\\*(?:[^*]|\\*(?!/))*\\*/|<<0>>|\\(<>*\\)",[_]),2),F=a("\\{(?!\\{)(?:(?![}:])<<0>>)*<<1>>?\\}",[A,z]);function U(e,n){return{interpolation:{pattern:t("((?:^|[^{])(?:\\{\\{)*)<<0>>",[e]),lookbehind:!0,inside:{"format-string":{pattern:t("(^\\{(?:(?![}:])<<0>>)*)<<1>>(?=\\}$)",[n,z]),lookbehind:!0,inside:{punctuation:/^:/}},punctuation:/^\{|\}$/,expression:{pattern:/[\s\S]+/,alias:"language-csharp",inside:s.languages.csharp}}},string:/[\s\S]+/}}s.languages.insertBefore("csharp","string",{"interpolation-string":[{pattern:t('(^|[^\\\\])(?:\\$@|@\\$)"(?:""|\\\\[^]|\\{\\{|<<0>>|[^\\\\{"])*"',[j]),lookbehind:!0,greedy:!0,inside:U(j,S)},{pattern:t('(^|[^@\\\\])\\$"(?:\\\\.|\\{\\{|<<0>>|[^\\\\"{])*"',[F]),lookbehind:!0,greedy:!0,inside:U(F,A)}]})}(Prism),Prism.languages.dotnet=Prism.languages.cs=Prism.languages.csharp; \ No newline at end of file +!function(s){function a(e,s){return e.replace(/<<(\d+)>>/g,function(e,n){return"(?:"+s[+n]+")"})}function t(e,n,s){return RegExp(a(e,n),s||"")}function e(e,n){for(var s=0;s>/g,function(){return"(?:"+e+")"});return e.replace(/<>/g,"[^\\s\\S]")}var n="bool byte char decimal double dynamic float int long object sbyte short string uint ulong ushort var void",r="class enum interface record struct",i="add alias and ascending async await by descending from(?=\\s*(?:\\w|$)) get global group into init(?=\\s*;) join let nameof not notnull on or orderby partial remove select set unmanaged value when where with(?=\\s*{)",o="abstract as base break case catch checked const continue default delegate do else event explicit extern finally fixed for foreach goto if implicit in internal is lock namespace new null operator out override params private protected public readonly ref return sealed sizeof stackalloc static switch this throw try typeof unchecked unsafe using virtual volatile while yield";function l(e){return"\\b(?:"+e.trim().replace(/ /g,"|")+")\\b"}var d=l(r),p=RegExp(l(n+" "+r+" "+i+" "+o)),c=l(r+" "+i+" "+o),u=l(n+" "+r+" "+o),g=e("<(?:[^<>;=+\\-*/%&|^]|<>)*>",2),b=e("\\((?:[^()]|<>)*\\)",2),h="@?\\b[A-Za-z_]\\w*\\b",f=a("<<0>>(?:\\s*<<1>>)?",[h,g]),m=a("(?!<<0>>)<<1>>(?:\\s*\\.\\s*<<1>>)*",[c,f]),k="\\[\\s*(?:,\\s*)*\\]",y=a("<<0>>(?:\\s*(?:\\?\\s*)?<<1>>)*(?:\\s*\\?)?",[m,k]),w=a("(?:<<0>>|<<1>>)(?:\\s*(?:\\?\\s*)?<<2>>)*(?:\\s*\\?)?",[a("\\(<<0>>+(?:,<<0>>+)+\\)",[a("[^,()<>[\\];=+\\-*/%&|^]|<<0>>|<<1>>|<<2>>",[g,b,k])]),m,k]),v={keyword:p,punctuation:/[<>()?,.:[\]]/},x="'(?:[^\r\n'\\\\]|\\\\.|\\\\[Uux][\\da-fA-F]{1,8})'",$='"(?:\\\\.|[^\\\\"\r\n])*"';s.languages.csharp=s.languages.extend("clike",{string:[{pattern:t("(^|[^$\\\\])<<0>>",['@"(?:""|\\\\[^]|[^\\\\"])*"(?!")']),lookbehind:!0,greedy:!0},{pattern:t("(^|[^@$\\\\])<<0>>",[$]),lookbehind:!0,greedy:!0},{pattern:RegExp(x),greedy:!0,alias:"character"}],"class-name":[{pattern:t("(\\busing\\s+static\\s+)<<0>>(?=\\s*;)",[m]),lookbehind:!0,inside:v},{pattern:t("(\\busing\\s+<<0>>\\s*=\\s*)<<1>>(?=\\s*;)",[h,w]),lookbehind:!0,inside:v},{pattern:t("(\\busing\\s+)<<0>>(?=\\s*=)",[h]),lookbehind:!0},{pattern:t("(\\b<<0>>\\s+)<<1>>",[d,f]),lookbehind:!0,inside:v},{pattern:t("(\\bcatch\\s*\\(\\s*)<<0>>",[m]),lookbehind:!0,inside:v},{pattern:t("(\\bwhere\\s+)<<0>>",[h]),lookbehind:!0},{pattern:t("(\\b(?:is(?:\\s+not)?|as)\\s+)<<0>>",[y]),lookbehind:!0,inside:v},{pattern:t("\\b<<0>>(?=\\s+(?!<<1>>|with\\s*\\{)<<2>>(?:\\s*[=,;:{)\\]]|\\s+(?:in|when)\\b))",[w,u,h]),inside:v}],keyword:p,number:/(?:\b0(?:x[\da-f_]*[\da-f]|b[01_]*[01])|(?:\B\.\d+(?:_+\d+)*|\b\d+(?:_+\d+)*(?:\.\d+(?:_+\d+)*)?)(?:e[-+]?\d+(?:_+\d+)*)?)(?:ul|lu|[dflmu])?\b/i,operator:/>>=?|<<=?|[-=]>|([-+&|])\1|~|\?\?=?|[-+*/%&|^!=<>]=?/,punctuation:/\?\.?|::|[{}[\];(),.:]/}),s.languages.insertBefore("csharp","number",{range:{pattern:/\.\./,alias:"operator"}}),s.languages.insertBefore("csharp","punctuation",{"named-parameter":{pattern:t("([(,]\\s*)<<0>>(?=\\s*:)",[h]),lookbehind:!0,alias:"punctuation"}}),s.languages.insertBefore("csharp","class-name",{namespace:{pattern:t("(\\b(?:namespace|using)\\s+)<<0>>(?:\\s*\\.\\s*<<0>>)*(?=\\s*[;{])",[h]),lookbehind:!0,inside:{punctuation:/\./}},"type-expression":{pattern:t("(\\b(?:default|typeof|sizeof)\\s*\\(\\s*(?!\\s))(?:[^()\\s]|\\s(?!\\s)|<<0>>)*(?=\\s*\\))",[b]),lookbehind:!0,alias:"class-name",inside:v},"return-type":{pattern:t("<<0>>(?=\\s+(?:<<1>>\\s*(?:=>|[({]|\\.\\s*this\\s*\\[)|this\\s*\\[))",[w,m]),inside:v,alias:"class-name"},"constructor-invocation":{pattern:t("(\\bnew\\s+)<<0>>(?=\\s*[[({])",[w]),lookbehind:!0,inside:v,alias:"class-name"},"generic-method":{pattern:t("<<0>>\\s*<<1>>(?=\\s*\\()",[h,g]),inside:{function:t("^<<0>>",[h]),generic:{pattern:RegExp(g),alias:"class-name",inside:v}}},"type-list":{pattern:t("\\b((?:<<0>>\\s+<<1>>|record\\s+<<1>>\\s*<<5>>|where\\s+<<2>>)\\s*:\\s*)(?:<<3>>|<<4>>|<<1>>\\s*<<5>>|<<6>>)(?:\\s*,\\s*(?:<<3>>|<<4>>|<<6>>))*(?=\\s*(?:where|[{;]|=>|$))",[d,f,h,w,p.source,b,"\\bnew\\s*\\(\\s*\\)"]),lookbehind:!0,inside:{"record-arguments":{pattern:t("(^(?!new\\s*\\()<<0>>\\s*)<<1>>",[f,b]),lookbehind:!0,greedy:!0,inside:s.languages.csharp},keyword:p,"class-name":{pattern:RegExp(w),greedy:!0,inside:v},punctuation:/[,()]/}},preprocessor:{pattern:/(^[\t ]*)#.*/m,lookbehind:!0,alias:"property",inside:{directive:{pattern:/(#)\b(?:define|elif|else|endif|endregion|error|if|line|nullable|pragma|region|undef|warning)\b/,lookbehind:!0,alias:"keyword"}}}});var _=$+"|"+x,B=a("/(?![*/])|//[^\r\n]*[\r\n]|/\\*(?:[^*]|\\*(?!/))*\\*/|<<0>>",[_]),E=e(a("[^\"'/()]|<<0>>|\\(<>*\\)",[B]),2),R="\\b(?:assembly|event|field|method|module|param|property|return|type)\\b",P=a("<<0>>(?:\\s*\\(<<1>>*\\))?",[m,E]);s.languages.insertBefore("csharp","class-name",{attribute:{pattern:t("((?:^|[^\\s\\w>)?])\\s*\\[\\s*)(?:<<0>>\\s*:\\s*)?<<1>>(?:\\s*,\\s*<<1>>)*(?=\\s*\\])",[R,P]),lookbehind:!0,greedy:!0,inside:{target:{pattern:t("^<<0>>(?=\\s*:)",[R]),alias:"keyword"},"attribute-arguments":{pattern:t("\\(<<0>>*\\)",[E]),inside:s.languages.csharp},"class-name":{pattern:RegExp(m),inside:{punctuation:/\./}},punctuation:/[:,]/}}});var z=":[^}\r\n]+",S=e(a("[^\"'/()]|<<0>>|\\(<>*\\)",[B]),2),j=a("\\{(?!\\{)(?:(?![}:])<<0>>)*<<1>>?\\}",[S,z]),A=e(a("[^\"'/()]|/(?!\\*)|/\\*(?:[^*]|\\*(?!/))*\\*/|<<0>>|\\(<>*\\)",[_]),2),F=a("\\{(?!\\{)(?:(?![}:])<<0>>)*<<1>>?\\}",[A,z]);function U(e,n){return{interpolation:{pattern:t("((?:^|[^{])(?:\\{\\{)*)<<0>>",[e]),lookbehind:!0,inside:{"format-string":{pattern:t("(^\\{(?:(?![}:])<<0>>)*)<<1>>(?=\\}$)",[n,z]),lookbehind:!0,inside:{punctuation:/^:/}},punctuation:/^\{|\}$/,expression:{pattern:/[\s\S]+/,alias:"language-csharp",inside:s.languages.csharp}}},string:/[\s\S]+/}}s.languages.insertBefore("csharp","string",{"interpolation-string":[{pattern:t('(^|[^\\\\])(?:\\$@|@\\$)"(?:""|\\\\[^]|\\{\\{|<<0>>|[^\\\\{"])*"',[j]),lookbehind:!0,greedy:!0,inside:U(j,S)},{pattern:t('(^|[^@\\\\])\\$"(?:\\\\.|\\{\\{|<<0>>|[^\\\\"{])*"',[F]),lookbehind:!0,greedy:!0,inside:U(F,A)}]})}(Prism),Prism.languages.dotnet=Prism.languages.cs=Prism.languages.csharp; \ No newline at end of file diff --git a/tests/languages/csharp/class-name-declaration_feature.test b/tests/languages/csharp/class-name-declaration_feature.test index 4e41f90970..a1c96fab7b 100644 --- a/tests/languages/csharp/class-name-declaration_feature.test +++ b/tests/languages/csharp/class-name-declaration_feature.test @@ -2,8 +2,12 @@ class Foo interface BarBaz struct Foo enum Foo +record Foo class Foo interface Bar +record Foo + +record TestData(string Name); // not variables public static RGBColor FromRainbow(Rainbow colorBand) => @@ -28,6 +32,9 @@ public static RGBColor FromRainbow(Rainbow colorBand) => ["keyword", "enum"], ["class-name", ["Foo"]], + ["keyword", "record"], + ["class-name", ["Foo"]], + ["keyword", "class"], ["class-name", [ "Foo", @@ -47,6 +54,26 @@ public static RGBColor FromRainbow(Rainbow colorBand) => ["punctuation", ">"] ]], + ["keyword", "record"], + ["class-name", [ + "Foo", + ["punctuation", "<"], + "A", + ["punctuation", ","], + " B", + ["punctuation", ">"] + ]], + + ["keyword", "record"], + ["class-name", ["TestData"]], + ["punctuation", "("], + ["class-name", [ + ["keyword", "string"] + ]], + " Name", + ["punctuation", ")"], + ["punctuation", ";"], + ["comment", "// not variables"], ["keyword", "public"], diff --git a/tests/languages/csharp/issue2991.test b/tests/languages/csharp/issue2991.test deleted file mode 100644 index 04568ce2ea..0000000000 --- a/tests/languages/csharp/issue2991.test +++ /dev/null @@ -1,52 +0,0 @@ -record TestData -{ - public string Name { get; init; } - public void Func() - { - } -} - -record TestData(string Name); - ----------------------------------------------------- - -[ - ["keyword", "record"], - ["class-name", ["TestData"]], - - ["punctuation", "{"], - - ["keyword", "public"], - ["return-type", [ - ["keyword", "string"] - ]], - " Name ", - ["punctuation", "{"], - ["keyword", "get"], - ["punctuation", ";"], - ["keyword", "init"], - ["punctuation", ";"], - ["punctuation", "}"], - - ["keyword", "public"], - ["return-type", [ - ["keyword", "void"] - ]], - ["function", "Func"], - ["punctuation", "("], - ["punctuation", ")"], - ["punctuation", "{"], - ["punctuation", "}"], - - ["punctuation", "}"], - - ["keyword", "record"], - ["class-name", ["TestData"]], - ["punctuation", "("], - ["class-name", [ - ["keyword", "string"] - ]], - " Name", - ["punctuation", ")"], - ["punctuation", ";"] -] diff --git a/tests/languages/csharp/keyword_feature.test b/tests/languages/csharp/keyword_feature.test index 1714cca187..3d42242aa8 100644 --- a/tests/languages/csharp/keyword_feature.test +++ b/tests/languages/csharp/keyword_feature.test @@ -108,6 +108,9 @@ where; while yield +// very contextual keywords: +Person person2 = person1 with { FirstName = "John" }; + ---------------------------------------------------- [ @@ -219,7 +222,21 @@ yield ["keyword", "when"], ["keyword", "where"], ["punctuation", ";"], ["keyword", "while"], - ["keyword", "yield"] + ["keyword", "yield"], + + ["comment", "// very contextual keywords:"], + + ["class-name", ["Person"]], + " person2 ", + ["operator", "="], + " person1 ", + ["keyword", "with"], + ["punctuation", "{"], + " FirstName ", + ["operator", "="], + ["string", "\"John\""], + ["punctuation", "}"], + ["punctuation", ";"] ] ---------------------------------------------------- diff --git a/tests/languages/csharp/type-list_feature.test b/tests/languages/csharp/type-list_feature.test index 04331c1b14..bd01217e05 100644 --- a/tests/languages/csharp/type-list_feature.test +++ b/tests/languages/csharp/type-list_feature.test @@ -7,6 +7,18 @@ public delegate ErrorCode GetInfoMethod(H handle, A value, I paramName, Size_t paramValueSize, IntPtr paramValue, out Size_t paramValueSizeRet) where H : unmanaged, IInfoHandle where A : unmanaged where I : unmanaged, Enum; +// the "new()" constraint +void Foo() + where A : IFoo, new() + where B : new(), IFoo; + +// records are kinda difficult to handle +public abstract record Person(string FirstName, string LastName); +public record Teacher(string FirstName, string LastName, int Grade) + : Person(FirstName, LastName), IFoo; +public record Student(string FirstName, string LastName, int Grade) + : Person(FirstName, LastName); + ---------------------------------------------------- [ @@ -40,10 +52,9 @@ public delegate ErrorCode GetInfoMethod(H handle, A value, I paramName, ["punctuation", ">"] ]], ["punctuation", ","], - ["class-name", [ - "IFoo" - ]] + ["class-name", ["IFoo"]] ]], + ["keyword", "where"], ["class-name", "T"], ["punctuation", ":"], @@ -69,9 +80,7 @@ public delegate ErrorCode GetInfoMethod(H handle, A value, I paramName, ["keyword", "public"], ["keyword", "class"], - ["class-name", [ - "Foo" - ]], + ["class-name", ["Foo"]], ["punctuation", ":"], ["type-list", [ ["class-name", [ @@ -86,9 +95,7 @@ public delegate ErrorCode GetInfoMethod(H handle, A value, I paramName, ["keyword", "public"], ["keyword", "delegate"], - ["return-type", [ - "ErrorCode" - ]], + ["return-type", ["ErrorCode"]], ["generic-method", [ ["function", "GetInfoMethod"], ["generic", [ @@ -102,37 +109,27 @@ public delegate ErrorCode GetInfoMethod(H handle, A value, I paramName, ]] ]], ["punctuation", "("], - ["class-name", [ - "H" - ]], + ["class-name", ["H"]], " handle", ["punctuation", ","], - ["class-name", [ - "A" - ]], + ["class-name", ["A"]], ["keyword", "value"], ["punctuation", ","], - ["class-name", [ - "I" - ]], + ["class-name", ["I"]], " paramName", ["punctuation", ","], - ["class-name", [ - "Size_t" - ]], + + ["class-name", ["Size_t"]], " paramValueSize", ["punctuation", ","], - ["class-name", [ - "IntPtr" - ]], + ["class-name", ["IntPtr"]], " paramValue", ["punctuation", ","], ["keyword", "out"], - ["class-name", [ - "Size_t" - ]], + ["class-name", ["Size_t"]], " paramValueSizeRet", ["punctuation", ")"], + ["keyword", "where"], ["class-name", "H"], ["punctuation", ":"], @@ -160,8 +157,139 @@ public delegate ErrorCode GetInfoMethod(H handle, A value, I paramName, ["type-list", [ ["keyword", "unmanaged"], ["punctuation", ","], + ["class-name", ["Enum"]] + ]], + ["punctuation", ";"], + + ["comment", "// the \"new()\" constraint"], + + ["return-type", [ + ["keyword", "void"] + ]], + ["generic-method", [ + ["function", "Foo"], + ["generic", [ + ["punctuation", "<"], + "A", + ["punctuation", ","], + " B", + ["punctuation", ">"] + ]] + ]], + ["punctuation", "("], + ["punctuation", ")"], + + ["keyword", "where"], + ["class-name", "A"], + ["punctuation", ":"], + ["type-list", [ + ["class-name", ["IFoo"]], + ["punctuation", ","], + ["keyword", "new"], + ["punctuation", "("], + ["punctuation", ")"] + ]], + + ["keyword", "where"], + ["class-name", "B"], + ["punctuation", ":"], + ["type-list", [ + ["keyword", "new"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", ","], + ["class-name", ["IFoo"]] + ]], + ["punctuation", ";"], + + ["comment", "// records are kinda difficult to handle"], + + ["keyword", "public"], + ["keyword", "abstract"], + ["keyword", "record"], + ["class-name", ["Person"]], + ["punctuation", "("], + ["class-name", [ + ["keyword", "string"] + ]], + " FirstName", + ["punctuation", ","], + ["class-name", [ + ["keyword", "string"] + ]], + " LastName", + ["punctuation", ")"], + ["punctuation", ";"], + + ["keyword", "public"], + ["keyword", "record"], + ["class-name", ["Teacher"]], + ["punctuation", "("], + ["class-name", [ + ["keyword", "string"] + ]], + " FirstName", + ["punctuation", ","], + ["class-name", [ + ["keyword", "string"] + ]], + " LastName", + ["punctuation", ","], + ["class-name", [ + ["keyword", "int"] + ]], + " Grade", + ["punctuation", ")"], + + ["punctuation", ":"], + ["type-list", [ + ["class-name", ["Person"]], + ["record-arguments", [ + ["punctuation", "("], + "FirstName", + ["punctuation", ","], + " LastName", + ["punctuation", ")"] + ]], + ["punctuation", ","], ["class-name", [ - "Enum" + "IFoo", + ["punctuation", "<"], + ["keyword", "int"], + ["punctuation", ">"] + ]] + ]], + ["punctuation", ";"], + + ["keyword", "public"], + ["keyword", "record"], + ["class-name", ["Student"]], + ["punctuation", "("], + ["class-name", [ + ["keyword", "string"] + ]], + " FirstName", + ["punctuation", ","], + ["class-name", [ + ["keyword", "string"] + ]], + " LastName", + ["punctuation", ","], + ["class-name", [ + ["keyword", "int"] + ]], + " Grade", + ["punctuation", ")"], + + ["punctuation", ":"], + ["type-list", [ + ["class-name", ["Person"]], + ["record-arguments", [ + ["punctuation", "("], + "FirstName", + ["punctuation", ","], + " LastName", + ["punctuation", ")"] ]] ]], ["punctuation", ";"]