aboutsummaryrefslogtreecommitdiffhomepage
path: root/public/posts/2023-01-10
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-03-17 01:35:04 +0900
committernsfisis <nsfisis@gmail.com>2023-03-17 01:35:04 +0900
commit0766039bd9e6b9f5e6334e84666f5be698d41fc3 (patch)
tree0f3a52fdbf56496850f903d64dcf7725fb0aedbe /public/posts/2023-01-10
parentee72f8780cf3681e4202cc3a6358fb4038db1ec8 (diff)
downloadblog.nsfisis.dev-0766039bd9e6b9f5e6334e84666f5be698d41fc3.tar.gz
blog.nsfisis.dev-0766039bd9e6b9f5e6334e84666f5be698d41fc3.tar.zst
blog.nsfisis.dev-0766039bd9e6b9f5e6334e84666f5be698d41fc3.zip
feat(nuldoc): implement syntax highlight
Diffstat (limited to 'public/posts/2023-01-10')
-rw-r--r--public/posts/2023-01-10/phperkaigi-2023-unused-token-quiz-3/index.html154
1 files changed, 77 insertions, 77 deletions
diff --git a/public/posts/2023-01-10/phperkaigi-2023-unused-token-quiz-3/index.html b/public/posts/2023-01-10/phperkaigi-2023-unused-token-quiz-3/index.html
index ab47b2b..61d9880 100644
--- a/public/posts/2023-01-10/phperkaigi-2023-unused-token-quiz-3/index.html
+++ b/public/posts/2023-01-10/phperkaigi-2023-unused-token-quiz-3/index.html
@@ -10,7 +10,7 @@
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
<title>PHPerKaigi 2023: ボツになったトークン問題 その 3 | REPL: Rest-Eat-Program Loop</title>
<link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a">
- <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f">
+ <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b">
</head>
<body class="single">
<header class="header">
@@ -92,24 +92,24 @@
注意: これはボツ問なので、得られたトークンを PHPerKaigi で入力してもポイントにはならない。
</p>
- <pre class="highlight" language="php" linenumbering="unnumbered"><code>&lt;?php
-try {
- f(g() / __LINE__);
-} catch (Throwable $e) {
- while ($e = $e-&gt;getPrevious()) printf(&apos;%c&apos;, $e-&gt;getLine() + 23);
- echo &quot;\n&quot;;
+ <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta">&lt;?php</span>
+<span class="hljs-keyword">try</span> {
+ <span class="hljs-title function_ invoke__">f</span>(<span class="hljs-title function_ invoke__">g</span>() / <span class="hljs-keyword">__LINE__</span>);
+} <span class="hljs-keyword">catch</span> (<span class="hljs-built_in">Throwable</span> <span class="hljs-variable">$e</span>) {
+ <span class="hljs-keyword">while</span> (<span class="hljs-variable">$e</span> = <span class="hljs-variable">$e</span>-&gt;<span class="hljs-title function_ invoke__">getPrevious</span>()) <span class="hljs-title function_ invoke__">printf</span>(<span class="hljs-string">&#x27;%c&#x27;</span>, <span class="hljs-variable">$e</span>-&gt;<span class="hljs-title function_ invoke__">getLine</span>() + <span class="hljs-number">23</span>);
+ <span class="hljs-keyword">echo</span> <span class="hljs-string">&quot;\n&quot;</span>;
}
-function f(int $i) {
- if ($i &lt; 0) f();
- try {
- match ($i) {
- 0 =&gt; 0 / 0,
+<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> <span class="hljs-variable">$i</span></span>) </span>{
+ <span class="hljs-keyword">if</span> (<span class="hljs-variable">$i</span> &lt; <span class="hljs-number">0</span>) <span class="hljs-title function_ invoke__">f</span>();
+ <span class="hljs-keyword">try</span> {
+ <span class="hljs-keyword">match</span> (<span class="hljs-variable">$i</span>) {
+ <span class="hljs-number">0</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
- 15, 36 =&gt; 0 / 0,
- 14 =&gt; 0 / 0,
- 37 =&gt; 0 / 0,
+ <span class="hljs-number">15</span>, <span class="hljs-number">36</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
+ <span class="hljs-number">14</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
+ <span class="hljs-number">37</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
@@ -120,16 +120,16 @@ function f(int $i) {
- 6 =&gt; 0 / 0,
+ <span class="hljs-number">6</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
- 5 =&gt; 0 / 0,
+ <span class="hljs-number">5</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
- 22 =&gt; 0 / 0,
+ <span class="hljs-number">22</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
- 34, 35 =&gt; 0 / 0,
+ <span class="hljs-number">34</span>, <span class="hljs-number">35</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
@@ -138,10 +138,10 @@ function f(int $i) {
- 25 =&gt; 0 / 0,
- 17, 21 =&gt; 0 / 0,
+ <span class="hljs-number">25</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
+ <span class="hljs-number">17</span>, <span class="hljs-number">21</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
- 24, 32 =&gt; 0 / 0,
+ <span class="hljs-number">24</span>, <span class="hljs-number">32</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
@@ -149,12 +149,12 @@ function f(int $i) {
- 33 =&gt; 0 / 0,
+ <span class="hljs-number">33</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
- 16 =&gt; 0 / 0,
+ <span class="hljs-number">16</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
- 18 =&gt; 0 / 0,
+ <span class="hljs-number">18</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
@@ -163,35 +163,35 @@ function f(int $i) {
- 7 =&gt; 0 / 0,
+ <span class="hljs-number">7</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
- 2 =&gt; 0 / 0,
- 1, 20 =&gt; 0 / 0,
- 10, 28 =&gt; 0 / 0,
- 8, 12, 26 =&gt; 0 / 0,
- 4, 9, 13 =&gt; 0 / 0,
+ <span class="hljs-number">2</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
+ <span class="hljs-number">1</span>, <span class="hljs-number">20</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
+ <span class="hljs-number">10</span>, <span class="hljs-number">28</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
+ <span class="hljs-number">8</span>, <span class="hljs-number">12</span>, <span class="hljs-number">26</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
+ <span class="hljs-number">4</span>, <span class="hljs-number">9</span>, <span class="hljs-number">13</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
- 31 =&gt; 0 / 0,
+ <span class="hljs-number">31</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
- 29 =&gt; 0 / 0,
+ <span class="hljs-number">29</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
- 11 =&gt; 0 / 0,
+ <span class="hljs-number">11</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
- 3, 19, 23 =&gt; 0 / 0,
+ <span class="hljs-number">3</span>, <span class="hljs-number">19</span>, <span class="hljs-number">23</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
- 27 =&gt; 0 / 0,
+ <span class="hljs-number">27</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
- 30 =&gt; 0 / 0,
+ <span class="hljs-number">30</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
};
- } finally {
- f($i - 1);
+ } <span class="hljs-keyword">finally</span> {
+ <span class="hljs-title function_ invoke__">f</span>(<span class="hljs-variable">$i</span> - <span class="hljs-number">1</span>);
}
}
@@ -201,8 +201,8 @@ function f(int $i) {
-function g() {
- return __LINE__;
+<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">g</span>(<span class="hljs-params"></span>) </span>{
+ <span class="hljs-keyword">return</span> <span class="hljs-keyword">__LINE__</span>;
}</code></pre>
<p>
@@ -247,19 +247,19 @@ function g() {
このうち 1つ目のケースは、<code>finally</code>節の中でエラーを投げると PHP 処理系が勝手に<code>$previous</code>を設定してくれる。
</p>
- <pre class="highlight" language="php" linenumbering="unnumbered"><code>&lt;?php
+ <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta">&lt;?php</span>
-try {
- try {
- throw new Exception(&quot;Error 1&quot;);
- } finally {
- throw new Exception(&quot;Error 2&quot;);
+<span class="hljs-keyword">try</span> {
+ <span class="hljs-keyword">try</span> {
+ <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Exception</span>(<span class="hljs-string">&quot;Error 1&quot;</span>);
+ } <span class="hljs-keyword">finally</span> {
+ <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Exception</span>(<span class="hljs-string">&quot;Error 2&quot;</span>);
}
-} catch (Exception $e) {
- echo $e-&gt;getMessage() . PHP_EOL;
- // =&gt; Error 2
- echo $e-&gt;getPrevious()-&gt;getMessage() . PHP_EOL;
- // =&gt; Error 1
+} <span class="hljs-keyword">catch</span> (<span class="hljs-built_in">Exception</span> <span class="hljs-variable">$e</span>) {
+ <span class="hljs-keyword">echo</span> <span class="hljs-variable">$e</span>-&gt;<span class="hljs-title function_ invoke__">getMessage</span>() . PHP_EOL;
+ <span class="hljs-comment">// =&gt; Error 2</span>
+ <span class="hljs-keyword">echo</span> <span class="hljs-variable">$e</span>-&gt;<span class="hljs-title function_ invoke__">getPrevious</span>()-&gt;<span class="hljs-title function_ invoke__">getMessage</span>() . PHP_EOL;
+ <span class="hljs-comment">// =&gt; Error 1</span>
}</code></pre>
<p>
@@ -273,14 +273,14 @@ try {
出力部をコメントや改行を追加して再掲する:
</p>
- <pre class="highlight" language="php" linenumbering="unnumbered"><code>&lt;?php
-try {
- f(g() / __LINE__);
-} catch (Throwable $e) {
- while ($e = $e-&gt;getPrevious()) {
- printf(&apos;%c&apos;, $e-&gt;getLine() + 23);
+ <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta">&lt;?php</span>
+<span class="hljs-keyword">try</span> {
+ <span class="hljs-title function_ invoke__">f</span>(<span class="hljs-title function_ invoke__">g</span>() / <span class="hljs-keyword">__LINE__</span>);
+} <span class="hljs-keyword">catch</span> (<span class="hljs-built_in">Throwable</span> <span class="hljs-variable">$e</span>) {
+ <span class="hljs-keyword">while</span> (<span class="hljs-variable">$e</span> = <span class="hljs-variable">$e</span>-&gt;<span class="hljs-title function_ invoke__">getPrevious</span>()) {
+ <span class="hljs-title function_ invoke__">printf</span>(<span class="hljs-string">&#x27;%c&#x27;</span>, <span class="hljs-variable">$e</span>-&gt;<span class="hljs-title function_ invoke__">getLine</span>() + <span class="hljs-number">23</span>);
}
- echo &quot;\n&quot;;
+ <span class="hljs-keyword">echo</span> <span class="hljs-string">&quot;\n&quot;</span>;
}</code></pre>
<p>
@@ -291,7 +291,7 @@ try {
フォーマット指定子<code>%c</code>は、整数を ASCII コード<span></span>と見做して印字する。トークン<code>#base64_decode(&apos;SGVsbG8sIFdvcmxkIQ==&apos;)</code>の<code>b</code>であれば、ASCII コード<code>98</code>なので、75 行目で発生したエラー、
</p>
- <pre class="highlight" language="php" linenumbering="unnumbered"><code>1, 20 =&gt; 0 / 0,</code></pre>
+ <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-number">1</span>, <span class="hljs-number">20</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,</code></pre>
<p>
によって表現されている。エラーを起こす方法はいろいろと考えられるが、今回はゼロ除算を使った。
@@ -308,24 +308,24 @@ try {
<code>f()</code>の定義を再掲する (エラーオブジェクトの行数を利用しているので、一部分だけ抜き出すと値が変わることに注意):
</p>
- <pre class="highlight" language="php" linenumbering="unnumbered"><code>function f(int $i) {
- if ($i &lt; 0) f();
- try {
- match ($i) {
- 0 =&gt; 0 / 0, // 12 行目
+ <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> <span class="hljs-variable">$i</span></span>) </span>{
+ <span class="hljs-keyword">if</span> (<span class="hljs-variable">$i</span> &lt; <span class="hljs-number">0</span>) <span class="hljs-title function_ invoke__">f</span>();
+ <span class="hljs-keyword">try</span> {
+ <span class="hljs-keyword">match</span> (<span class="hljs-variable">$i</span>) {
+ <span class="hljs-number">0</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, <span class="hljs-comment">// 12 行目</span>
- 15, 36 =&gt; 0 / 0,
- 14 =&gt; 0 / 0,
- 37 =&gt; 0 / 0,
+ <span class="hljs-number">15</span>, <span class="hljs-number">36</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
+ <span class="hljs-number">14</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
+ <span class="hljs-number">37</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,
- // (略)
+ <span class="hljs-comment">// (略)</span>
- 30 =&gt; 0 / 0, // 97 行目
+ <span class="hljs-number">30</span> =&gt; <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, <span class="hljs-comment">// 97 行目</span>
};
- } finally {
- f($i - 1);
+ } <span class="hljs-keyword">finally</span> {
+ <span class="hljs-title function_ invoke__">f</span>(<span class="hljs-variable">$i</span> - <span class="hljs-number">1</span>);
}
}</code></pre>
@@ -333,12 +333,12 @@ try {
前述のように、<code>finally</code>節でエラーを投げると PHP 処理系が<code>$previous</code>を設定する。ここでは、エラーを繋げるために<code>f()</code>を再帰呼び出ししている。最初に<code>f()</code>を呼び出している箇所を確認すると、
</p>
- <pre class="highlight" language="php" linenumbering="unnumbered"><code>&lt;?php
-try {
- f(g() / __LINE__); // 3 行目</code></pre>
+ <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta">&lt;?php</span>
+<span class="hljs-keyword">try</span> {
+ <span class="hljs-title function_ invoke__">f</span>(<span class="hljs-title function_ invoke__">g</span>() / <span class="hljs-keyword">__LINE__</span>); <span class="hljs-comment">// 3 行目</span></code></pre>
- <pre class="highlight" language="php" linenumbering="unnumbered"><code>function g() {
- return __LINE__; // 111 行目
+ <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">g</span>(<span class="hljs-params"></span>) </span>{
+ <span class="hljs-keyword">return</span> <span class="hljs-keyword">__LINE__</span>; <span class="hljs-comment">// 111 行目</span>
}</code></pre>
<p>