Syntax
諏訪子 <suwako@076.moe>、2026-01-29 04:05
コミット 20124107fb35aa9d9667c5b24362bfa961e52553
・親 65fa46e
・ファイルを見る
20個のファイル、+1411 -0
追加
data/main.c
| @@ -0,0 +1,10 @@ | ||
| 1 | +#include <stdio.h> | |
| 2 | + | |
| 3 | +int main(int argc, char *argv[]) { | |
| 4 | + for (int i = 0; i < 9000; ++i) { | |
| 5 | + size_t size = 0; | |
| 6 | + puts("うんこちんこ"); // 現実:マンコ | |
| 7 | + } | |
| 8 | + | |
| 9 | + return 0; | |
| 10 | +} |
追加
data/main.s
| @@ -0,0 +1,175 @@ | ||
| 1 | +; FreeBSDで、シスコール番号を調べるには:/usr/include/sys/syscall.h | |
| 2 | +; Linuxで、シスコール番号を調べるには:/usr/include/asm-generic/unistd.h | |
| 3 | +; 下記のコードはFreeBSD向けの物です。 | |
| 4 | + | |
| 5 | +bits 64 | |
| 6 | +default rel | |
| 7 | + | |
| 8 | +section .data | |
| 9 | + | |
| 10 | +section .rodata | |
| 11 | + basename db "output-",0 | |
| 12 | + suffix db ".ppm", 0 | |
| 13 | + hdr db "P6", 10, "960 540", 10, "255", 10 | |
| 14 | + | |
| 15 | + err db "開くに失敗", 10 | |
| 16 | + errlen equ $-err | |
| 17 | + suc db "60フレームを作成しました。", 10 | |
| 18 | + suclen equ $-suc | |
| 19 | + | |
| 20 | + w equ 960 | |
| 21 | + h equ 540 | |
| 22 | + | |
| 23 | +section .bss | |
| 24 | + buf resb 960*540*3 | |
| 25 | + outfile resb 64 ; "output-nn.ppm\0" | |
| 26 | + | |
| 27 | +section .text | |
| 28 | + global _start | |
| 29 | + | |
| 30 | +_start: | |
| 31 | + mov r12, 0 ; i = 0 | |
| 32 | + | |
| 33 | +frameloop: | |
| 34 | + ; ファイル名 | |
| 35 | + lea rdi, [outfile] | |
| 36 | + lea rsi, [basename] | |
| 37 | + call strcpy | |
| 38 | + | |
| 39 | + ; iは2つの文字に変換 | |
| 40 | + mov rax, r12 | |
| 41 | + mov rcx, 10 | |
| 42 | + xor rdx, rdx | |
| 43 | + div rcx ; rax = 10, rdx = 01 | |
| 44 | + | |
| 45 | + add al, '0' | |
| 46 | + add dl, '0' | |
| 47 | + mov [rdi], al ; 10 | |
| 48 | + mov [rdi+1], dl; 01 | |
| 49 | + add rdi, 2 | |
| 50 | + | |
| 51 | + lea rsi, [suffix] | |
| 52 | + call strcpy ; 「.ppm\0」の追加 | |
| 53 | + | |
| 54 | + mov rax, 5 ; sys_open | |
| 55 | + lea rdi, [outfile] | |
| 56 | + mov rsi, 0x100601 ; 0x100601 = 0001 0000 0000 0110 0000 0001 = 1048576 + 1024 + 512 + 1 = 1050113 | |
| 57 | + ; O_WRONLY = 0x0001 | |
| 58 | + ; O_CREAT = 0x0200 | |
| 59 | + ; O_TRUNC = 0x0400 | |
| 60 | + ; O_CLOEXEC = 0x010000 | |
| 61 | + ; /usr/include/sys/fcntl.h | |
| 62 | + mov rdx, 0o666 ; chmod 666 | |
| 63 | + syscall | |
| 64 | + | |
| 65 | + test rax, rax | |
| 66 | + js error ; エラーがあれば | |
| 67 | + mov r15, rax ; ファイルディスクリプターをr15に保存 | |
| 68 | + | |
| 69 | + ; ヘッダーの書き込み | |
| 70 | + mov eax, 4 ; sys_write | |
| 71 | + mov rdi, r15 ; fd | |
| 72 | + lea rsi, [hdr] | |
| 73 | + mov rdx, 18 | |
| 74 | + syscall | |
| 75 | + | |
| 76 | + ; チェッカーボードループ | |
| 77 | + lea rdi, [buf] | |
| 78 | + mov rcx, h | |
| 79 | + xor r13, r13 | |
| 80 | + | |
| 81 | +yloop: | |
| 82 | + mov r8d, w | |
| 83 | + | |
| 84 | +xloop: | |
| 85 | + ; (x/60 + y/60) % 2の計算 | |
| 86 | + mov eax, r8d ; x | |
| 87 | + add eax, r12d ; x + i | |
| 88 | + xor edx, edx | |
| 89 | + mov ebx, 60 | |
| 90 | + div ebx ; eax = (x + i)/60 | |
| 91 | + push rax | |
| 92 | + | |
| 93 | + mov eax, r13d | |
| 94 | + add eax, r12d ; y + i | |
| 95 | + xor edx, edx | |
| 96 | + div ebx ; eax = (y + i)/60 | |
| 97 | + | |
| 98 | + pop rdx | |
| 99 | + add eax, edx ; (x + i)/60 + (y + i)/60 | |
| 100 | + and al, 1 ; % 2 | |
| 101 | + jz .black | |
| 102 | + | |
| 103 | +.green: | |
| 104 | + mov al, 0 | |
| 105 | + stosb ; R | |
| 106 | + mov al, 0xFF | |
| 107 | + stosb ; G | |
| 108 | + mov al, 0 | |
| 109 | + stosb ; B | |
| 110 | + jmp .next | |
| 111 | + | |
| 112 | +.black: | |
| 113 | + xor eax, eax | |
| 114 | + stosb | |
| 115 | + stosb | |
| 116 | + stosb | |
| 117 | + | |
| 118 | +.next: | |
| 119 | + dec r8d | |
| 120 | + jnz xloop | |
| 121 | + | |
| 122 | + inc r13d | |
| 123 | + dec rcx | |
| 124 | + jnz yloop | |
| 125 | + | |
| 126 | + ; ピクセルデータの書き込み | |
| 127 | + mov eax, 4 | |
| 128 | + mov rdi, r15 | |
| 129 | + lea rsi, [buf] | |
| 130 | + mov edx, 960*540*3 | |
| 131 | + syscall | |
| 132 | + | |
| 133 | +close: | |
| 134 | + mov rax, 6 ; sys_close | |
| 135 | + mov rdi, r15 | |
| 136 | + syscall | |
| 137 | + | |
| 138 | + inc r12 | |
| 139 | + cmp r12, 60 | |
| 140 | + jb frameloop | |
| 141 | + | |
| 142 | + mov rax, 4 | |
| 143 | + mov rdi, 1 | |
| 144 | + lea rsi, [suc] | |
| 145 | + mov rdx, suclen | |
| 146 | + syscall | |
| 147 | + | |
| 148 | +end: | |
| 149 | + mov eax, 1 ; sys_exit | |
| 150 | + xor edi, edi | |
| 151 | + syscall | |
| 152 | + | |
| 153 | +error: | |
| 154 | + mov rax, 4 | |
| 155 | + mov rdi, 2 ; stderr | |
| 156 | + lea rsi, [err] | |
| 157 | + mov rdx, errlen | |
| 158 | + syscall | |
| 159 | + | |
| 160 | + mov rax, 1 | |
| 161 | + mov rdi, 1 | |
| 162 | + syscall | |
| 163 | + | |
| 164 | +strcpy: | |
| 165 | +.loop: | |
| 166 | + mov al, [rsi] | |
| 167 | + mov [rdi], al | |
| 168 | + test al, al | |
| 169 | + jz .done | |
| 170 | + inc rdi | |
| 171 | + inc rsi | |
| 172 | + jmp .loop | |
| 173 | + | |
| 174 | +.done: | |
| 175 | + ret |
変更
route.php
| @@ -60,6 +60,7 @@ | ||
| 60 | 60 | $routes = [ |
| 61 | 61 | Route::add('GET', 'robots.txt', Home::class.'@robots'), |
| 62 | 62 | Route::add('GET', 'blog/{page}', Home::class.'@article'), |
| 63 | + Route::add('GET', 'test', Page::class.'@test'), | |
| 63 | 64 | Route::add('GET', 'about', Page::class.'@about'), |
| 64 | 65 | Route::add('GET', 'monero', Page::class.'@monero'), |
| 65 | 66 | Route::add('GET', 'secret', Page::class.'@secret'), |
| @@ -42,8 +42,45 @@ | ||
| 42 | 42 | use Std\Lib\Template; |
| 43 | 43 | use Roles; |
| 44 | 44 | |
| 45 | +use Site\Lib\Syntax; // TEST | |
| 46 | + | |
| 45 | 47 | class Page { |
| 46 | 48 | use Mods; |
| 49 | + | |
| 50 | + public function test(array $params): void { | |
| 51 | + try { | |
| 52 | + // getImageInfo('o_53803618dc1691.28179609-orig.jpg'); | |
| 53 | + $img = getImageInfo('/public/static/article/fat-logo.png'); | |
| 54 | + $tmpl = new Template('/'); | |
| 55 | + $pagetit = '新ページ'; | |
| 56 | + $description = 'PHPフレームワークについて'; | |
| 57 | + | |
| 58 | + // ユーザー | |
| 59 | + $auth = new Auth(); | |
| 60 | + $user = $auth->getLoggedInUser(); | |
| 61 | + $tmpl->assign('user', $user); | |
| 62 | + | |
| 63 | + $codeAsm = file_get_contents(ROOT.'/data/main.s'); | |
| 64 | + $codeC = file_get_contents(ROOT.'/data/main.c'); | |
| 65 | + $asm = new Syntax('asm'); | |
| 66 | + $c = new Syntax('c'); | |
| 67 | + | |
| 68 | + $tmpl->assign('img', $img); | |
| 69 | + $tmpl->assign('cCode', $c->colorize($codeC)); | |
| 70 | + $tmpl->assign('asmCode', $asm->colorize($codeAsm)); | |
| 71 | + | |
| 72 | + $tmpl->assign('pagetit', $pagetit); | |
| 73 | + $tmpl->assign('curPage', 'test'); | |
| 74 | + $tmpl->assign('custCss', false); | |
| 75 | + $tmpl->assign('menu', $this->getMenu()); | |
| 76 | + $tmpl->assign('description', $description); | |
| 77 | + | |
| 78 | + $tmpl->addCss('code'); | |
| 79 | + $tmpl->render('test'); | |
| 80 | + } catch (\Exception $e) { | |
| 81 | + throw new \Exception($e->getMessage()); | |
| 82 | + } | |
| 83 | + } | |
| 47 | 84 | |
| 48 | 85 | public function about(array $params): void { |
| 49 | 86 | try { |
| @@ -0,0 +1,280 @@ | ||
| 1 | +<?php | |
| 2 | +namespace Site\Lib; | |
| 3 | + | |
| 4 | +use Site\Lib\Syntax\SyntaxInterface; | |
| 5 | +use Site\Lib\Syntax\AsmAarch32; | |
| 6 | +use Site\Lib\Syntax\AsmAarch64; | |
| 7 | +use Site\Lib\Syntax\AsmX8664; | |
| 8 | +use Site\Lib\Syntax\C; | |
| 9 | +use Site\Lib\Syntax\Cpp; | |
| 10 | +use Site\Lib\Syntax\Glsl; | |
| 11 | +use Site\Lib\Syntax\Go; | |
| 12 | + | |
| 13 | +class Syntax { | |
| 14 | + private array $alt = [ | |
| 15 | + 'asm-aarch32' => ['asm-arm'], | |
| 16 | + 'asm-x8664' => ['asm', 'asm-x86', 'asm-x64'], | |
| 17 | + 'cpp' => ['cc', 'c++'], | |
| 18 | + 'css' => ['css3'], | |
| 19 | + 'go' => ['golang'], | |
| 20 | + ]; | |
| 21 | + | |
| 22 | + private array $include = []; | |
| 23 | + private string $lang; | |
| 24 | + private SyntaxInterface $handler; | |
| 25 | + | |
| 26 | + private array $supported = [ | |
| 27 | + 'asm-aarch32' => AsmAarch32::class, | |
| 28 | + 'asm-aarch64' => AsmAarch64::class, | |
| 29 | + 'asm-x8664' => AsmX8664::class, | |
| 30 | + 'c' => C::class, | |
| 31 | + 'cpp' => Cpp::class, | |
| 32 | + 'glsl' => Glsl::class, | |
| 33 | + 'go' => Go::class, | |
| 34 | + ]; | |
| 35 | + | |
| 36 | + public function __construct(string $lang) { | |
| 37 | + $this->lang = $this->resolveLanguage($lang); | |
| 38 | + $this->handler = $this->createHandler($this->lang); | |
| 39 | + } | |
| 40 | + | |
| 41 | + public function colorize(string $code): string { | |
| 42 | + $lines = explode("\n", $code); | |
| 43 | + foreach ($lines as $c) { | |
| 44 | + $c = str_replace('<', '<', $c); | |
| 45 | + $c = str_replace('>', '>', $c); | |
| 46 | + } | |
| 47 | + | |
| 48 | + switch ($this->lang) { | |
| 49 | + case 'asm-aarch': | |
| 50 | + break; | |
| 51 | + case 'asm-x8664': | |
| 52 | + $lines = $this->addString($lines); | |
| 53 | + $lines = $this->addNumber($lines); | |
| 54 | + $lines = $this->addComment($lines); | |
| 55 | + $lines = $this->add($lines, 'register'); | |
| 56 | + $lines = $this->add($lines, 'operator'); | |
| 57 | + $lines = $this->addLabel($lines); | |
| 58 | + $lines = $this->addSection($lines); | |
| 59 | + $lines = $this->addDirective($lines); | |
| 60 | + break; | |
| 61 | + case 'c': | |
| 62 | + $this->include = $this->handler->getInclude($lines); | |
| 63 | + $lines = $this->addString($lines); | |
| 64 | + $lines = $this->addNumber($lines); | |
| 65 | + $lines = $this->addComment($lines); | |
| 66 | + $lines = $this->add($lines, 'preprocessor'); | |
| 67 | + $lines = $this->add($lines, 'keyword'); | |
| 68 | + foreach ($this->include as $inc) { | |
| 69 | + $lines = $this->add($lines, 'typedef', $inc); | |
| 70 | + $lines = $this->add($lines, 'libc', $inc); | |
| 71 | + } | |
| 72 | + $lines = $this->addFunction($lines); | |
| 73 | + // kys($lines); | |
| 74 | + break; | |
| 75 | + case 'cpp': | |
| 76 | + break; | |
| 77 | + case 'glsl': | |
| 78 | + break; | |
| 79 | + case 'go': | |
| 80 | + break; | |
| 81 | + default: | |
| 82 | + break; | |
| 83 | + } | |
| 84 | + | |
| 85 | + return implode("\n", $lines); | |
| 86 | + } | |
| 87 | + | |
| 88 | + /////////////// | |
| 89 | + | |
| 90 | + private function resolveLanguage(string $lang): string { | |
| 91 | + if (isset($this->supported[$lang])) return $lang; | |
| 92 | + foreach ($this->alt as $k => $v) if (in_array($lang, $v, true)) return $k; | |
| 93 | + throw new \InvalidArgumentException("未対応の言語: {$lang}"); | |
| 94 | + } | |
| 95 | + | |
| 96 | + private function createHandler(string $lang): SyntaxInterface { | |
| 97 | + $class = $this->supported[$lang] ?? null; | |
| 98 | + if (!$class) throw new \RuntimeException("言語のハンドルが存在しない: {$lang}"); | |
| 99 | + return new $class(); | |
| 100 | + } | |
| 101 | + | |
| 102 | + private function addComment(array $code): array { | |
| 103 | + global $colorPalette; | |
| 104 | + | |
| 105 | + $sc = $this->handler->getComment() ?? null; | |
| 106 | + $mc = $this->handler->getMultiline() ?? [null, null]; | |
| 107 | + $mcs = $mc[0]; | |
| 108 | + $mce = $mc[1]; | |
| 109 | + | |
| 110 | + $color = $this->handler->getColors()['comment'] ?? $colorPalette['dark']['green']; | |
| 111 | + | |
| 112 | + $isMulti = false; | |
| 113 | + $out = []; | |
| 114 | + | |
| 115 | + foreach ($code as $c) { | |
| 116 | + $cur = $c; | |
| 117 | + | |
| 118 | + if ($isMulti || strpos($cur, $sc) !== false || ($mcs && strpos($cur, $mcs) !== false)) { | |
| 119 | + $cur = preg_replace('/<span[^>]*>(.*?)<\/span>/s', '$1', $cur); | |
| 120 | + } | |
| 121 | + | |
| 122 | + if ($isMulti) { | |
| 123 | + $endPos = $mcs ? strpos($cur, $mce) : false; | |
| 124 | + | |
| 125 | + if ($endPos !== false) { | |
| 126 | + $before = substr($cur, 0, $endPos + strlen($mce)); | |
| 127 | + $after = substr($cur, $endPos + strlen($mce)); | |
| 128 | + | |
| 129 | + $cur = '<span style="color: '.$color.'; font-style: italics;">'.$before.'</span>'.$after; | |
| 130 | + $isMulti = false; | |
| 131 | + } else { | |
| 132 | + $cur = '<span style="color: '.$color.'; font-style: italics;">'.$cur.'</span>'; | |
| 133 | + } | |
| 134 | + } else { | |
| 135 | + if ($sc && ($pos = strpos($cur, $sc, 1)) !== false) { | |
| 136 | + $before = substr($cur, 0, $pos); | |
| 137 | + $rest = trim(substr($cur, $pos)); | |
| 138 | + $cur = $before.'<span style="color: '.$color.'; font-style: italics;">'.$rest.'</span>'; | |
| 139 | + } | |
| 140 | + | |
| 141 | + if (!$isMulti && $mcs && $mce && str_contains($cur, $mcs)) { | |
| 142 | + $startPos = strpos($cur, $mcs); | |
| 143 | + $endPos = $mce ? strpos($cur, $mce) : false; | |
| 144 | + | |
| 145 | + if ($endPos !== false && $startPos < $endPos) { | |
| 146 | + $before = substr($cur, 0, $startPos); | |
| 147 | + $part = substr($cur, $startPos, $endPos - $startPos + strlen($mce)); | |
| 148 | + $after = substr($cur, $endPos + strlen($mce)); | |
| 149 | + | |
| 150 | + $cur = $before.'<span style="color: '.$color.'; font-style: italics;">'.$part.'</span>'.$after; | |
| 151 | + } else { | |
| 152 | + $before = substr($cur, 0, $startPos); | |
| 153 | + $rest = substr($cur, $startPos); | |
| 154 | + | |
| 155 | + $cur = $before.'<span style="color: '.$color.'; font-style: italics;">'.$rest; | |
| 156 | + $isMulti = true; | |
| 157 | + } | |
| 158 | + } | |
| 159 | + } | |
| 160 | + | |
| 161 | + $out[] = $cur; | |
| 162 | + } | |
| 163 | + | |
| 164 | + return $out; | |
| 165 | + } | |
| 166 | + | |
| 167 | + private function addNumber(array $code): array { | |
| 168 | + $color = $this->handler->getColors()['number']; | |
| 169 | + $pattern = '/(?<![\w$@.])(?: # 関係ない | |
| 170 | + (?:0[xX][0-9a-fA-F]+) # 0xFF, 0XFF | |
| 171 | + |(?:0[bB][01]+) # 0b1010 | |
| 172 | + |(?:[0-9]+[hH]) # FFh, 0FFh | |
| 173 | + |(?:\$[0-9a-fA-F]+) # $FF | |
| 174 | + |(?:%[01]+) # %1010 | |
| 175 | + |(?:\d+(?:\.\d+)?(?:[eE][+-]?\d+)?) # 42, 3.14, 1e-5 | |
| 176 | + |(?:\d+) # 普通数字 | |
| 177 | + )(?![\w$@.])(?![a-zA-Z])/ix'; | |
| 178 | + | |
| 179 | + return array_map(fn($c) => preg_replace_callback($pattern, fn($m) => '<span style="color:'.$color.'">'.$m[0].'</span>', $c), $code); | |
| 180 | + } | |
| 181 | + | |
| 182 | + private function addString(array $code): array { | |
| 183 | + $color = $this->handler->getColors()['string']; | |
| 184 | + $pattern = '/(?:"(?:[^"\\\\]|\\\\.)*"|\'(?:[^\'\\\\]|\\\\.)*\')/s'; | |
| 185 | + | |
| 186 | + return array_map( | |
| 187 | + function ($c) use ($pattern, $color) { | |
| 188 | + return preg_replace_callback($pattern, fn($m) => '<span style="color:'.$color.'">'.$m[0].'</span>', $c); | |
| 189 | + }, | |
| 190 | + $code | |
| 191 | + ); | |
| 192 | + } | |
| 193 | + | |
| 194 | + private function addLabel(array $code): array { | |
| 195 | + $color = $this->handler->getColors()['label']; | |
| 196 | + $out = []; | |
| 197 | + foreach ($code as $c) $out[] = preg_replace('/^\s*([\.a-zA-Z_][a-zA-Z0-9_]*)\s*:/m', '<span style="color: '.$color.';">$1</span>:', $c); | |
| 198 | + return $out; | |
| 199 | + } | |
| 200 | + | |
| 201 | + private function addSection(array $code): array { | |
| 202 | + $color1 = $this->handler->getColors()['label']; | |
| 203 | + $color2 = $this->handler->getColors()['register']; | |
| 204 | + $color3 = $this->handler->getColors()['number']; | |
| 205 | + $out = []; | |
| 206 | + | |
| 207 | + foreach ($code as $c) { | |
| 208 | + $cur = $c; | |
| 209 | + | |
| 210 | + $cur = preg_replace( | |
| 211 | + '/^(?:(section|default|segment|group)\s+)([\w.][\w.\-]*)(?:\s*(?:;.*)?)?$/im', | |
| 212 | + '<span style="color: '.$color1.';">$1</span> <span style="color: '.$color2.';">$2</span>', | |
| 213 | + $cur); | |
| 214 | + $cur = preg_replace( | |
| 215 | + '/^(bits)\s+(16|32|64)(?:\s*(?:;.*)?)?$/im', | |
| 216 | + '<span style="color: '.$color1.';">$1</span> <span style="color: '.$color3.';">$2</span>', | |
| 217 | + $cur); | |
| 218 | + | |
| 219 | + $out[] = $cur; | |
| 220 | + } | |
| 221 | + | |
| 222 | + return $out; | |
| 223 | + } | |
| 224 | + | |
| 225 | + private function add(array $code, string $type, ?string $header = null): array { | |
| 226 | + $tok = null !== $header ? $this->handler->getTokens()[$type][$header] : $this->handler->getTokens()[$type]; | |
| 227 | + $color = $this->handler->getColors()[$type]; | |
| 228 | + $pattern = '/\b('.implode('|', array_map(fn($r) => preg_quote($r, '/'), $tok)).')\b/i'; | |
| 229 | + $so = '<span style="color: '.$color.';">'; | |
| 230 | + $sc = '</span>'; | |
| 231 | + $out = []; | |
| 232 | + foreach ($code as $c) { | |
| 233 | + $out[] = preg_replace_callback($pattern, function ($m) use ($so, $sc) { return $so.$m[0].$sc; }, $c); | |
| 234 | + } | |
| 235 | + return $out; | |
| 236 | + } | |
| 237 | + | |
| 238 | + private function addFunction(array $code): array { | |
| 239 | + $color = $this->handler->getColors()['function']; | |
| 240 | + $out = []; | |
| 241 | + | |
| 242 | + foreach ($code as $c) { | |
| 243 | + $cur = $c; | |
| 244 | + $cur = preg_replace_callback("/\b(.*)\(\b/i", fn($m) => '<span style="color: '.$color.';">'.$m[0].'</span>', $cur); | |
| 245 | + $out[] = $cur; | |
| 246 | + } | |
| 247 | + | |
| 248 | + return $out; | |
| 249 | + } | |
| 250 | + | |
| 251 | + private function addDirective(array $code): array { | |
| 252 | + $tok = $this->handler->getTokens()['directive']; | |
| 253 | + $color1 = $this->handler->getColors()['directive']; | |
| 254 | + $color2 = $this->handler->getColors()['register']; | |
| 255 | + $pattern = implode('|', array_map(fn($r) => preg_quote($r, '/'), $tok)); | |
| 256 | + $out = []; | |
| 257 | + | |
| 258 | + foreach ($code as $c) { | |
| 259 | + $cur = $c; | |
| 260 | + $cur = preg_replace_callback("/\b({$pattern})\b/i", fn($m) => '<span style="color: '.$color1.';">'.$m[0].'</span>', $cur); | |
| 261 | + $cur = preg_replace_callback( | |
| 262 | + '/^\s*([a-zA-Z_][a-zA-Z0-9_$.@]*)\s+('.$pattern.')\b\s+(.+?)(?:\s*(?:;.*)?)?$/im', | |
| 263 | + function ($m) use ($color1, $color2) { | |
| 264 | + $l = $m[1]; | |
| 265 | + $d = $m[2]; | |
| 266 | + $v = $m[3]; | |
| 267 | + | |
| 268 | + // if (strcasecmp($d, 'equ') === 0) $v = preg_replace('/\$-[a-zA-Z_][a-zA-Z0-9_]*/i', '<span style="color: '.$color1.';">$o</span>', $v); | |
| 269 | + return sprintf( | |
| 270 | + '<span style="color: %s;">%s</span> '.'<span style="color: %s;">%s</span> %s', | |
| 271 | + $color1, $l, $color2, $v, $v | |
| 272 | + ); | |
| 273 | + }, $cur); | |
| 274 | + | |
| 275 | + $out[] = $cur; | |
| 276 | + } | |
| 277 | + | |
| 278 | + return $out; | |
| 279 | + } | |
| 280 | +} |
| @@ -0,0 +1,40 @@ | ||
| 1 | +<?php | |
| 2 | +namespace Site\Lib\Syntax; | |
| 3 | + | |
| 4 | +use Site\Lib\Syntax\SyntaxInterface; | |
| 5 | + | |
| 6 | +class Asm6502 implements SyntaxInterface { | |
| 7 | + private array $colors = []; | |
| 8 | + private string $comment = ';'; | |
| 9 | + private ?array $multiline = null; | |
| 10 | + | |
| 11 | + private array $tokens = [ | |
| 12 | + 'register' => [ | |
| 13 | + // 16ビット | |
| 14 | + // 8ビット | |
| 15 | + ], | |
| 16 | + 'operator' => [ | |
| 17 | + ], | |
| 18 | + 'directive' => [ | |
| 19 | + ], | |
| 20 | + ]; | |
| 21 | + | |
| 22 | + public function __construct() { | |
| 23 | + global $colorPalette; | |
| 24 | + | |
| 25 | + $this->colors = [ | |
| 26 | + 'comment' => $colorPalette['dark']['green'], | |
| 27 | + 'directive' => $colorPalette['dark']['pink'], | |
| 28 | + 'label' => $colorPalette['light']['yellow'], | |
| 29 | + 'number' => $colorPalette['light']['green'], | |
| 30 | + 'operator' => $colorPalette['dark']['blue'], | |
| 31 | + 'register' => $colorPalette['dark']['cyan'], | |
| 32 | + 'string' => $colorPalette['medium']['orange'], | |
| 33 | + ]; | |
| 34 | + } | |
| 35 | + | |
| 36 | + public function getColors(): array { return $this->colors; } | |
| 37 | + public function getComment(): ?string { return $this->comment; } | |
| 38 | + public function getMultiline(): ?array { return $this->multiline; } | |
| 39 | + public function getTokens(): array { return $this->tokens; } | |
| 40 | +} |
| @@ -0,0 +1,39 @@ | ||
| 1 | +<?php | |
| 2 | +namespace Site\Lib\Syntax; | |
| 3 | + | |
| 4 | +use Site\Lib\Syntax\SyntaxInterface; | |
| 5 | + | |
| 6 | +class Asm68000 implements SyntaxInterface { | |
| 7 | + private array $colors = []; | |
| 8 | + private string $comment = ';'; | |
| 9 | + private ?array $multiline = null; | |
| 10 | + | |
| 11 | + private array $tokens = [ | |
| 12 | + 'register' => [ | |
| 13 | + // 16ビット | |
| 14 | + ], | |
| 15 | + 'operator' => [ | |
| 16 | + ], | |
| 17 | + 'directive' => [ | |
| 18 | + ], | |
| 19 | + ]; | |
| 20 | + | |
| 21 | + public function __construct() { | |
| 22 | + global $colorPalette; | |
| 23 | + | |
| 24 | + $this->colors = [ | |
| 25 | + 'comment' => $colorPalette['dark']['green'], | |
| 26 | + 'directive' => $colorPalette['dark']['pink'], | |
| 27 | + 'label' => $colorPalette['light']['yellow'], | |
| 28 | + 'number' => $colorPalette['light']['green'], | |
| 29 | + 'operator' => $colorPalette['dark']['blue'], | |
| 30 | + 'register' => $colorPalette['dark']['cyan'], | |
| 31 | + 'string' => $colorPalette['medium']['orange'], | |
| 32 | + ]; | |
| 33 | + } | |
| 34 | + | |
| 35 | + public function getColors(): array { return $this->colors; } | |
| 36 | + public function getComment(): ?string { return $this->comment; } | |
| 37 | + public function getMultiline(): ?array { return $this->multiline; } | |
| 38 | + public function getTokens(): array { return $this->tokens; } | |
| 39 | +} |
| @@ -0,0 +1,56 @@ | ||
| 1 | +<?php | |
| 2 | +namespace Site\Lib\Syntax; | |
| 3 | + | |
| 4 | +use Site\Lib\Syntax\SyntaxInterface; | |
| 5 | + | |
| 6 | +class AsmAarch32 implements SyntaxInterface { | |
| 7 | + private array $colors = []; | |
| 8 | + private string $comment = ';'; | |
| 9 | + private ?array $multiline = null; | |
| 10 | + | |
| 11 | + private array $tokens = [ | |
| 12 | + 'register' => [ | |
| 13 | + // フロート、SIMD、ベクター | |
| 14 | + 'd0', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', // 64 | |
| 15 | + 'd10', 'd11', 'd12', 'd13', 'd14', 'd15', 'd16', 'd17', 'd18', 'd19', // 64 | |
| 16 | + 'd20', 'd21', 'd22', 'd23', 'd24', 'd25', 'd26', 'd27', 'd28', 'd29', 'd30', 'd31', // 64 | |
| 17 | + 's0', 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', // 32 | |
| 18 | + 's10', 's11', 's12', 's13', 's14', 's15', 's16', 's17', 's18', 's19', // 32 | |
| 19 | + 's20', 's21', 's22', 's23', 's24', 's25', 's26', 's27', 's28', 's29', 's30', 's31', // 32 | |
| 20 | + 'q0', 'q1', 'q2', 'q3', 'q4', 'q5', 'q6', 'q7', 'q8', 'q9', 'q10', 'q11', 'q12', 'q13', 'q14', 'q15', | |
| 21 | + // GPR | |
| 22 | + 'r0', 'r1', 'r2', 'r3', 'r4', 'r5', 'r6', 'r7', 'r8', 'r9', 'r10', 'r11', 'r12', | |
| 23 | + 'r13' /*スタックポインター*/, 'r14' /*リンクレジスター*/, 'r15' /*プログラムカウンター*/, | |
| 24 | + ], | |
| 25 | + 'operator' => [ | |
| 26 | + 'add', 'sub', 'mul', 'umul', 'mla', 'madd', 'msub', | |
| 27 | + 'and', 'orr', 'eor', 'bic', 'mvn', 'eon', 'ldr', 'bl', | |
| 28 | + 'ldm', 'stm', 'ldrd', 'strd', 'ldrex', 'strex', | |
| 29 | + 'vadd', 'vmul', 'vmla', 'blx', 'cmp', | |
| 30 | + ], | |
| 31 | + 'directive' => [ | |
| 32 | + '.arch armv8-a', 'arch_extension', '.cfi_', '.global', '.globl', '.section', | |
| 33 | + '.equ', '.set', '.byte', '.hword', '.word', '.quad', | |
| 34 | + '.arm', '.code 32', '.thumb', '.code 16', | |
| 35 | + ], | |
| 36 | + ]; | |
| 37 | + | |
| 38 | + public function __construct() { | |
| 39 | + global $colorPalette; | |
| 40 | + | |
| 41 | + $this->colors = [ | |
| 42 | + 'comment' => $colorPalette['dark']['green'], | |
| 43 | + 'directive' => $colorPalette['dark']['pink'], | |
| 44 | + 'label' => $colorPalette['light']['yellow'], | |
| 45 | + 'number' => $colorPalette['light']['green'], | |
| 46 | + 'operator' => $colorPalette['dark']['blue'], | |
| 47 | + 'register' => $colorPalette['dark']['cyan'], | |
| 48 | + 'string' => $colorPalette['medium']['orange'], | |
| 49 | + ]; | |
| 50 | + } | |
| 51 | + | |
| 52 | + public function getColors(): array { return $this->colors; } | |
| 53 | + public function getComment(): ?string { return $this->comment; } | |
| 54 | + public function getMultiline(): ?array { return $this->multiline; } | |
| 55 | + public function getTokens(): array { return $this->tokens; } | |
| 56 | +} |
| @@ -0,0 +1,65 @@ | ||
| 1 | +<?php | |
| 2 | +namespace Site\Lib\Syntax; | |
| 3 | + | |
| 4 | +use Site\Lib\Syntax\SyntaxInterface; | |
| 5 | + | |
| 6 | +class AsmAarch64 implements SyntaxInterface { | |
| 7 | + private array $colors = []; | |
| 8 | + private string $comment = ';'; | |
| 9 | + private ?array $multiline = null; | |
| 10 | + | |
| 11 | + private array $tokens = [ | |
| 12 | + 'register' => [ | |
| 13 | + // フロート、SIMD、ベクター | |
| 14 | + 'd0', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', // 64 | |
| 15 | + 'd10', 'd11', 'd12', 'd13', 'd14', 'd15', 'd16', 'd17', 'd18', 'd19', // 64 | |
| 16 | + 'd20', 'd21', 'd22', 'd23', 'd24', 'd25', 'd26', 'd27', 'd28', 'd29', 'd30', 'd31', // 64 | |
| 17 | + 's0', 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', // 32 | |
| 18 | + 's10', 's11', 's12', 's13', 's14', 's15', 's16', 's17', 's18', 's19', // 32 | |
| 19 | + 's20', 's21', 's22', 's23', 's24', 's25', 's26', 's27', 's28', 's29', 's30', 's31', // 32 | |
| 20 | + 'v0', 'v1', 'v2', 'v3', 'v4', 'v5', 'v6', 'v7', 'v8', 'v9', | |
| 21 | + 'v10', 'v11', 'v12', 'v13', 'v14', 'v15', 'v16', 'v17', 'v18', 'v19', | |
| 22 | + 'v20', 'v21', 'v22', 'v23', 'v24', 'v25', 'v26', 'v27', 'v28', 'v29', 'v30', 'v31', | |
| 23 | + 'q16', 'q17', 'q18', 'q19', 'q20', 'q21', 'q22', 'q23', 'q24', 'q25', 'q26', 'q27', 'q28', 'q29', 'q30', 'q31', | |
| 24 | + // GPR | |
| 25 | + 'x0', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x9', | |
| 26 | + 'x10', 'x11', 'x12', 'x13', 'x14', 'x15', 'x16', 'x17', 'x18', 'x19', | |
| 27 | + 'x20', 'x21', 'x22', 'x23', 'x24', 'x25', 'x26', 'x27', 'x28', 'x29', 'x30', 'x31' /*ゼロレジスター*/, | |
| 28 | + 'w0', 'w1', 'w2', 'w3', 'w4', 'w5', 'w6', 'w7', 'w8', 'w9', | |
| 29 | + 'w10', 'w11', 'w12', 'w13', 'w14', 'w15', 'w16', 'w17', 'w18', 'w19', | |
| 30 | + 'w20', 'w21', 'w22', 'w23', 'w24', 'w25', 'w26', 'w27', 'w28', 'w29', 'w30', | |
| 31 | + 'xzr' /*ゼロレジスター*/, 'wzr' /*ゼロレジスター*/, | |
| 32 | + 'sp' /*スタックポインター*/, 'pc' /*プログラムカウンター*/, | |
| 33 | + ], | |
| 34 | + 'operator' => [ | |
| 35 | + 'add', 'sub', 'mul', 'umul', 'mla', 'madd', 'msub', | |
| 36 | + 'and', 'orr', 'eor', 'bic', 'mvn', 'eon', 'ldr', 'bl', | |
| 37 | + 'csel', 'cinc', 'cset', 'addv', 'smull', 'fmla', 'blr', 'cbz', 'cbnz', 'tbz', 'tbnz', | |
| 38 | + 'adpr', 'movz', 'movk', 'ldp', 'stp', 'ldxr', 'stxr', 'ldadd', 'ldclr', 'ldset', | |
| 39 | + ], | |
| 40 | + 'directive' => [ | |
| 41 | + '.arch armv8-a', 'arch_extension', '.cfi_', '.global', '.globl', '.section', | |
| 42 | + '.equ', '.set', '.byte', '.hword', '.word', '.quad', | |
| 43 | + '.req', '.aarch64', | |
| 44 | + ], | |
| 45 | + ]; | |
| 46 | + | |
| 47 | + public function __construct() { | |
| 48 | + global $colorPalette; | |
| 49 | + | |
| 50 | + $this->colors = [ | |
| 51 | + 'comment' => $colorPalette['dark']['green'], | |
| 52 | + 'directive' => $colorPalette['dark']['pink'], | |
| 53 | + 'label' => $colorPalette['light']['yellow'], | |
| 54 | + 'number' => $colorPalette['light']['green'], | |
| 55 | + 'operator' => $colorPalette['dark']['blue'], | |
| 56 | + 'register' => $colorPalette['dark']['cyan'], | |
| 57 | + 'string' => $colorPalette['medium']['orange'], | |
| 58 | + ]; | |
| 59 | + } | |
| 60 | + | |
| 61 | + public function getColors(): array { return $this->colors; } | |
| 62 | + public function getComment(): ?string { return $this->comment; } | |
| 63 | + public function getMultiline(): ?array { return $this->multiline; } | |
| 64 | + public function getTokens(): array { return $this->tokens; } | |
| 65 | +} |
| @@ -0,0 +1,40 @@ | ||
| 1 | +<?php | |
| 2 | +namespace Site\Lib\Syntax; | |
| 3 | + | |
| 4 | +use Site\Lib\Syntax\SyntaxInterface; | |
| 5 | + | |
| 6 | +class AsmMips implements SyntaxInterface { | |
| 7 | + private array $colors = []; | |
| 8 | + private string $comment = ';'; | |
| 9 | + private ?array $multiline = null; | |
| 10 | + | |
| 11 | + private array $tokens = [ | |
| 12 | + 'register' => [ | |
| 13 | + // 64ビット | |
| 14 | + // 32ビット | |
| 15 | + ], | |
| 16 | + 'operator' => [ | |
| 17 | + ], | |
| 18 | + 'directive' => [ | |
| 19 | + ], | |
| 20 | + ]; | |
| 21 | + | |
| 22 | + public function __construct() { | |
| 23 | + global $colorPalette; | |
| 24 | + | |
| 25 | + $this->colors = [ | |
| 26 | + 'comment' => $colorPalette['dark']['green'], | |
| 27 | + 'directive' => $colorPalette['dark']['pink'], | |
| 28 | + 'label' => $colorPalette['light']['yellow'], | |
| 29 | + 'number' => $colorPalette['light']['green'], | |
| 30 | + 'operator' => $colorPalette['dark']['blue'], | |
| 31 | + 'register' => $colorPalette['dark']['cyan'], | |
| 32 | + 'string' => $colorPalette['medium']['orange'], | |
| 33 | + ]; | |
| 34 | + } | |
| 35 | + | |
| 36 | + public function getColors(): array { return $this->colors; } | |
| 37 | + public function getComment(): ?string { return $this->comment; } | |
| 38 | + public function getMultiline(): ?array { return $this->multiline; } | |
| 39 | + public function getTokens(): array { return $this->tokens; } | |
| 40 | +} |
| @@ -0,0 +1,40 @@ | ||
| 1 | +<?php | |
| 2 | +namespace Site\Lib\Syntax; | |
| 3 | + | |
| 4 | +use Site\Lib\Syntax\SyntaxInterface; | |
| 5 | + | |
| 6 | +class AsmPower implements SyntaxInterface { | |
| 7 | + private array $colors = []; | |
| 8 | + private string $comment = ';'; | |
| 9 | + private ?array $multiline = null; | |
| 10 | + | |
| 11 | + private array $tokens = [ | |
| 12 | + 'register' => [ | |
| 13 | + // 64ビット | |
| 14 | + // 32ビット | |
| 15 | + ], | |
| 16 | + 'operator' => [ | |
| 17 | + ], | |
| 18 | + 'directive' => [ | |
| 19 | + ], | |
| 20 | + ]; | |
| 21 | + | |
| 22 | + public function __construct() { | |
| 23 | + global $colorPalette; | |
| 24 | + | |
| 25 | + $this->colors = [ | |
| 26 | + 'comment' => $colorPalette['dark']['green'], | |
| 27 | + 'directive' => $colorPalette['dark']['pink'], | |
| 28 | + 'label' => $colorPalette['light']['yellow'], | |
| 29 | + 'number' => $colorPalette['light']['green'], | |
| 30 | + 'operator' => $colorPalette['dark']['blue'], | |
| 31 | + 'register' => $colorPalette['dark']['cyan'], | |
| 32 | + 'string' => $colorPalette['medium']['orange'], | |
| 33 | + ]; | |
| 34 | + } | |
| 35 | + | |
| 36 | + public function getColors(): array { return $this->colors; } | |
| 37 | + public function getComment(): ?string { return $this->comment; } | |
| 38 | + public function getMultiline(): ?array { return $this->multiline; } | |
| 39 | + public function getTokens(): array { return $this->tokens; } | |
| 40 | +} |
| @@ -0,0 +1,41 @@ | ||
| 1 | +<?php | |
| 2 | +namespace Site\Lib\Syntax; | |
| 3 | + | |
| 4 | +use Site\Lib\Syntax\SyntaxInterface; | |
| 5 | + | |
| 6 | +class AsmRiscV implements SyntaxInterface { | |
| 7 | + private array $colors = []; | |
| 8 | + private string $comment = ';'; | |
| 9 | + private ?array $multiline = null; | |
| 10 | + | |
| 11 | + private array $tokens = [ | |
| 12 | + 'register' => [ | |
| 13 | + // 128ビット | |
| 14 | + // 64ビット | |
| 15 | + // 32ビット | |
| 16 | + ], | |
| 17 | + 'operator' => [ | |
| 18 | + ], | |
| 19 | + 'directive' => [ | |
| 20 | + ], | |
| 21 | + ]; | |
| 22 | + | |
| 23 | + public function __construct() { | |
| 24 | + global $colorPalette; | |
| 25 | + | |
| 26 | + $this->colors = [ | |
| 27 | + 'comment' => $colorPalette['dark']['green'], | |
| 28 | + 'directive' => $colorPalette['dark']['pink'], | |
| 29 | + 'label' => $colorPalette['light']['yellow'], | |
| 30 | + 'number' => $colorPalette['light']['green'], | |
| 31 | + 'operator' => $colorPalette['dark']['blue'], | |
| 32 | + 'register' => $colorPalette['dark']['cyan'], | |
| 33 | + 'string' => $colorPalette['medium']['orange'], | |
| 34 | + ]; | |
| 35 | + } | |
| 36 | + | |
| 37 | + public function getColors(): array { return $this->colors; } | |
| 38 | + public function getComment(): ?string { return $this->comment; } | |
| 39 | + public function getMultiline(): ?array { return $this->multiline; } | |
| 40 | + public function getTokens(): array { return $this->tokens; } | |
| 41 | +} |
| @@ -0,0 +1,56 @@ | ||
| 1 | +<?php | |
| 2 | +namespace Site\Lib\Syntax; | |
| 3 | + | |
| 4 | +use Site\Lib\Syntax\SyntaxInterface; | |
| 5 | + | |
| 6 | +class AsmX8664 implements SyntaxInterface { | |
| 7 | + private array $colors = []; | |
| 8 | + private string $comment = ';'; | |
| 9 | + private ?array $multiline = null; | |
| 10 | + | |
| 11 | + private array $tokens = [ | |
| 12 | + 'register' => [ | |
| 13 | + // 64ビット | |
| 14 | + 'rax', 'rbx', 'rcx', 'rdx', 'rsi', 'rdi', 'r8', 'r8d', 'r9', 'r9d', 'r10', 'r10d', 'r11', 'r11d', 'r12', 'r12d', 'r13', 'r13d', 'r14', 'r14d', 'r15', 'r15d', | |
| 15 | + // 32ビット | |
| 16 | + 'eax', 'ebx', 'ecx', 'edx', 'esi', 'edi', | |
| 17 | + // 16ビット | |
| 18 | + 'al', 'bl', 'cl', 'dl', | |
| 19 | + 'ah', 'bh', 'ch', 'dh', | |
| 20 | + 'spl', 'bpl', 'sil', 'dil', | |
| 21 | + ], | |
| 22 | + 'operator' => [ | |
| 23 | + 'mov', 'lea', | |
| 24 | + 'add', 'sub', 'div', 'imul', 'dec', 'inc', | |
| 25 | + 'xor', 'or', 'and', | |
| 26 | + 'js', 'jmp', 'jz', 'jnz', 'ja', 'jb', | |
| 27 | + 'pop', 'push', | |
| 28 | + 'call', 'ret', 'syscall', 'cmp', 'test', 'stosb', | |
| 29 | + ], | |
| 30 | + 'directive' => [ | |
| 31 | + 'db', 'dw', 'dd', 'dw', | |
| 32 | + 'equ', 'global', 'extern', | |
| 33 | + 'resb', 'resw', 'resd', 'resq', | |
| 34 | + ], | |
| 35 | + ]; | |
| 36 | + | |
| 37 | + public function __construct() { | |
| 38 | + global $colorPalette; | |
| 39 | + | |
| 40 | + $this->colors = [ | |
| 41 | + 'comment' => $colorPalette['dark']['green'], | |
| 42 | + 'directive' => $colorPalette['dark']['pink'], | |
| 43 | + 'label' => $colorPalette['light']['yellow'], | |
| 44 | + 'number' => $colorPalette['light']['green'], | |
| 45 | + 'operator' => $colorPalette['dark']['blue'], | |
| 46 | + 'register' => $colorPalette['dark']['cyan'], | |
| 47 | + 'string' => $colorPalette['medium']['orange'], | |
| 48 | + ]; | |
| 49 | + } | |
| 50 | + | |
| 51 | + public function getColors(): array { return $this->colors; } | |
| 52 | + public function getComment(): ?string { return $this->comment; } | |
| 53 | + public function getInclude(array $code): ?array { return null; } | |
| 54 | + public function getMultiline(): ?array { return $this->multiline; } | |
| 55 | + public function getTokens(): array { return $this->tokens; } | |
| 56 | +} |
| @@ -0,0 +1,66 @@ | ||
| 1 | +<?php | |
| 2 | +namespace Site\Lib\Syntax; | |
| 3 | + | |
| 4 | +use Site\Lib\Syntax\SyntaxInterface; | |
| 5 | + | |
| 6 | +class AsmZ80 implements SyntaxInterface { | |
| 7 | + private array $colors = []; | |
| 8 | + private string $comment = ';'; | |
| 9 | + private ?array $multiline = null; | |
| 10 | + | |
| 11 | + private array $tokens = [ | |
| 12 | + 'register' => [ | |
| 13 | + // 16ビット | |
| 14 | + "bc'", "de'", "hl'", | |
| 15 | + 'bc', 'de', 'hl', | |
| 16 | + 'ix' /*指標レジスター*/, 'iy' /*指標レジスター*/, | |
| 17 | + 'sp' /*スタックポインター*/, 'pc' /*プログラムカウンター*/, | |
| 18 | + // 8ビット | |
| 19 | + 'a', 'b', 'd', 'h', 'f', 'c', 'e', 'l', | |
| 20 | + "a'", "b'", "d'", "h'", "f'", "c'", "e'", "l'", | |
| 21 | + 'a', 'b', 'd', 'h', 'f', 'c', 'e', 'l', | |
| 22 | + ], | |
| 23 | + 'operator' => [ | |
| 24 | + // Z80 + GBZ80 + eZ80 | |
| 25 | + 'adc', 'add', 'and', 'bit', 'call', 'ccf', 'cp', 'daa', 'dec', 'di', 'djnz', 'ei', | |
| 26 | + 'halt', 'im0', 'im1', 'im2', 'im', 'inc', 'in', 'jp', 'jr', 'ldd', | |
| 27 | + 'nop', 'otir', 'otdr', 'or', 'pop', 'push', 'retn', 'reti', 'ret', 'res', | |
| 28 | + 'rst', 'rrc', 'rr', 'rdc', 'rl', 'sub', 'srl', 'sra', 'sla', 'set', 'scf', 'sbc', 'xor', | |
| 29 | + // Z80 + GBZ80のみ | |
| 30 | + 'sll', 'ld', | |
| 31 | + // eZ80のみ | |
| 32 | + 'ind2', 'indmr', 'indrx', 'indm', 'inimr', 'inim', 'ini2r', 'ini2', 'lea', 'mlt', | |
| 33 | + 'otirx', 'otimr', 'otim', 'oti2r', 'otdrx', 'otdmr', 'otdm', 'otd2r', 'out0', 'outd2', | |
| 34 | + 'outi2', 'pea', 'rsmix', 'slp', 'stmix', 'tstio', 'tst', '.is', 'xxx.S', 'xxx.L', '.il', '.sis', '.lil', | |
| 35 | + // Z80のみ | |
| 36 | + 'cpdr', 'cpir', 'cpd', 'cpi', 'exx', 'ex', 'outd', 'inir', 'ini', 'indr', 'ind', 'lddr', 'ldir', 'ldi', | |
| 37 | + 'neg', 'outi', 'outdi', 'out', 'rld', 'rrd', | |
| 38 | + // GBZ80のみ | |
| 39 | + 'outd', 'stop', 'swap', | |
| 40 | + ], | |
| 41 | + 'directive' => [ | |
| 42 | + // 'db', 'dw', 'dd', 'dw', | |
| 43 | + // 'equ', 'global', 'extern', | |
| 44 | + // 'resb', 'resw', 'resd', 'resq', | |
| 45 | + ], | |
| 46 | + ]; | |
| 47 | + | |
| 48 | + public function __construct() { | |
| 49 | + global $colorPalette; | |
| 50 | + | |
| 51 | + $this->colors = [ | |
| 52 | + 'comment' => $colorPalette['dark']['green'], | |
| 53 | + 'directive' => $colorPalette['dark']['pink'], | |
| 54 | + 'label' => $colorPalette['light']['yellow'], | |
| 55 | + 'number' => $colorPalette['light']['green'], | |
| 56 | + 'operator' => $colorPalette['dark']['blue'], | |
| 57 | + 'register' => $colorPalette['dark']['cyan'], | |
| 58 | + 'string' => $colorPalette['medium']['orange'], | |
| 59 | + ]; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public function getColors(): array { return $this->colors; } | |
| 63 | + public function getComment(): ?string { return $this->comment; } | |
| 64 | + public function getMultiline(): ?array { return $this->multiline; } | |
| 65 | + public function getTokens(): array { return $this->tokens; } | |
| 66 | +} |
| @@ -0,0 +1,277 @@ | ||
| 1 | +<?php | |
| 2 | +namespace Site\Lib\Syntax; | |
| 3 | + | |
| 4 | +use Site\Lib\Syntax\SyntaxInterface; | |
| 5 | + | |
| 6 | +class C implements SyntaxInterface { | |
| 7 | + private array $colors = []; | |
| 8 | + private string $comment = '//'; | |
| 9 | + private array $multiline = ['/*', '*/']; | |
| 10 | + | |
| 11 | + private array $tokens = [ | |
| 12 | + 'keyword' => [ | |
| 13 | + // C23 | |
| 14 | + 'alignas', 'alignof', 'bool', 'constexpr', 'false', 'nullptr', 'static_assert', 'thread_local', 'true', 'typeof', 'typeof_unqual', | |
| 15 | + '_BitInt', '_Decimal128', '_Decimal32', '_Decimal64', | |
| 16 | + // C11 | |
| 17 | + '_Alignas', '_Alignof', '_Atomic', '_Generic', '_Noreturn', '_Static_assert', '_Thread_local', | |
| 18 | + // C99 | |
| 19 | + 'inline', 'restrict', '_Bool', '_Complex', '_Imaginary', | |
| 20 | + // C89 | |
| 21 | + 'asm', 'auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do', 'double', 'else', 'enum', 'extern', 'float', 'fortran', 'for', 'goto', 'if', 'inline', | |
| 22 | + 'int', 'long', 'noreturn', 'register', 'return', 'short', 'signed', 'sizeof', 'static', 'struct', 'switch', 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while', | |
| 23 | + // ISO | |
| 24 | + 'FILE', | |
| 25 | + ], | |
| 26 | + 'libc' => [ | |
| 27 | + // ISO C | |
| 28 | + 'assert.h' => [ // C89 | |
| 29 | + 'assert', | |
| 30 | + ], | |
| 31 | + 'complex.h' => [ // C99 | |
| 32 | + 'cabs', 'cabsf', 'cabsl', 'cacos', 'cacosf', 'cacosl', 'cacosh', 'cacoshf', 'cacoshl', 'carg', 'cargf', 'cargl', 'casin', 'casinf', 'casinl', 'casinh', 'casinhf', 'casinhl', 'catan', 'catanf', 'catanl', 'catanh', 'catanhf', 'catanhl', 'ccos', 'ccosf', 'ccosl', 'ccosh', 'ccoshf', 'ccoshl', 'cexp', 'cexpf', 'cexpl', | |
| 33 | + 'cimag', 'cimagf', 'cimagl', 'clog', 'clogf', 'clogl', 'conj', 'conjf', 'conjl', 'cpow', 'cpowf', 'cpowl', 'cproj', 'cprojf', 'cprojl', 'creal', 'crealf', 'creall', | |
| 34 | + 'csqrt', 'csqrtf', 'csqrtl', 'csin', 'csinf', 'csinl', 'csinh', 'csinhf', 'csinhl', 'ctan', 'ctanf', 'ctanl', 'ctanh', 'ctanhf', 'ctanhl', | |
| 35 | + ], | |
| 36 | + 'ctype.h' => [ // C89 | |
| 37 | + 'isalnum', 'isalpha', 'isblank', 'iscntrl', 'isdigit', 'isgraph', 'islower', 'isprint', 'ispunct', 'isspace', 'isupper', 'isxdigit', 'tolower', 'toupper', | |
| 38 | + ], | |
| 39 | + 'errno.h' => [ // C89 | |
| 40 | + 'errno', | |
| 41 | + ], | |
| 42 | + 'fenv.h' => [ // C99 | |
| 43 | + 'feclearexcept', 'fegetround', 'fegetenv', 'fegetexpectflag', 'feholdexcept', 'feraiseexcept', 'fesetround', 'fesetenv', 'fesetexpectflag', 'fetestexcept', | |
| 44 | + 'feupdateenv', | |
| 45 | + // __STDC_IEC_60559_DFP__ | |
| 46 | + 'fe_dec_getround', 'fe_dec_setround', | |
| 47 | + ], | |
| 48 | + 'inttypes.h' => [ // C99 | |
| 49 | + 'imaxabs', 'imaxdiv', 'strtoimax', 'strtoumax', 'wcstoimax', 'wcstoumax', | |
| 50 | + ], | |
| 51 | + 'locale.h' => [ // C89 | |
| 52 | + 'localeconv', 'setlocale', | |
| 53 | + ], | |
| 54 | + 'math.h' => [ // C89 | |
| 55 | + 'acos', 'acosf', 'acosl', 'acosh', 'acoshf', 'acoshl', 'asin', 'asinf', 'asinl', 'asinh', 'asinhf', 'asinhl', 'atan', 'atanf', 'atanl', 'atanh', 'atanhf', 'atanhl', | |
| 56 | + 'atan2', 'atan2f', 'atan2l', 'cbrt', 'cbrtf', 'cbrtl', 'ceil', 'ceilf', 'ceill', 'copysign', 'copysignf', 'copysignl', 'cos', 'cosf', 'cosl', 'erf', 'erff', 'erfl', | |
| 57 | + 'erfc', 'erfcf', 'erfcl', 'exp', 'expf', 'expl', 'exp2', 'exp2f', 'exp2l', 'expml', 'expmlf', 'expmll', 'fabs', 'fabsf', 'fabsl', 'fdim', 'fdimf', 'fdiml', | |
| 58 | + 'floor', 'floorf', 'floorl', 'fma', 'fmaf', 'fmal', 'fmax', 'fmaxf', 'fmaxl', 'fmin', 'fminf', 'fminl', 'fpclassify', 'frexp', 'frexpf', 'frexpl', | |
| 59 | + 'hypot', 'hypotf', 'hypotl', 'ilogb', 'ilogbf', 'ilogbl', 'isfinite', 'isgreater', 'isgreaterequal', 'isinf', 'isless', 'islessequal', 'islessgreater', 'isnan', | |
| 60 | + 'isnormal', 'isunordered', 'ldexp', 'ldexpf', 'ldexpl', 'lgamma', 'lgammaf', 'lgammal', 'log', 'logf', 'logl', 'log10', 'log10f', 'log10l', 'log2', 'log2f', 'log2l', | |
| 61 | + 'logb', 'logbf', 'logbl', 'loglp', 'loglpf', 'loglpl', 'lrint', 'lrintf', 'lrintl', 'llrint', 'llrintf', 'llrintl', 'lround', 'lroundf', 'lroundl', 'llround', 'llroundf', 'llroundl', 'modf', 'modff', 'modfl', 'nan', 'nanf', 'nanl', 'nearbyint', 'nearbyintf', 'nearbyintl', 'nextafter', 'nextafterf', 'nextafterl', | |
| 62 | + 'nexttoward', 'nexttowardf', 'nexttowardl', 'pow', 'powf', 'powl', 'remainder', 'remainderf', 'remainderl', 'remquo', 'remquof', 'remquol', 'rint', 'rintf', 'rintl', | |
| 63 | + 'round', 'roundf', 'roundl', 'scalbn', 'scalbnf', 'scalbnl', 'scalbln', 'scalblnf', 'scalblnl', 'signbit', 'sin', 'sinf', 'sinl', 'sinh', 'sinhf', 'sinhl', | |
| 64 | + 'sqrt', 'sqrtf', 'sqrtl', 'tan', 'tanf', 'tanl', 'tanh', 'tanhf', 'tanhl', 'tgamma', 'tgammaf', 'tgammal', 'trunc', 'truncf', 'truncl', | |
| 65 | + ], | |
| 66 | + 'setjmp.h' => [ // C89 | |
| 67 | + 'longjmp', 'setjmp', | |
| 68 | + ], | |
| 69 | + 'signal.h' => [ // C89 | |
| 70 | + 'raise', 'signal', | |
| 71 | + ], | |
| 72 | + 'stdarg.h' => [ // C89 | |
| 73 | + 'va_arg', 'va_copy', 'va_end', 'va_start', | |
| 74 | + ], | |
| 75 | + 'stdatomic.h' => [ // C11 | |
| 76 | + 'atomic_fetch_add', 'atomic_fetch_add_explicit', 'atomic_fetch_and', 'atomic_fetch_and_explicit', 'atomic_fetch_or', 'atomic_fetch_or_explicit', | |
| 77 | + 'atomic_fetch_sub', 'atomic_fetch_sub_explicit', 'atomic_fetch_xor', 'atomic_fetch_xor_explicit', 'atomic_flag', 'atomic_flag_clear', 'atomic_flag_clear_explicit', | |
| 78 | + 'atomic_flag_test_and_set', 'atomic_flag_test_and_set_explicit', 'atomic_init', 'atomic_is_lock_free', 'atomic_load', 'atomic_load_explicit', 'atomic_signal_fence', | |
| 79 | + 'atomic_store', 'atomic_store_explicit', 'atomic_thread_fence', 'kill_dependency', 'memory_order', | |
| 80 | + ], | |
| 81 | + 'stdbit.h' => [ // C23 | |
| 82 | + 'stdc_bit_ceil_uc', 'stdc_bit_ceil_us', 'stdc_bit_ceil_ui', 'stdc_bit_ceil_ul', 'stdc_bit_ceil_ull', 'stdc_bit_ceil', | |
| 83 | + 'stdc_bit_floor_uc', 'stdc_bit_floor_us', 'stdc_bit_floor_ui', 'stdc_bit_floor_ul', 'stdc_bit_floor_ull', 'stdc_bit_floor', | |
| 84 | + 'stdc_bit_width_uc', 'stdc_bit_width_us', 'stdc_bit_width_ui', 'stdc_bit_width_ul', 'stdc_bit_width_ull', 'stdc_bit_width', | |
| 85 | + 'stdc_count_ones_uc', 'stdc_count_ones_us', 'stdc_count_ones_ui', 'stdc_count_ones_ul', 'stdc_count_ones_ull', 'stdc_count_ones', | |
| 86 | + 'stdc_count_zeros_uc', 'stdc_count_zeros_us', 'stdc_count_zeros_ui', 'stdc_count_zeros_ul', 'stdc_count_zeros_ull', 'stdc_count_zeros', | |
| 87 | + 'stdc_first_leading_ones_uc', 'stdc_first_leading_ones_us', 'stdc_first_leading_ones_ui', 'stdc_first_leading_ones_ul', 'stdc_first_leading_ones_ull', | |
| 88 | + 'stdc_first_leading_ones', | |
| 89 | + 'stdc_first_leading_zeros_uc', 'stdc_first_leading_zeros_us', 'stdc_first_leading_zeros_ui', 'stdc_first_leading_zeros_ul', 'stdc_first_leading_zeros_ull', | |
| 90 | + 'stdc_first_leading_zeros', | |
| 91 | + 'stdc_first_trailing_ones_uc', 'stdc_first_trailing_ones_us', 'stdc_first_trailing_ones_ui', 'stdc_first_trailing_ones_ul', 'stdc_first_trailing_ones_ull', | |
| 92 | + 'stdc_first_trailing_ones', | |
| 93 | + 'stdc_first_trailing_zeros_uc', 'stdc_first_trailing_zeros_us', 'stdc_first_trailing_zeros_ui', 'stdc_first_trailing_zeros_ul', 'stdc_first_trailing_zeros_ull', | |
| 94 | + 'stdc_first_trailing_zeros', | |
| 95 | + 'stdc_has_single_bit_uc', 'stdc_has_single_bit_us', 'stdc_has_single_bit_ui', 'stdc_has_single_bit_ul', 'stdc_has_single_bit_ull', 'stdc_has_single_bit', | |
| 96 | + 'stdc_leading_ones_uc', 'stdc_leading_ones_us', 'stdc_leading_ones_ui', 'stdc_leading_ones_ul', 'stdc_leading_ones_ull', 'stdc_leading_ones', | |
| 97 | + 'stdc_leading_zeros_uc', 'stdc_leading_zeros_us', 'stdc_leading_zeros_ui', 'stdc_leading_zeros_ul', 'stdc_leading_zeros_ull', 'stdc_leading_zeros', | |
| 98 | + 'stdc_trailing_ones_uc', 'stdc_trailing_ones_us', 'stdc_trailing_ones_ui', 'stdc_trailing_ones_ul', 'stdc_trailing_ones_ull', 'stdc_trailing_ones', | |
| 99 | + 'stdc_trailing_zeros_uc', 'stdc_trailing_zeros_us', 'stdc_trailing_zeros_ui', 'stdc_trailing_zeros_ul', 'stdc_trailing_zeros_ull', 'stdc_trailing_zeros', | |
| 100 | + 'stdc_rotate_left_uc', 'stdc_rotate_left_us', 'stdc_rotate_left_ui', 'stdc_rotate_left_ul', 'stdc_rotate_left_ull', 'stdc_rotate_left', | |
| 101 | + 'stdc_rotate_right_uc', 'stdc_rotate_right_us', 'stdc_rotate_right_ui', 'stdc_rotate_right_ul', 'stdc_rotate_right_ull', 'stdc_rotate_right', | |
| 102 | + ], | |
| 103 | + 'stdckdint.h' => [ // C23 | |
| 104 | + 'ckd_add', 'ckd_sub', 'ckd_mul', | |
| 105 | + ], | |
| 106 | + 'stdio.h' => [ // C89 | |
| 107 | + 'clearerr', 'fclose', 'feof', 'ferror', 'fflush', 'fgetc', 'fgetpos', 'fgets', 'fopen', 'fprintf', 'fputc', 'fputs', 'fread', 'freopen', 'fscanf', 'fseek', | |
| 108 | + 'fseekpos', 'fsetpos', 'ftell', 'fwrite', 'getc', 'getchar', 'perror', 'printf', 'putc', 'putchar', 'puts', 'remove', 'rename', 'rewind', 'scanf', 'setbuf', | |
| 109 | + 'setvbuf', 'snprintf', 'sprintf', 'sscanf', 'tmpfile', 'tmpnam', 'ungetc', 'vfprintf', 'vfscanf', 'vprintf', 'vscanf', 'vsnprintf', 'vsprintf', 'vsscanf', | |
| 110 | + // __STDC_WANT_LIB_EXT1__ | |
| 111 | + 'fopen_s', 'fprintf_s', 'freopen_s', 'fscanf_s', 'gets_s', 'printf_s', 'scanf_s', 'snprintf_s', 'sprintf_s', 'sscanf_s', 'tmpfile_s', 'tmpnam_s', | |
| 112 | + 'vfprintf_s', 'vfscanf_s', 'vprintf_s', 'vscanf_s', 'vsnprintf_s', 'vsprintf_s', 'vsscanf_s', | |
| 113 | + ], | |
| 114 | + 'stdlib.h' => [ // C89 | |
| 115 | + 'abort', 'abs', 'aligned_alloc', 'at_quick_exit', 'atexit', 'atof', 'atoi', 'atol', 'atoll', 'bsearch', 'calloc', 'div', 'exit', '_Exit', 'free', 'free_sized', | |
| 116 | + 'free_aligned_sized', 'labs', 'llabs', 'ldiv', 'lldiv', 'malloc', 'mblen', 'mbtowc', 'mbstowcs', 'memalignment', 'qsort', 'quick_exit', 'rand', 'realloc', 'srand', | |
| 117 | + 'strfromd', 'strfromf', 'strfroml', 'strtod', 'strtof', 'strtold', 'strtol', 'strtoll', 'strtoul', 'strtoull', 'system', 'wctomb', 'wcstombs', | |
| 118 | + // __STDC_IEC_60559_DFP__ | |
| 119 | + 'strfromd32', 'strfromd64', 'strfromd128', 'strtod32', 'strtod64', 'strtod128', | |
| 120 | + // __STDC_WANT_IEC_60559_TYPES_EXT__ | |
| 121 | + 'strfromdN', 'strfromdNx', 'strfromencfN', 'strfromencdecdN', 'strfromencbindN', 'strfromfN', 'strfromfNx', 'strtodN', 'strtodNx', 'strtofN', 'strtofNx', | |
| 122 | + 'strtoencfN', 'strtoencdecdN', 'strtoencbindN', | |
| 123 | + // __STDC_WANT_LIB_EXT1__ | |
| 124 | + 'abort_handler_s', 'bsearch_s', 'getenv_s', 'ignore_handler_s', 'mbstowcs_s', 'qsort_s', 'set_constraint_handler_s', 'wcstomb_s', 'wcstombs_s', | |
| 125 | + ], | |
| 126 | + 'stdmchar.h' => [ // C29 | |
| 127 | + 'stdc_mcnrtoc16n', 'stdc_mcnrtoc32n', 'stdc_mcnrtoc8n', 'stdc_mcnrtomcn', 'stdc_mcnrtomwcn', 'stdc_mcsnrtoc16sn', 'stdc_mcsnrtoc32sn', 'stdc_mcsnrtoc8sn', | |
| 128 | + 'stdc_mwcnrtomcn', 'stdc_mcsnrtomcsn', 'stdc_mwcnrtomwcn', 'stdc_mcsnrtomwcsn', 'stdc_mwcnrtoc16n', 'stdc_mwcnrtoc32n', 'stdc_mwcnrtoc8n', 'stdc_mwcsnrtoc16sn', | |
| 129 | + 'stdc_mwcsnrtoc32sn', 'stdc_mwcsnrtoc8sn', 'stdc_mwcsnrtomcsn', 'stdc_mwcsnrtomwcsn', 'stdc_c16nrtoc16n', 'stdc_c16nrtoc32n', 'stdc_c16nrtoc8n', 'stdc_c16nrtomcn', | |
| 130 | + 'stdc_c16nrtomwcn', 'stdc_c16snrtoc8sn', 'stdc_c16snrtoc16sn', 'stdc_c16snrtoc32sn', 'stdc_c16snrtomwcsn', 'stdc_c16snrtomcsn', 'stdc_c32nrtoc16n', 'stdc_c32nrtoc32n', | |
| 131 | + 'stdc_c32nrtoc8n', 'stdc_c32nrtomcn', 'stdc_c32nrtomwcn', 'stdc_c32snrtoc16sn', 'stdc_c32snrtoc32sn', 'stdc_c32snrtoc8sn', 'stdc_c32snrtomcsn', 'stdc_c32snrtomwcsn', | |
| 132 | + 'stdc_c8nrtoc16n', 'stdc_c8nrtoc32n', 'stdc_c8nrtoc8n', 'stdc_c8nrtomcn', 'stdc_c8nrtomwcn', 'stdc_c8snrtoc16sn', 'stdc_c8snrtoc32sn', 'stdc_c8snrtoc8sn', 'stdc_c8snrtomwcsn', 'stdc_c8snrtomcsn', | |
| 133 | + ], | |
| 134 | + 'string.h' => [ // C89 | |
| 135 | + 'memccpy', 'memchr', 'memcmp', 'memcpy', 'memcpy_s', 'memmove', 'memmove_s', 'memset', 'memset_explicit', 'memset_s', | |
| 136 | + 'strcat', 'strcat_s', 'strchr', 'strcmp', 'strcoll', 'strcpy', 'strcpy_s', 'strcspn', 'strdup', 'strlen', 'strncat', 'strncat_s', 'strncmp', 'strncpy', 'strncpy_s', | |
| 137 | + 'strndup', 'strnlen_s', 'strpbrk', 'strrchr', 'strspn', 'strstr', 'strtok', 'strtok_s', 'strxfrm', | |
| 138 | + // __STD_WANT_LIB_EXT1__ | |
| 139 | + 'memcpy_s', 'memmove_s', 'memset_s', 'strcat_s', 'strcpy_s', 'strerror_s', 'strerrorlen_s', 'strncat_s', 'strncpy_s', 'strnlen_s', 'strtok_s', | |
| 140 | + ], | |
| 141 | + 'threads.h' => [ // C11 | |
| 142 | + 'call_once', 'cnd_broadcast', 'cnd_destroy', 'cnd_init', 'cnd_signal', 'cnd_timedwait', 'cnd_wait', | |
| 143 | + 'mtx_destroy', 'mtx_init', 'mtx_lock', 'mtx_timedlock', 'mtx_trylock', 'mtx_unlock', | |
| 144 | + 'thrd_create', 'thrd_current', 'thrd_detach', 'thrd_equal', 'thrd_exit', 'thrd_join', 'thrd_sleep', 'thrd_yield', 'tss_create', 'tss_delete', 'tss_get', 'tss_set', | |
| 145 | + ], | |
| 146 | + 'time.h' => [ // C89 | |
| 147 | + 'asctime', 'clock', 'ctime', 'difftime', 'gmtime', 'gmtime_r', 'localtime', 'localtime_r', 'mktime', | |
| 148 | + 'strftime', 'time', 'timegm', | |
| 149 | + // __STD_WANT_LIB_EXT1__ | |
| 150 | + 'asctime_s', 'ctime_s', 'gmtime_s', 'localtime_s', | |
| 151 | + ], | |
| 152 | + 'uchar.h' => [ // C11 | |
| 153 | + 'c8rtomb', 'c16rtomb', 'c32rtomb', 'mbrtoc8', 'mbrtoc16', 'mbrtoc32', | |
| 154 | + ], | |
| 155 | + 'wchar.h' => [ // C95 | |
| 156 | + 'wcscat', 'wcscat_s', 'wcschr', 'wcscmp', 'wcscpy', 'wcscpy_s', 'wcscroll', 'wcscroll', 'wcscspn', 'wcslen', 'wcsncpy', 'wcsncpy_s', 'wcsncat', 'wcsncat_s', | |
| 157 | + 'wcsncmp', 'wcsnlen_s', 'wcsrchr', 'wcspbrk', 'wcsstr', 'wcstok', 'wcstok_s', 'wcsxfrm', | |
| 158 | + 'wmemchr', 'wmemcmp', 'wmemcpy', 'wmemcpy_s', 'wmemmove', 'wmemmove_s', 'wmemset', | |
| 159 | + // __STDC_IEC_60559_DFP__ | |
| 160 | + 'wcstod32', 'wcstod64', 'wcstod128', | |
| 161 | + // __STDC_IEC_60559_TYPES__ | |
| 162 | + 'encptr', 'nptr', | |
| 163 | + // __STDC_WANT_LIB_EXT1__ | |
| 164 | + 'fwprintf_s', 'fwscanf_s', 'mvsrtowcs_s', 'snwprinf_s', 'swprintf_s', 'swscanf_s', 'vfwprintf_s', 'vfwscanf_s', 'vsnwprinf_s', 'vswprintf_s', 'vswscanf_s', | |
| 165 | + 'wcrtomb_s', 'wcscat_s', 'wcsncat_s', 'wcstok_s', 'wcsnlen_s', 'wcscpy_s', 'wcsncpy_s', 'wcsrtombs_s', 'wmemcpy_s', 'wmemmove_s', 'wprintf_s', 'wscanf_s', | |
| 166 | + ], | |
| 167 | + 'wctype.h' => [ // C95 | |
| 168 | + 'iswalnum', 'iswalpha', 'iswblank', 'iswcntrl', 'iswctype', 'iswdigit', 'iswgraph', 'iswlower', 'iswprint', 'iswpunct', 'iswspace', 'iswupper', 'iswxdigit', | |
| 169 | + 'towctrans', 'towlower', 'towupper', | |
| 170 | + 'wctrans', 'cwtype', | |
| 171 | + ], | |
| 172 | + ], | |
| 173 | + 'preprocessor' => [ | |
| 174 | + // C23 | |
| 175 | + '#elifdef', '#elifndef', '#embed', '#warning', '__has_include', '__has_embed', '__has_c_attribute', | |
| 176 | + // C99 | |
| 177 | + '#_Pragma', | |
| 178 | + // C89 | |
| 179 | + '#if', '#elif', '#else', '#endif', '#ifdef', '#ifndef', '#define', '#undef', '#include', '#line', '#error', '#pragma', '#defined', | |
| 180 | + ], | |
| 181 | + 'typedef' => [ | |
| 182 | + 'errno.h' => [ | |
| 183 | + 'errno_t', | |
| 184 | + ], | |
| 185 | + 'inttypes.h' => [ | |
| 186 | + 'intmax_t', 'uintmax_t', 'imaxdiv_t', | |
| 187 | + ], | |
| 188 | + 'iso646.h' => [ | |
| 189 | + 'and'/*&&*/, 'and_eq'/*&=*/, 'bitand'/*&*/, 'bitor'/*|*/, 'compl'/*~*/, 'not'/*!*/, 'not_eq'/*!=*/, 'or'/*||*/, 'or_eq',/*|=*/ 'xor'/*^*/, 'xor_eq'/*^=*/, | |
| 190 | + ], | |
| 191 | + 'setjmp.h' => [ | |
| 192 | + 'jmp_buf', | |
| 193 | + ], | |
| 194 | + 'signal.h' => [ | |
| 195 | + 'sig_atomic_t', | |
| 196 | + ], | |
| 197 | + 'stdatomic.h' => [ | |
| 198 | + 'atomic_bool', 'atomic_char', 'atomic_schar', 'atomic_uchar', 'atomic_short', 'atomic_ushort', 'atomic_int', 'atomic_uint', 'atomic_long', 'atomic_ulong', | |
| 199 | + 'atomic_llong', 'atomic_ullong', 'atomic_char8_t', 'atomic_char16_t', 'atomic_char32_t', 'atomic_wchar_t', 'atomic_int_least8_t', 'atomic_uint_least8_t', | |
| 200 | + 'atomic_int_least16_t', 'atomic_uint_least16_t', 'atomic_int_least32_t', 'atomic_uint_least32_t', 'atomic_int_least64_t', 'atomic_uint_least64_t', 'atomic_int_fast8_t', | |
| 201 | + 'atomic_uint_fast8_t', 'atomic_int_fast16_t', 'atomic_uint_fast16_t', 'atomic_int_fast32_t', 'atomic_uint_fast32_t', 'atomic_int_fast64_t', 'atomic_uint_fast64_t', | |
| 202 | + 'atomic_intptr_t', 'atomic_uintptr_t', 'atomic_size_t', 'atomic_ptrdiff_t', 'atomic_intmax_t', 'atomic_uintmax_t', | |
| 203 | + ], | |
| 204 | + 'stddef.h' => [ | |
| 205 | + 'max_align_t', 'nullptr', 'ptrdiff_t', 'size_t', | |
| 206 | + ], | |
| 207 | + 'stdio.h' => [ | |
| 208 | + 'FILE', 'size_t', 'fpos_t', | |
| 209 | + ], | |
| 210 | + 'stdint.h' => [ | |
| 211 | + 'int8_t', 'int16_t', 'int32_t', 'int64_t', | |
| 212 | + 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', | |
| 213 | + 'fpos_t', 'intptr_t', 'intmax_t', 'uintptr_t', 'uintmax_t', | |
| 214 | + 'int_least8_t', 'int_least16_t', 'int_least32_t', 'int_least64_t', | |
| 215 | + 'uint_least8_t', 'uint_least16_t', 'uint_least32_t', 'uint_least64_t', | |
| 216 | + 'int_fast8_t', 'int_fast16_t', 'int_fast32_t', 'int_fast64_t', | |
| 217 | + 'uint_fast8_t', 'uint_fast16_t', 'uint_fast32_t', 'uint_fast64_t', | |
| 218 | + ], | |
| 219 | + 'stdmchar.h' => [ | |
| 220 | + 'stdc_mcerr', | |
| 221 | + ], | |
| 222 | + 'stdarg.h' => [ | |
| 223 | + 'va_list', | |
| 224 | + ], | |
| 225 | + 'threads.h' => [ | |
| 226 | + 'cnd_t', | |
| 227 | + 'mtx_t', | |
| 228 | + 'thrd_t', | |
| 229 | + 'thrd_start_t', | |
| 230 | + 'tss_t', | |
| 231 | + 'tss_dtor_t', | |
| 232 | + ], | |
| 233 | + 'time.h' => [ | |
| 234 | + 'rsize_t', 'clock_t', 'time_t', | |
| 235 | + ], | |
| 236 | + 'uchar.h' => [ | |
| 237 | + 'char8_t', 'char16_t', 'char32_t', 'mbstate_t', | |
| 238 | + ], | |
| 239 | + 'wchar.h' => [ | |
| 240 | + 'wchar_t', 'wint_t', | |
| 241 | + ], | |
| 242 | + 'wctype.h' => [ | |
| 243 | + 'wctrans_t', 'wctype_t', | |
| 244 | + ], | |
| 245 | + ], | |
| 246 | + ]; | |
| 247 | + | |
| 248 | + public function __construct() { | |
| 249 | + global $colorPalette; | |
| 250 | + | |
| 251 | + $this->colors = [ | |
| 252 | + 'comment' => $colorPalette['dark']['green'], | |
| 253 | + 'keyword' => $colorPalette['dark']['blue'], | |
| 254 | + 'number' => $colorPalette['light']['green'], | |
| 255 | + 'preprocessor' => $colorPalette['medium']['purple'], | |
| 256 | + 'string' => $colorPalette['medium']['orange'], | |
| 257 | + 'typedef' => $colorPalette['dark']['lime'], | |
| 258 | + 'function' => $colorPalette['light']['yellow'], | |
| 259 | + 'libc' => $colorPalette['light']['yellow'], | |
| 260 | + ]; | |
| 261 | + } | |
| 262 | + | |
| 263 | + public function getColors(): array { return $this->colors; } | |
| 264 | + public function getComment(): ?string { return $this->comment; } | |
| 265 | + public function getInclude(array $code): ?array { | |
| 266 | + $headers = []; | |
| 267 | + foreach ($code as $c) { | |
| 268 | + $c = htmlspecialchars($c); | |
| 269 | + if (!str_starts_with($c, '#include')) continue; | |
| 270 | + $header = str_replace(['#include ', '<', '>', '"', '''], '', $c); | |
| 271 | + $headers[] = trim($header); | |
| 272 | + } | |
| 273 | + return $headers; | |
| 274 | + } | |
| 275 | + public function getMultiline(): ?array { return $this->multiline; } | |
| 276 | + public function getTokens(): array { return $this->tokens; } | |
| 277 | +} |
| @@ -0,0 +1,66 @@ | ||
| 1 | +<?php | |
| 2 | +namespace Site\Lib\Syntax; | |
| 3 | + | |
| 4 | +use Site\Lib\Syntax\SyntaxInterface; | |
| 5 | + | |
| 6 | +class Cpp implements SyntaxInterface { | |
| 7 | + private array $colors = []; | |
| 8 | + private string $comment = '//'; | |
| 9 | + private array $multiline = ['/*', '*/']; | |
| 10 | + | |
| 11 | + private array $tokens = [ | |
| 12 | + 'keyword' => [ | |
| 13 | + // C++26 | |
| 14 | + 'contract_assert', 'pre', 'post', 'trivially_reallocate_if_eligible', 'replaceable_if_eligible', | |
| 15 | + // C++20 | |
| 16 | + 'char8_t', 'concept', 'consteval', 'constinit', 'co_await', 'co_return', 'co_yield', 'import', 'module', 'requires', | |
| 17 | + // C++11 | |
| 18 | + 'alignas', 'alignof', 'char16_t', 'char32_t', 'constexpr', 'decltype', 'final', 'noexcept', 'nullptr', 'override', 'static_assert', 'thread_local', | |
| 19 | + // C++99 | |
| 20 | + 'and', 'and_eq', 'asm', 'auto', 'bitand', 'bitor', 'bool', 'break', 'case', 'catch', 'char', 'class', 'compl', 'const', 'const_cast', 'continue', | |
| 21 | + 'default', 'delete', 'do', 'double', 'dynamic_cast', 'else', 'enum', 'explicit', 'export', 'extern', 'false', 'float', 'for', 'friend', 'goto', 'if', 'inline', | |
| 22 | + 'int', 'long', 'mutable', 'namespace', 'new', 'not', 'not_eq', 'operator', 'or', 'or_eq', 'private', 'protected', 'public', 'reflexpr', 'register', | |
| 23 | + 'reinterpret_cast', 'return', 'short', 'signed', 'sizeof', 'static', 'static_assert', 'static_cast', 'struct', 'switch', 'template', 'this', 'throw', 'true', 'try', | |
| 24 | + 'typedef', 'typeid', 'typename', 'union', 'unsigned', 'using', 'virtual', 'void', 'volatile', 'wchar_t', 'while', 'xor', 'xor_eq', | |
| 25 | + // TMTS | |
| 26 | + 'atomic_cancel', 'atomic_commit', 'atomic_noexcept', 'synchronized', 'transaction_safe', 'transaction_safe_dynamic', | |
| 27 | + ], | |
| 28 | + 'preprocessor' => [ | |
| 29 | + // C++26 | |
| 30 | + '#embed', '__has_embed', | |
| 31 | + // C++23 | |
| 32 | + '#elifdef', '#elifndef', '#warning', | |
| 33 | + // C++20 | |
| 34 | + '#__has_cpp_attribute', '#export', '#import', '#module', | |
| 35 | + // C++17 | |
| 36 | + '#__has_include', | |
| 37 | + // C++11 | |
| 38 | + '#_Pragma', | |
| 39 | + // C++99 | |
| 40 | + '#if', '#elif', '#else', '#endif', '#ifdef', '#ifndef', '#define', '#undef', '#include', '#line', '#error', '#pragma', '#defined', | |
| 41 | + ], | |
| 42 | + 'typedef' => [ | |
| 43 | + 'int8_t', 'int16_t', 'int32_t', 'int64_t', | |
| 44 | + 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', | |
| 45 | + 'size_t', | |
| 46 | + ], | |
| 47 | + ]; | |
| 48 | + | |
| 49 | + public function __construct() { | |
| 50 | + global $colorPalette; | |
| 51 | + | |
| 52 | + $this->colors = [ | |
| 53 | + 'comment' => $colorPalette['dark']['green'], | |
| 54 | + 'keyword' => $colorPalette['dark']['blue'], | |
| 55 | + 'number' => $colorPalette['light']['green'], | |
| 56 | + 'preprocessor' => $colorPalette['medium']['purple'], | |
| 57 | + 'string' => $colorPalette['medium']['orange'], | |
| 58 | + 'typedef' => $colorPalette['dark']['lime'], | |
| 59 | + ]; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public function getColors(): array { return $this->colors; } | |
| 63 | + public function getComment(): ?string { return $this->comment; } | |
| 64 | + public function getMultiline(): ?array { return $this->multiline; } | |
| 65 | + public function getTokens(): array { return $this->tokens; } | |
| 66 | +} |
| @@ -0,0 +1,65 @@ | ||
| 1 | +<?php | |
| 2 | +namespace Site\Lib\Syntax; | |
| 3 | + | |
| 4 | +use Site\Lib\Syntax\SyntaxInterface; | |
| 5 | + | |
| 6 | +class Glsl implements SyntaxInterface { | |
| 7 | + private array $colors = []; | |
| 8 | + private string $comment = '//'; | |
| 9 | + | |
| 10 | + private array $tokens = [ | |
| 11 | + 'function' => [ | |
| 12 | + 'asin', 'acos', 'atan', 'cos', 'degrees', 'radians', 'sin', 'tan', | |
| 13 | + 'exp', 'exp2', 'inversesqrt', 'log', 'log2', 'pow', 'sqrt', | |
| 14 | + 'abs', 'ceil', 'clamp', 'floor', 'fract', 'max', 'min', 'mix', 'mod', 'sign', 'smoothstep', 'step', | |
| 15 | + 'cross', 'distance', 'dot', 'faceforward', 'ftransform', 'length', 'normalize', 'reflect', 'refract', | |
| 16 | + 'dFdx', 'dFdy', 'fwidth', | |
| 17 | + 'matrixCompMulti', | |
| 18 | + 'all', 'any', 'equal', 'greaterThan', 'greaterThanEqual', 'lessThan', 'lessThanEqual', 'not', 'notEqual', | |
| 19 | + 'texture1D', 'texture1DProj', 'texture2D', 'texture2DProj', 'texture3D', 'texture3DProj', 'textureCube', | |
| 20 | + 'texture1DLod', 'texture1DProjLod', 'texture2DLod', 'texture2DProjLod', 'texture3DProjLod', | |
| 21 | + 'shadow1DLog', 'shadow1DProjLog', 'shadow2DLog', 'shadow2DProjLog', | |
| 22 | + 'noise1', 'noise2', 'noise3', 'noise4', | |
| 23 | + ], | |
| 24 | + 'keyword' => [ | |
| 25 | + 'attribute', 'bool', 'bvec2', 'bvec3', 'bvec4', 'const', 'float', 'genType', 'in', 'int', 'inout', 'ivec2', 'ivec3', 'ivec4', 'mat2', 'mat3', 'mat4', 'out', | |
| 26 | + 'sampler1D', 'sampler1DShadow', 'sampler2D', 'sampler2DShadow', 'sampler3D', 'samplerCube', 'struct', 'uniform', 'varying', 'vec2', 'vec3', 'vec4', 'void', | |
| 27 | + ], | |
| 28 | + 'preprocessor' => [ | |
| 29 | + '#', '#define', '#elif', '#else', '#endif', '#error', '#extension', '#if', '#ifdef', '#ifndef', '#line', '#pragma', '#version', '#undef', | |
| 30 | + '__FILE__', '__LINE__', '__VERSION__', | |
| 31 | + ], | |
| 32 | + 'variables' => [ | |
| 33 | + // Vertex | |
| 34 | + 'gl_ClipVertex', 'gl_PointSize', 'gl_Position', 'gl_Color', 'gl_FogCoord', 'gl_Normal', 'gl_SecondaryColor', 'gl_Vertex', | |
| 35 | + 'gl_MultiTexCoord0', 'gl_MultiTexCoord1', 'gl_MultiTexCoord2', 'gl_MultiTexCoord3', 'gl_MultiTexCoord4', 'gl_MultiTexCoord5', 'gl_MultiTexCoord6', 'gl_MultiTexCoord7', | |
| 36 | + 'gl_BackColor', 'gl_BackSecondaryColor', 'gl_FogFragCoord', 'gl_FrontColor', 'gl_FrontSecondaryColor', 'gl_TexCoord', | |
| 37 | + // Fragment | |
| 38 | + 'gl_FragColor', 'gl_FragCoord', 'gl_FragData', 'gl_FragDepth', 'gl_FrontFacing', 'gl_MaxDrawBuffers', | |
| 39 | + // Constant | |
| 40 | + 'gl_MaxClipPlanes', 'gl_MaxCombinedTextureImageUnits', 'gl_MaxDrawBuffers', 'gl_MaxFragmentUniformComponents', 'gl_MaxLights', 'gl_MaxTextureCoords', | |
| 41 | + 'gl_MaxTextureImageUnits', 'gl_MaxTextureUnits', 'gl_MaxVaryingFloats', 'gl_MaxVertexAttribs', 'gl_MaxVertexUniformComponents', | |
| 42 | + // Uniform | |
| 43 | + 'gl_ClipPlane', 'gl_DepthRange', 'gl_DepthRangeParameters', 'gl_EyePlane', 'gl_Fog', 'gl_FogParameters', 'gl_LightModel', 'gl_LightModelParameters', | |
| 44 | + 'gl_LightModelProducts', 'gl_BackLightModelProduct', 'gl_FrontLightModelProduct', 'gl_LightProducts', 'gl_BackLightProduct', 'gl_FrontLightProduct', | |
| 45 | + 'gl_LightSource', 'gl_LightSourceParameters', 'gl_MaterialParameters', 'gl_BackMaterial', 'gl_FrontMaterial', | |
| 46 | + 'gl_ModelViewMatrix', 'gl_ModelViewMatrixInverse', 'gl_ModelViewMatrixTranspose', 'gl_ModelViewMatrixInverseTranspose', | |
| 47 | + 'gl_ModelViewProjectionMatrix', 'gl_ModelViewProjectionMatrixInverse', 'gl_ModelViewProjectionMatrixTranspose', 'gl_ModelViewProjectionMatrixInverseTranspose', | |
| 48 | + 'gl_ObjectPlane', 'gl_Point', 'gl_PointParameters', | |
| 49 | + 'gl_ProjectionMatrix', 'gl_ProjectionMatrixInverse', 'gl_ProjectionMatrixTranspose', 'gl_ProjectionMatrixInverseTranspose', 'gl_NormalMatrix', 'gl_NormalScale', | |
| 50 | + 'gl_TextureEnvColor', 'gl_TextureMatrix', 'gl_TextureMatrixInverse', 'gl_TextureMatrixTranspose', 'gl_TextureMatrixInverseTranspose', | |
| 51 | + ], | |
| 52 | + ]; | |
| 53 | + | |
| 54 | + public function __construct() { | |
| 55 | + global $colorPalette; | |
| 56 | + | |
| 57 | + $this->colors = [ | |
| 58 | + ]; | |
| 59 | + } | |
| 60 | + | |
| 61 | + public function getColors(): array { return $this->colors; } | |
| 62 | + public function getComment(): ?string { return $this->comment; } | |
| 63 | + public function getMultiline(): ?array { return $this->multiline; } | |
| 64 | + public function getTokens(): array { return $this->tokens; } | |
| 65 | +} |
| @@ -0,0 +1,40 @@ | ||
| 1 | +<?php | |
| 2 | +namespace Site\Lib\Syntax; | |
| 3 | + | |
| 4 | +use Site\Lib\Syntax\SyntaxInterface; | |
| 5 | + | |
| 6 | +class Go implements SyntaxInterface { | |
| 7 | + private array $colors = []; | |
| 8 | + private string $comment = '//'; | |
| 9 | + | |
| 10 | + private array $tokens = [ | |
| 11 | + 'keyword' => [ | |
| 12 | + 'break', 'case', 'chan', 'const', 'continue', 'default', 'defer', 'else', 'fallthrough', 'for', 'func', 'go', 'goto', 'if', 'import', 'interface', 'map', | |
| 13 | + 'package', 'range', 'return', 'select', 'struct', 'switch', 'type', 'var', | |
| 14 | + 'uint8', 'uint16', 'uint32', 'uint64', | |
| 15 | + 'int8', 'int16', 'int32', 'int64', | |
| 16 | + 'float32', 'float64', | |
| 17 | + 'complex64', 'complex128', | |
| 18 | + 'byte', 'rune', 'string', 'bool', | |
| 19 | + 'uint', 'int', 'uintptr', | |
| 20 | + ], | |
| 21 | + 'operator' => [ | |
| 22 | + '+', '-', '*', '/', '%', '&', '|', '^', '<<', '>>', '&^', '<', '>', '=', '!', '~', '...', ',', '.', ';', ':', | |
| 23 | + '{', '}', '(', ')', '[', ']', | |
| 24 | + '+=', '-=', '*=', '/=', '%=', '&=', '|=', '^=', '<<=', '>>=', '&^=', '!=', '<=', '>=', ';=', | |
| 25 | + '&&', '||', '<-', '++', '--', '==', | |
| 26 | + ], | |
| 27 | + ]; | |
| 28 | + | |
| 29 | + public function __construct() { | |
| 30 | + global $colorPalette; | |
| 31 | + | |
| 32 | + $this->colors = [ | |
| 33 | + ]; | |
| 34 | + } | |
| 35 | + | |
| 36 | + public function getColors(): array { return $this->colors; } | |
| 37 | + public function getComment(): ?string { return $this->comment; } | |
| 38 | + public function getMultiline(): ?array { return $this->multiline; } | |
| 39 | + public function getTokens(): array { return $this->tokens; } | |
| 40 | +} |
| @@ -0,0 +1,10 @@ | ||
| 1 | +<?php | |
| 2 | +namespace Site\Lib\Syntax; | |
| 3 | + | |
| 4 | +interface SyntaxInterface { | |
| 5 | + public function getColors(): array; | |
| 6 | + public function getComment(): ?string; | |
| 7 | + public function getInclude(array $code): ?array; | |
| 8 | + public function getMultiline(): ?array; | |
| 9 | + public function getTokens(): array; | |
| 10 | +} |
| @@ -0,0 +1,7 @@ | ||
| 1 | +{@ include(common/header) @} | |
| 2 | + <h1 class="paragraph">test</h1> | |
| 3 | + <p class="paragraph"> | |
| 4 | + <pre><code>{{{ $cCode }}}</code></pre> | |
| 5 | + <pre><code>{{{ $asmCode }}}</code></pre> | |
| 6 | + </p> | |
| 7 | +{@ include(common/footer) @} |