Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GitHub Linguistと学ぶ!全国このコードはPerlとRakuどっちでしょうクイズ選...

polamjag
February 10, 2024

GitHub Linguistと学ぶ!全国このコードはPerlとRakuどっちでしょうクイズ選手権大会 in YAPC::Hiroshima 2024 #yapcjapan

polamjag

February 10, 2024
Tweet

More Decks by polamjag

Other Decks in Programming

Transcript

  1. 8 use v6; use Test; use ***; use ***; plan

    2; if %*ENV<NO_NETWORK_TESTING> { diag "NO_NETWORK_TESTING was set"; skip-rest("NO_NETWORK_TESTING was set"); exit; } my %headers = "Accept" => "application/json", "User-Agent" => "...", ; (固有名詞などはマスク)
  2. 10 use strict; use warnings; use ****::****; # (略) subtest

    'request_send' => sub { my $ua = ua; my $res = $ua->get('http://www.example.com'); ok($res->is_success, 'handler should succeed'); is($res->content,'ok','handler-provided response should be used'); }; subtest 'request_prepare' => sub { my $ua = ua; $ua->add_handler( request_prepare => sub { # the docs say this is the way to replace the request $_[0] = HTTP::Request->new(POST=>'http://mmm.example.com/'); (固有名詞などはマスク)
  3. 12 use v6; use Test; use Auth::SASL; my $sasl =

    Auth::SASL.new; ok $sasl, 'got an object'; isa-ok $sasl, Auth::SASL; ok $sasl.supports-client-mechanisms('PLAIN'), 'supports PLAIN'; ok $sasl.supports-client-mechanisms('ANONYMOUS'), 'supports ANONYMOUS'; ok $sasl.supports-client-mechanisms('PLAIN ANONYMOUS'), 'supports PLAIN ANONYMOUS'; ok $sasl.supports-client-mechanisms('PLAIN WEIRD'), 'supports PLAIN WEIRD'; nok $sasl.supports-client-mechanisms('SUPER WEIRD'), 'does not supoprt SUPER WEIRD'; (固有名詞などはマスク)
  4. 14 use v6; use Test; use BSON; # (略) #------------------------------------------------------------------------------

    - subtest { my BSON::Javascript $js .= new( :javascript('function(x){return x;}') ); my BSON::Javascript $js-scope .= new( :javascript('function(x){return x;}'), :scope(BSON::Document.new: (nn => 10, a1 => 2)) ); (固有名詞などはマスク)
  5. 16 use Test; plan 6; use Digest::HMAC; use Digest::MD5; use

    Digest::SHA1; use Digest::SHA2; # tests taken from wikipedia is hmac-hex("", "", &md5), '74e6f7298a9c2d168935f58c001bad88', "Empty md5 HMAC"; is hmac-hex("", "", &sha1), 'fbdb1d1b18aa6c08324b7d64b71fb76370690e1d', "Empty SHA1 HMAC"; is hmac-hex("", "", &sha256), 'b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad', "Empty SHA256 HMAC";
  6. 21

  7. 22

  8. 23

  9. 24 # A strategy should return an Array of Language

    candidates. # # Strategies are called in turn until a single Language is re STRATEGIES = [ Linguist::Strategy::Modeline, Linguist::Strategy::Filename, Linguist::Shebang, Linguist::Strategy::Extension, Linguist::Strategy::XML, Linguist::Strategy::Manpage, Linguist::Heuristics, Linguist::Classifier ] … cpanfile は Perl、.irbrc は Ruby など
  10. 25 returning_strategy = nil STRATEGIES.each do |strategy| returning_strategy = strategy

    candidates = Linguist.instrument("linguist.strategy", :blob => blob, :str strategy.call(blob, languages) end if candidates.size == 1 languages = candidates break elsif candidates.size > 1 # More than one candidate was found, pass them to the next strategy. languages = candidates else # No candidates, try the next strategy end end
  11. 27

  12. 29

  13. 31 - extensions: ['.t'] rules: - language: Perl and: -

    negative_pattern: '^\s*use\s+v6\b' - named_pattern: perl - language: Raku pattern: '^\s*(?:use\s+v6\b|\bmodule\b|\bmy\s+class\b)'
  14. 32

  15. 33

  16. 35 - extensions: ['.t'] rules: - language: Perl and: -

    negative_pattern: '^\s*use\s+v6\b' - named_pattern: perl - language: Raku pattern: '^\s*(?:use\s+v6\b|\bmodule\b|\bmy\s+class\b)'
  17. 36 - extensions: ['.t'] rules: - language: Perl and: -

    negative_pattern: '^\s*use\s+v6\b' - named_pattern: perl - language: Raku pattern: '^\s*(?:use\s+v6\b|\bmodule\b|\bmy\s+class\b)'
  18. 37 - extensions: ['.t'] rules: - language: Perl and: -

    negative_pattern: '^\s*use\s+v6\b' - named_pattern: perl - language: Raku pattern: '^\s*(?:use\s+v6\b|\bmodule\b|\bmy\s+class\b)' use v6 って書いてたら Perl 5じゃない (それはそう)
  19. 38 named_patterns: (snip) objectivec: '^\s*(@(interface|class|protocol|property|end|synchronise perl: - '\buse\s+(?:strict\b|v?5\b)' - '^\s*use\s+(?:constant|overload)\b'

    - '^\s*(?:\*|(?:our\s*)?@)EXPORT\s*=' - '^\s*package\s+[^\W\d]\w*(?:::\w+)*\s*(?:[;{]|\sv?\d)' - '[\s$][^\W\d]\w*(?::\w+)*->[a-zA-Z_\[({]' raku: '^\s*(?:use\s+v6\b|\bmodule\b|\b(?:my\s+)?class\b)' vb-class: '^[ ]*VERSION [0-9]\.[0-9] CLASS' vb-form: '^[ ]*VERSION [0-9]\.[0-9]{2}' vb-module: '^[ ]*Attribute VB_Name = ' vba: - '\b(?:VBA|[vV]ba)(?:\b|[0-9A-Z_])'
  20. 39 named_patterns: (snip) objectivec: '^\s*(@(interface|class|protocol|property|end|synchronise perl: - '\buse\s+(?:strict\b|v?5\b)' - '^\s*use\s+(?:constant|overload)\b'

    - '^\s*(?:\*|(?:our\s*)?@)EXPORT\s*=' - '^\s*package\s+[^\W\d]\w*(?:::\w+)*\s*(?:[;{]|\sv?\d)' - '[\s$][^\W\d]\w*(?::\w+)*->[a-zA-Z_\[({]' raku: '^\s*(?:use\s+v6\b|\bmodule\b|\b(?:my\s+)?class\b)' vb-class: '^[ ]*VERSION [0-9]\.[0-9] CLASS' vb-form: '^[ ]*VERSION [0-9]\.[0-9]{2}' vb-module: '^[ ]*Attribute VB_Name = ' vba: - '\b(?:VBA|[vV]ba)(?:\b|[0-9A-Z_])'
  21. 40 named_patterns: (snip) objectivec: '^\s*(@(interface|class|protocol|property|end|synchronise perl: - '\buse\s+(?:strict\b|v?5\b)' - '^\s*use\s+(?:constant|overload)\b'

    - '^\s*(?:\*|(?:our\s*)?@)EXPORT\s*=' - '^\s*package\s+[^\W\d]\w*(?:::\w+)*\s*(?:[;{]|\sv?\d)' - '[\s$][^\W\d]\w*(?::\w+)*->[a-zA-Z_\[({]' raku: '^\s*(?:use\s+v6\b|\bmodule\b|\b(?:my\s+)?class\b)' パッケージ (クラス) を定義する構文 メソッド呼び出しの構文 use strict 概念の有無
  22. 44 .inc 11 .m 7 .fcgi 6 .cls 6 .sql

    5 .pro 5 .yml 4 .yaml 4 .x 4 .t 4 .sch 4 .ncl 4 .mod 4 .l 4 .gs 4 .gml 4 .fs 4 .bf 4 .bas 4 languages.yml基準 拡張子被りランキング 8c380f3 基準
  23. 45 .inc 11 .m 7 .fcgi 6 .cls 6 .sql

    5 .pro 5 .yml 4 .yaml 4 .x 4 .t 4 .sch 4 .ncl 4 .mod 4 .l 4 .gs 4 .gml 4 .fs 4 .bf 4 .bas 4 Assembly, C++, HTML, Motorola 68K Assembly, NASL, Pascal, Pawn, PHP, POV-Ray SDL, SourcePawn, SQL Lua, Perl, PHP, Python, Ruby, Shell Perl, Raku, Terra, Turing
  24. 47

  25. 48