master
ブランチ master
LittleBeast / src / Std / Lib / Syntax / CSharp.php
2.8 KB、45行 生 Blame 履歴
1<?php
2namespace Std\Lib\Syntax;
3
4class CSharp extends Language {
5 protected bool $preprocessor = true;
6 protected string $digitSep = '_';
7 // 「@class」の様な逐語的識別子
8 protected string $identifier = '@?[\p{L}_][\p{L}\p{N}_]*';
9
10 protected array $rules = [
11 // 生文字列 """…"""($"""…"""も)
12 ['re' => '\$*"""(?s:.*?)(?:"""|\z)', 'class' => 'string'],
13 // 逐語的文字列 @"…"(""でエスケープ、複数行可)、$@"…"、@$"…"
14 ['re' => '(?:\$@|@\$|@)"(?:[^"]|"")*"?', 'class' => 'string'],
15 // 補間文字列 $"…"
16 ['re' => '\$"(?:[^"\\\\\n]|\\\\.)*"?', 'class' => 'string'],
17 ];
18
19 protected array $tokens = [
20 'keyword' => [
21 'abstract', 'as', 'base', 'break', 'case', 'catch', 'checked', 'class', 'const', 'continue', 'default', 'delegate', 'do', 'else',
22 'enum', 'event', 'explicit', 'extern', 'finally', 'fixed', 'for', 'foreach', 'goto', 'if', 'implicit', 'in', 'interface', 'internal',
23 'is', 'lock', 'namespace', 'new', 'operator', 'out', 'override', 'params', 'private', 'protected', 'public', 'readonly', 'ref',
24 'return', 'sealed', 'sizeof', 'stackalloc', 'static', 'struct', 'switch', 'this', 'throw', 'try', 'typeof', 'unchecked', 'unsafe',
25 'using', 'virtual', 'volatile', 'while',
26 // 文脈依存(「value」「select」「file」等、変数名によく使う単語は除く)
27 'alias', 'and', 'async', 'await', 'get', 'global', 'init', 'managed', 'nameof', 'not', 'notnull', 'or', 'partial', 'record',
28 'required', 'scoped', 'set', 'unmanaged', 'var', 'when', 'where', 'with', 'yield',
29 ],
30 'constant' => [
31 'true', 'false', 'null',
32 ],
33 'type' => [
34 'bool', 'byte', 'sbyte', 'char', 'decimal', 'double', 'float', 'int', 'uint', 'nint', 'nuint', 'long', 'ulong', 'short', 'ushort',
35 'object', 'string', 'void', 'dynamic',
36 'Boolean', 'Byte', 'SByte', 'Char', 'Decimal', 'Double', 'Single', 'Int16', 'Int32', 'Int64', 'Int128', 'UInt16', 'UInt32', 'UInt64',
37 'IntPtr', 'UIntPtr', 'Half', 'Object', 'String', 'Guid', 'DateTime', 'TimeSpan', 'Span', 'ReadOnlySpan', 'Memory', 'ReadOnlyMemory',
38 'List', 'Dictionary', 'HashSet', 'Queue', 'Stack', 'LinkedList', 'SortedList', 'SortedDictionary', 'Array', 'Tuple', 'ValueTuple',
39 'IEnumerable', 'IEnumerator', 'ICollection', 'IList', 'IDictionary', 'IReadOnlyList', 'IDisposable', 'IComparable', 'IEquatable',
40 'Task', 'ValueTask', 'Action', 'Func', 'Predicate', 'EventHandler', 'Exception', 'ArgumentException', 'ArgumentNullException',
41 'InvalidOperationException', 'NotImplementedException', 'Console', 'Math', 'MathF', 'Convert', 'Enumerable', 'StringBuilder',
42 'Thread', 'CancellationToken', 'Stream', 'File', 'Path', 'Directory', 'Random', 'Vector2', 'Vector3', 'Vector4', 'Matrix4x4', 'Quaternion',
43 ],
44 ];
45}