ときどきの雑記帖 RE* (新南口)
Starship operators
日本の巨大ロボット群像@横須賀美術館
なんとか 鈴木敏夫とジブリ展 | 展覧会 | 横須賀美術館 が始まる前に行ってきた。
「物足りない」のは否定できないけど、 行ってよかったと思えるものでした。 次の巡回地がどこなのか(まだ)わからないけど、 あなた(誰)がお住まいの地域近くに来たときはぜひ。
詳細な感想は今余裕がないのであとで(そういや永野護デザイン展の話もまだだった…)
awk
gawk
gawkのコミットを追いかけていたら興味深いものがあった。
minrx
以前からgawkのリポジトリのなかに feature/minrx というブランチがあることには気づいていたのだけど、 それがどういう目的のものなのかはわからなかった。 feature/cpp-compile のような名前だとわかりやすいのだけど。
今回、そのminrxがなんなのかがわかるコミット Add README_d/README.matchers. があった。
追加されたファイルREADME.matchers の中身を見ると
Sun 10 Mar 2024 10:39:42 IST
============================
* I * M * P * O * R * T * A * N * T *
This release includes a new regular expression matcher, MinRX, written
by Mike Haertel, the original author of GNU grep. It's available from
GITHUB URL HERE.
This matcher is fully POSIX compliant, which the current GNU matchers
are not. In particular it follows POSIX rules for finding the longest
leftmost submatches. It is also more strict as to regular expression
syntax, but primarily in a few corner cases that normal, correct,
regular expression usage should not encounter.
Because regular expression matching is such a fundamental part of
awk/gawk, the original GNU matchers are still included in gawk. In order
to use them, give a value to the GAWK_GNU_MATCHERS environment variable
before invoking gawk.
If you find a difference in behavior between the new and original
matchers, please report it. In particular if it adversely affects your
current application(s). Note that if the difference is due to being fully
POSIX compliant, then you should consider revising your application.
Please use the gawkbug script to report any issues, as would be done
for any other bug. See node Bugs in the manual for more details; it's
online at https://www.gnu.org/software/gawk/manual/html_node/Bugs.html.
MinRX is currently written in C++, so you will need to have g++
installed on your system. It will eventually be rewritten in C for
greater portability.
PLEASE NOTE! The original GNU matchers will eventually be removed from
gawk. So, please take the time to notice and report any issues in the
MinRX matcher, so that they can be ironed out sooner rather than later.
Thanks!
正規表現エンジンを(よりPOSIXに従った実装のものに)入れ替えるという話らしい。
どんなコードなのだろうとリポジトリを探してみたのだけど
それらしいものは見つけられなかった。
上記のドキュメントの冒頭にも
It's available from GITHUB URL HERE.
とあるので、まだ公開されていないもの?
githubに同じ名前のものがあったけどそれは別物らしい。
feature/minrxにあるgawk本体のコードを見ると minrx対応のためだろう部分がいくつか見つかる。 たとえば
/* research --- do a regexp search. use dfa if possible */
int
research(Regexp *rp, char *str, int start,
size_t len, int flags)
{
const char *ret = str;
bool try_backref = false;
int need_start;
int no_bol;
int res;
int minrx_flags = 0;
need_start = ((flags & RE_NEED_START) != 0);
no_bol = ((flags & RE_NO_BOL) != 0);
if (use_gnu_matchers) {
if (no_bol)
rp->pat.not_bol = 1;
/*
* Always do dfa search if can; if it fails, then even if
* need_start is true, we won't bother with the regex search.
*
* The dfa matcher doesn't have a no_bol flag, so don't bother
* trying it in that case.
*
* 7/2008: Skip the dfa matcher if need_start. The dfa matcher
* has bugs in certain multibyte cases and it's too difficult
* to try to special case things.
* 7/2017: Apparently there are some cases where DFA gets
* stuck, even in the C locale, so we use dfa only if not need_start.
*
* Should that issue ever get resolved, note this comment:
*
* 7/2016: The dfa matcher can't handle a case where searching
* starts in the middle of a string, so don't bother trying it
* in that case.
* if (rp->dfa && ! no_bol && start == 0) ...
*/
if (rp->dfareg != NULL && ! no_bol && ! need_start) {
struct dfa *superset = dfasuperset(rp->dfareg);
if (superset)
ret = dfaexec(superset, str+start, str+start+len,
true, NULL, NULL);
if (ret && (! need_start
|| (! superset && dfaisfast(rp->dfareg))))
ret = dfaexec(rp->dfareg, str+start, str+start+len,
true, NULL, &try_backref);
}
if (ret) {
if ( rp->dfareg == NULL
|| start != 0
|| no_bol
|| need_start
|| try_backref) {
/*
* Passing NULL as last arg speeds up search for cases
* where we don't need the start/end info.
*/
res = re_search(&(rp->pat), str, start+len,
start, len, need_start ? &(rp->regs) : NULL);
} else
res = 1;
} else
res = -1;
rp->pat.not_bol = 0;
} else {
if (no_bol)
minrx_flags |= MINRX_REG_NOTBOL;
memset(rp->mre_regs, 0, (rp->mre_pat.re_nsub + 1) * sizeof(minrx_regmatch_t));
if (start > 0) {
rp->mre_regs[0].rm_eo = start;
minrx_flags |= MINRX_REG_RESUME;
}
res = minrx_regnexec(&(rp->mre_pat),
len, str,
need_start ? rp->mre_pat.re_nsub + 1 : 1,
rp->mre_regs,
minrx_flags);
if (res == 0)
res = rp->mre_regs[0].rm_so;
else
res = -1;
}
return res;
}
ふと気になったのだけど Tom Lordの正規表現ライブラリ rxと 何か関係があるんだろうか>minrx
Hugo メモ
つづき。
結局、 どのバージョンでエラーが起きるようになるのか (マイナーバージョン単位で)ひとつひとつ 確かめた。 その結果、0.122.0→0.123.0で変わっていることがわかった。
PS C:\Users\kbk> $env:HUGO_ENV="" ; hugo --buildFuture server --source C:\Users\kbk\home\mypage\z3 --logLevel error --verbose
Watching for changes in C:\Users\kbk\home\mypage\z3\{content,layouts,static,themes}
Watching for config changes in C:\Users\kbk\home\mypage\z3\config.toml, C:\Users\kbk\home\mypage\z3\themes\ananke\config.yaml
Start building sites …
hugo v0.122.0-b9a03bd59d5f71a529acb3e33f995e0ef332b3aa+extended windows/amd64 BuildDate=2024-01-26T15:54:24Z VendorInfo=gohugoio
| JA
-------------------+------
Pages | 378
Paginator pages | 30
Non-page files | 2
Static files | 10
Processed images | 0
Aliases | 3
Sitemaps | 1
Cleaned | 0
Built in 1934 ms
Environment: "development"
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at http://localhost:1313/~kbk/zakkicho/ (bind address 127.0.0.1)
Press Ctrl+C to stop
PS C:\Users\kbk> $env:HUGO_ENV="" ; hugo --buildFuture server --source C:\Users\kbk\home\mypage\z3 --logLevel error --verbose
Watching for changes in C:\Users\kbk\home\mypage\z3\{content,layouts,static,themes}
Watching for config changes in C:\Users\kbk\home\mypage\z3\config.toml, C:\Users\kbk\home\mypage\z3\themes\ananke\config.yaml
Start building sites …
hugo v0.123.0-3c8a4713908e48e6523f058ca126710397aa4ed5+extended windows/amd64 BuildDate=2024-02-19T16:32:38Z VendorInfo=gohugoio
ERROR failed to fetch remote resource: Forbidden
Built in 2944 ms
Error: error building site: logged 1 error(s)
PS C:\Users\kbk>
それからエラーメッセージfailed to fetch remote resource
がソースコードのどこにあるのか探してみた
Code search results
ところ
hugo/resources/resource_factories/create/remote.go
if res.StatusCode != http.StatusNotFound {
if res.StatusCode < 200 || res.StatusCode > 299 {
return nil,
temporaryHTTPStatusCodes[res.StatusCode],
toHTTPError(
fmt.Errorf(
"failed to fetch remote resource: %s",
http.StatusText(res.StatusCode)),
res, !isHeadMethod)
}
}
で出されているもののようだ(幅を小さくするためインデントが変になっているけどご容赦)
同じ文字列は hugo/hugolib/resource_chain_test.go にもあるけどこちらではないようだ。
さらにtweet のshortcode (hugo/tpl/tplimpl/embedded/templates/shortcodes/twitter.html) がどうなっているか確かめたら
{{- with resources.GetRemote $request -}}
{{- with .Err -}}
{{- errorf "%s" . -}}
{{- else -}}
{{- (. | transform.Unmarshal).html | safeHTML -}}
{{- end -}}
{{- else -}}
{{- warnidf "shortcode-twitter-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" .name .position -}}
{{- end -}}
この辺りが実に怪しい。 じゃあこのファイルの変更履歴はと History for tpl/tplimpl/embedded/templates/shortcodes/twitter.html - gohugoio/hugo をみると、2024年2月2日にコミット tpl/tplimpl: Update embedded instagram, twitter, and vimeo shortcodes · gohugoio/hugo@d0788b9 がある。
- {{- $json := getJSON $request -}}
- {{- if not .disableInlineCSS -}}
- {{- template "__h_simple_twitter_css" .ctx -}}
- {{- end }}
- {{ $json.html | safeHTML -}}
+ {{- with resources.GetRemote $request -}}
+ {{- with .Err -}}
+ {{- errorf "%s" . -}}
+ {{- else -}}
+ {{- (. | transform.Unmarshal).html | safeHTML -}}
+ {{- end -}}
+ {{- else -}}
+ {{- warnidf "shortcode-twitter-simple-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" .name .position -}}
+ {{- end -}}
この変更が引き金っぽい。 この変更の理由を確かめてみたところ
tpl/tplimpl: Update embedded instagram, twitter, and vimeo shortcodes · gohugoio/hugo@d0788b9
Commit
tpl/tplimpl: Update embedded instagram, twitter, and vimeo shortcodes
- Replace data.GetJSON calls with resources.GetRemote
- Remove usage of Facebook’s oEmbed Read feature
Fixes #11971
元のコードで使っていたgetJSON
がdeprecatedになったので
resources.GetRemote
を使うようにしたと。
resources.GetRemote
を使った方だと
エラーが起きたかなどを見ているけど、古いgetJSONの方だとそれはない。
ということなので、今まではサイトのビルドができていた。ということなのか。
原因はわかったが、さてどう対処しようか。
弊社
会社員のやっていたころ
— ゆきうさぎ@フリーのシステム屋 (@__snow_rabbit__) March 10, 2024
「有給は病気にかかった時のため用で原則取るな」
みたいな感じだったので(毎年20日づつ有給が消滅していたんだが…5年で100日くらい有給消滅)
「有給消化率ランキング」
を見ると…元弊社。上位にランクインしているんだよね。
なんで?
って思った。
「『元』弊社」って表現はナシだと思うけど ちょくちょく見かけますわね…