aboutsummaryrefslogtreecommitdiffhomepage
path: root/public/posts/2021-10-02
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-03-12 15:12:10 +0900
committernsfisis <nsfisis@gmail.com>2023-03-12 15:12:10 +0900
commitde13d68cddef5bb321469bcffb868f27ddd5390e (patch)
tree3183bb2bc8b2ad7d34b6953e6a248747239f0afa /public/posts/2021-10-02
parent5b49e6bca39d7cd3b98db8b826dc597d9f758a26 (diff)
downloadblog.nsfisis.dev-de13d68cddef5bb321469bcffb868f27ddd5390e.tar.gz
blog.nsfisis.dev-de13d68cddef5bb321469bcffb868f27ddd5390e.tar.zst
blog.nsfisis.dev-de13d68cddef5bb321469bcffb868f27ddd5390e.zip
style: add .highlight class to pre tag
Diffstat (limited to 'public/posts/2021-10-02')
-rw-r--r--public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html4
-rw-r--r--public/posts/2021-10-02/python-unbound-local-error/index.html6
-rw-r--r--public/posts/2021-10-02/ruby-detect-running-implementation/index.html4
-rw-r--r--public/posts/2021-10-02/ruby-then-keyword-and-case-in/index.html24
-rw-r--r--public/posts/2021-10-02/rust-where-are-primitive-types-from/index.html12
-rw-r--r--public/posts/2021-10-02/vim-difference-between-autocmd-bufwrite-and-bufwritepre/index.html10
-rw-r--r--public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html8
7 files changed, 34 insertions, 34 deletions
diff --git a/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html b/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html
index 479520e..ae44da9 100644
--- a/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html
+++ b/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html
@@ -56,7 +56,7 @@
タイトル落ち。まずはこのコードを見て欲しい。
</p>
- <pre language="cpp" linenumbering="unnumbered">
+ <pre class="highlight" language="cpp" linenumbering="unnumbered">
<code>#include &lt;iostream&gt;
[[alignas]] [[alignof]] [[and]] [[and_eq]] [[asm]] [[auto]] [[bitand]]
@@ -126,7 +126,7 @@ std::cout &lt;&lt; &quot;Hello, World!&quot; &lt;&lt; std::endl;
上のコードでは<code>[[using]]</code>をコメントアウトしているが、これは<code>using</code>キーワードのみ属性構文の中で意味を持つからであり、このコメントアウトを外すとコンパイルに失敗する。
</p>
- <pre language="cpp" linenumbering="unnumbered">
+ <pre class="highlight" language="cpp" linenumbering="unnumbered">
<code>// using の例
[[using foo: attr1, attr2]] int x; // [[foo::attr1, foo::attr2]] の糖衣構文</code>
</pre>
diff --git a/public/posts/2021-10-02/python-unbound-local-error/index.html b/public/posts/2021-10-02/python-unbound-local-error/index.html
index fa0b1db..27c2d05 100644
--- a/public/posts/2021-10-02/python-unbound-local-error/index.html
+++ b/public/posts/2021-10-02/python-unbound-local-error/index.html
@@ -60,7 +60,7 @@
Python でクロージャを作ろうと、次のようなコードを書いた。
</p>
- <pre language="python" linenumbering="unnumbered">
+ <pre class="highlight" language="python" linenumbering="unnumbered">
<code>def f():
x = 0
def g():
@@ -84,7 +84,7 @@ f()</code>
local変数<code>x</code>が代入前に参照された、とある。これは、<code>f</code>の<code>x</code>を参照するのではなく、新しく別の変数を<code>g</code>内に作ってしまっているため。 前述のコードを宣言と代入を便宜上分けて書き直すと次のようになる。<code>var</code>を変数宣言のための構文として擬似的に利用している。
</p>
- <pre language="python" linenumbering="unnumbered">
+ <pre class="highlight" language="python" linenumbering="unnumbered">
<code># 注: var は正しい Python の文法ではない。上記参照のこと
def f():
var x # f の local変数 &apos;x&apos; を宣言
@@ -101,7 +101,7 @@ g()</code>
当初の意図を表現するには、次のように書けばよい。
</p>
- <pre language="python" linenumbering="unnumbered">
+ <pre class="highlight" language="python" linenumbering="unnumbered">
<code>def f():
x = 0
def g():
diff --git a/public/posts/2021-10-02/ruby-detect-running-implementation/index.html b/public/posts/2021-10-02/ruby-detect-running-implementation/index.html
index 08700c4..ed7ccd5 100644
--- a/public/posts/2021-10-02/ruby-detect-running-implementation/index.html
+++ b/public/posts/2021-10-02/ruby-detect-running-implementation/index.html
@@ -65,7 +65,7 @@
上記ページの例から引用する:
</p>
- <pre language="shell-session" linenumbering="unnumbered">
+ <pre class="highlight" language="shell-session" linenumbering="unnumbered">
<code>$ ruby-1.9.1 -ve &apos;p RUBY_ENGINE&apos;
ruby 1.9.1p0 (2009-03-04 revision 22762) [x86_64-linux]
&quot;ruby&quot;
@@ -192,7 +192,7 @@ jruby 1.2.0 (ruby 1.8.6 patchlevel 287) (2009-03-16 rev 9419) [i386-java]
<a href="https://github.com/mruby/mruby/blob/ed29d74bfd95362eaeb946fcf7e865d80346b62b/include/mruby/version.h#L32-L35">mruby 該当部分のソース</a>より引用:
</p>
- <pre language="c" linenumbering="unnumbered">
+ <pre class="highlight" language="c" linenumbering="unnumbered">
<code>/*
* Ruby engine.
*/
diff --git a/public/posts/2021-10-02/ruby-then-keyword-and-case-in/index.html b/public/posts/2021-10-02/ruby-then-keyword-and-case-in/index.html
index 1def6b6..9b1df47 100644
--- a/public/posts/2021-10-02/ruby-then-keyword-and-case-in/index.html
+++ b/public/posts/2021-10-02/ruby-then-keyword-and-case-in/index.html
@@ -65,7 +65,7 @@
使われることは稀だが、Ruby では<code>then</code>がキーワードになっている。次のように使う:
</p>
- <pre language="ruby" linenumbering="unnumbered">
+ <pre class="highlight" language="ruby" linenumbering="unnumbered">
<code>if cond then
puts &quot;Y&quot;
else
@@ -77,7 +77,7 @@
このキーワードが現れうる場所はいくつかあり、<code>if</code>、<code>unless</code>、<code>rescue</code>、<code>case</code>構文がそれに当たる。 上記のように、何か条件を書いた後<code>then</code>を置き、式がそこで終了していることを示すマーカーとして機能する。
</p>
- <pre language="ruby" linenumbering="unnumbered">
+ <pre class="highlight" language="ruby" linenumbering="unnumbered">
<code># Example:
if x then
@@ -107,7 +107,7 @@ end</code>
普通 Ruby のコードで<code>then</code>を書くことはない。なぜか。次のコードを実行してみるとわかる。
</p>
- <pre language="ruby" linenumbering="unnumbered">
+ <pre class="highlight" language="ruby" linenumbering="unnumbered">
<code>if true puts &apos;Hello, World!&apos; end</code>
</pre>
@@ -115,7 +115,7 @@ end</code>
次のような構文エラーが出力される。
</p>
- <pre class="monospaced">
+ <pre class="monospaced highlight">
<code>20:1: syntax error, unexpected local variable or method, expecting `then&apos; or &apos;;&apos; or &apos;\n&apos;
if true puts &apos;Hello, World!&apos; end
^~~~
@@ -131,7 +131,7 @@ end</code>
ポイントは改行が<code>then</code>(や<code>;</code>) の代わりとなることである。<code>true</code>の後に改行を入れてみる。
</p>
- <pre language="ruby" linenumbering="unnumbered">
+ <pre class="highlight" language="ruby" linenumbering="unnumbered">
<code>if true
puts &apos;Hello, World!&apos; end</code>
</pre>
@@ -147,7 +147,7 @@ puts &apos;Hello, World!&apos; end</code>
なぜ<code>then</code>や<code>;</code>や改行 (以下 「<code>then</code>等」) が必要なのだろうか。次の例を見てほしい:
</p>
- <pre language="ruby" linenumbering="unnumbered">
+ <pre class="highlight" language="ruby" linenumbering="unnumbered">
<code>if a b end</code>
</pre>
@@ -155,14 +155,14 @@ puts &apos;Hello, World!&apos; end</code>
<code>then</code>も<code>;</code>も改行もないのでエラーになるが、これは条件式がどこまで続いているのかわからないためだ。 この例は二通りに解釈できる。
</p>
- <pre language="ruby" linenumbering="unnumbered">
+ <pre class="highlight" language="ruby" linenumbering="unnumbered">
<code># a という変数かメソッドの評価結果が truthy なら b という変数かメソッドを評価
if a then
b
end</code>
</pre>
- <pre language="ruby" linenumbering="unnumbered">
+ <pre class="highlight" language="ruby" linenumbering="unnumbered">
<code># a というメソッドに b という変数かメソッドの評価結果を渡して呼び出し、
# その結果が truthy なら何もしない
if a(b) then
@@ -188,7 +188,7 @@ end</code>
<a href="https://github.com/ruby/ruby/blob/221ca0f8281d39f0dfdfe13b2448875384bbf735/parse.y#L3961-L3986">https://github.com/ruby/ruby/blob/221ca0f8281d39f0dfdfe13b2448875384bbf735/parse.y#L3961-L3986</a>
</p>
- <pre language="yacc" linenumbering="unnumbered">
+ <pre class="highlight" language="yacc" linenumbering="unnumbered">
<code>p_case_body : keyword_in
{
SET_LEX_STATE(EXPR_BEG|EXPR_LABEL);
@@ -221,7 +221,7 @@ end</code>
簡略版:
</p>
- <pre language="yacc" linenumbering="unnumbered">
+ <pre class="highlight" language="yacc" linenumbering="unnumbered">
<code>p_case_body : keyword_in p_top_expr then compstmt p_cases
;</code>
</pre>
@@ -234,7 +234,7 @@ end</code>
これにより、<code>case</code>-<code>when</code>による従来の構文と同じように、<code>then</code>等をパターンの後ろに挿入すればよいことがわかった。つまり次の3通りのいずれかになる:
</p>
- <pre language="ruby" linenumbering="unnumbered">
+ <pre class="highlight" language="ruby" linenumbering="unnumbered">
<code>case x
in 1 then a
in 2 then b
@@ -261,7 +261,7 @@ end</code>
ところで、<code>p_top_expr</code>には<code>if</code>による guard clause が書けるので、その場合は<code>if</code>-<code>then</code>と似たような見た目になる。
</p>
- <pre language="ruby" linenumbering="unnumbered">
+ <pre class="highlight" language="ruby" linenumbering="unnumbered">
<code>case x
in 0 then a
in n if n &lt; 0 then b
diff --git a/public/posts/2021-10-02/rust-where-are-primitive-types-from/index.html b/public/posts/2021-10-02/rust-where-are-primitive-types-from/index.html
index 8879a79..8bcb923 100644
--- a/public/posts/2021-10-02/rust-where-are-primitive-types-from/index.html
+++ b/public/posts/2021-10-02/rust-where-are-primitive-types-from/index.html
@@ -55,7 +55,7 @@
Rust において、プリミティブ型の名前は予約語でない。したがって、次のコードは合法である。
</p>
- <pre language="rust" linenumbering="unnumbered">
+ <pre class="highlight" language="rust" linenumbering="unnumbered">
<code>#![allow(non_camel_case_types)]
#![allow(dead_code)]
@@ -111,7 +111,7 @@ struct str;</code>
<code>rustc</code>はセルフホストされている (=<code>rustc</code>自身が Rust で書かれている) ので、<code>bool</code>や<code>char</code>などで適当に検索をかけてもノイズが多すぎて話にならない。 しかし、お誂え向きなことに<code>i128</code>/<code>u128</code>というコンパイラ自身が使うことがなさそうな型が存在するのでこれを使って<code>git grep</code>してみる。
</p>
- <pre class="monospaced">
+ <pre class="monospaced highlight">
<code>$ git grep &quot;\bi128\b&quot; | wc # i128
165 1069 15790
@@ -126,7 +126,7 @@ $ git grep &quot;\bbool\b&quot; | wc # cf. bool の結果
165 程度であれば探すことができそうだ。今回は、クレート名を見ておおよその当たりをつけた。
</p>
- <pre class="monospaced">
+ <pre class="monospaced highlight">
<code>$ git grep &quot;\bi128\b&quot;
...
rustc_resolve/src/lib.rs: table.insert(sym::i128, Int(IntTy::I128));
@@ -137,7 +137,7 @@ rustc_resolve/src/lib.rs: table.insert(sym::i128, Int(IntTy::I128));
<code>rustc_resolve</code>というのはいかにも名前解決を担いそうなクレート名である。該当箇所を見てみる。
</p>
- <pre language="rust" linenumbering="unnumbered">
+ <pre class="highlight" language="rust" linenumbering="unnumbered">
<code>/// Interns the names of the primitive types.
///
/// All other types are defined somewhere and possibly imported, but the primitive ones need
@@ -186,7 +186,7 @@ Self { primitive_types: table }
とある。次はこの struct の使用箇所を追う。追うと言っても使われている箇所は次の一箇所しかない。なお説明に不要な箇所は大きく削っている。
</p>
- <pre language="rust" linenumbering="unnumbered">
+ <pre class="highlight" language="rust" linenumbering="unnumbered">
<code> /// This resolves the identifier `ident` in the namespace `ns` in the current lexical scope.
/// (略)
fn resolve_ident_in_lexical_scope(
@@ -226,7 +226,7 @@ None
動作がわかったところで、例として次のコードを考える。
</p>
- <pre language="rust" linenumbering="unnumbered">
+ <pre class="highlight" language="rust" linenumbering="unnumbered">
<code>#![allow(non_camel_case_types)]
struct bool;
diff --git a/public/posts/2021-10-02/vim-difference-between-autocmd-bufwrite-and-bufwritepre/index.html b/public/posts/2021-10-02/vim-difference-between-autocmd-bufwrite-and-bufwritepre/index.html
index 5fc12fc..db28b1c 100644
--- a/public/posts/2021-10-02/vim-difference-between-autocmd-bufwrite-and-bufwritepre/index.html
+++ b/public/posts/2021-10-02/vim-difference-between-autocmd-bufwrite-and-bufwritepre/index.html
@@ -112,7 +112,7 @@
<a href="https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L85-L86">https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L85-L86</a>
</p>
- <pre language="c" linenumbering="unnumbered">
+ <pre class="highlight" language="c" linenumbering="unnumbered">
<code> {&quot;BufAdd&quot;, EVENT_BUFADD},
{&quot;BufCreate&quot;, EVENT_BUFADD},</code>
</pre>
@@ -121,7 +121,7 @@
<a href="https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L95-L97">https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L95-L97</a>
</p>
- <pre language="c" linenumbering="unnumbered">
+ <pre class="highlight" language="c" linenumbering="unnumbered">
<code> {&quot;BufRead&quot;, EVENT_BUFREADPOST},
{&quot;BufReadCmd&quot;, EVENT_BUFREADCMD},
{&quot;BufReadPost&quot;, EVENT_BUFREADPOST},</code>
@@ -131,7 +131,7 @@
<a href="https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L103-L105">https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L103-L105</a>
</p>
- <pre language="c" linenumbering="unnumbered">
+ <pre class="highlight" language="c" linenumbering="unnumbered">
<code> {&quot;BufWrite&quot;, EVENT_BUFWRITEPRE},
{&quot;BufWritePost&quot;, EVENT_BUFWRITEPOST},
{&quot;BufWritePre&quot;, EVENT_BUFWRITEPRE},</code>
@@ -148,7 +148,7 @@
<a href="https://github.com/neovim/neovim/blob/71d4f5851f068eeb432af34850dddda8cc1c71e3/src/nvim/auevents.lua#L119-L124">https://github.com/neovim/neovim/blob/71d4f5851f068eeb432af34850dddda8cc1c71e3/src/nvim/auevents.lua#L119-L124</a>
</p>
- <pre language="lua" linenumbering="unnumbered">
+ <pre class="highlight" language="lua" linenumbering="unnumbered">
<code> aliases = {
BufCreate = &apos;BufAdd&apos;,
BufRead = &apos;BufReadPost&apos;,
@@ -161,7 +161,7 @@ FileEncoding = &apos;EncodingChanged&apos;,
ところで、上では取り上げなかった<code>FileEncoding</code>だが、これは<code>:help FileEncoding</code>にしっかりと書いてある。
</p>
- <pre class="monospaced">
+ <pre class="monospaced highlight">
<code> *FileEncoding*
FileEncoding Obsolete. It still works and is equivalent
to |EncodingChanged|.</code>
diff --git a/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html b/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html
index afe6ba9..8a3b304 100644
--- a/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html
+++ b/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html
@@ -115,7 +115,7 @@
なお、<code>:g/^/m0</code>は全ての行を入れ替えるが、<code>:N,Mg/^/mN-1</code>とすることで N行目から M行目を処理範囲とするよう拡張できる。手でこれを入力するわけにはいかないので、次のようなコマンドを用意する。
</p>
- <pre language="vim" linenumbering="unnumbered">
+ <pre class="highlight" language="vim" linenumbering="unnumbered">
<code>command! -bar -range=%
\ Reverse
\ &lt;line1&gt;,&lt;line2&gt;g/^/m&lt;line1&gt;-1</code>
@@ -152,7 +152,7 @@
前述した<code>:Reverse</code>コマンドの定義を少し変えて、次のようにする:
</p>
- <pre language="vim" linenumbering="unnumbered">
+ <pre class="highlight" language="vim" linenumbering="unnumbered">
<code>function! s:reverse_lines(from, to) abort
execute printf(&quot;%d,%dg/^/m%d&quot;, a:from, a:to, a:from - 1)
endfunction
@@ -211,7 +211,7 @@
</p>
</blockquote>
- <pre language="vim" linenumbering="unnumbered">
+ <pre class="highlight" language="vim" linenumbering="unnumbered">
<code>command! -bar -range=%
\ Reverse
\ keeppatterns &lt;line1&gt;,&lt;line2&gt;g/^/m&lt;line1&gt;-1</code>
@@ -230,7 +230,7 @@
<section id="section--_コピペ用再掲">
<h2><a href="#section--_コピペ用再掲">コピペ用再掲</a></h2>
- <pre language="vim" linenumbering="unnumbered">
+ <pre class="highlight" language="vim" linenumbering="unnumbered">
<code>&quot; License: Public Domain
command! -bar -range=%