我试图将一个ro属性子类化,使它rw像这样:
has '+content' => (is => 'rw');
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用.这不可能吗?
我想用 Raku 建立一个课程。这是我到目前为止所拥有的:
unit class Vimwiki::File;
has Str:D $.path is required where *.IO.e;
method size {
return $.file.IO.s;
}
Run Code Online (Sandbox Code Playgroud)
我想size通过简单地让我的类继承 IO::Path 的方法来摆脱该方法,但我对如何实现这一点有点不知所措。is IO::Path当我尝试创建新对象时尝试抛出错误:
$vwf = Vimwiki::File.new(path => 't/test_file.md');
Must specify a non-empty string as a path
in block <unit> at t/01-basic.rakutest line 24
Run Code Online (Sandbox Code Playgroud) 得到这个简单的语法:
grammar H1 {
token TOP { <h1> }
token h1 { \# }
}
Run Code Online (Sandbox Code Playgroud)
结果是:Null regex not allowed Missing block
谷歌在这方面几乎没有任何发现。
这段代码$string按照我想要的方式解析:
#! /usr/bin/env raku\n\nmy $string = q:to/END/;\naaa bbb # this has trailing spaces which I want to keep\n\n kjkjsdf\nkjkdsf\nEND\n\ngrammar Markdown {\n token TOP { ^ ([ <blank> | <text> ])+ $ }\n token blank { [ \\h* <.newline> ] }\n token text { <indent> <content> }\n token indent { \\h* }\n token newline { \\n }\n token content { \\N*? <trailing>* <.newline> } \n token trailing { \\h+ }\n}\n\nmy $match = Markdown.parse($string);\n$match.say;\nRun Code Online (Sandbox Code Playgroud)\n输出
\n\xef\xbd\xa2aaa bbb\n\n …Run Code Online (Sandbox Code Playgroud) 好吧,这要么是一个错误,要么我看起来像个十足的白痴,而且我使用的环视断言完全错误。我不关心后者,所以我们开始吧。
我正在测试这个语法:
our grammar HC2 {
token TOP { <line>+ }
token line { [ <header> \n | <not-header> \n ] }
token header { <header-start> <header-content> }
token not-header { \N* }
token header-start { <header-one> }
token header-one { <[#]> <![#]> } # note this negative lookahead here
token header-content { \N* }
}
Run Code Online (Sandbox Code Playgroud)
我想捕获一个只有一个#符号的 Markdown 标题,仅此而已。
这是 Grammar::Tracer/Debugger 的输出:
所以它会直接跳过<header-start>捕获。如果我删除<![#]>否定的前瞻断言,我会得到以下结果:
这是一个错误还是我出去吃午饭了?
作为文本:
TOP
>
| line
>
| | not-header
> …Run Code Online (Sandbox Code Playgroud) 如果我做:
my $parsed_grammar = PG.parse( $some_string );
Run Code Online (Sandbox Code Playgroud)
有没有办法做类似下面的伪代码的事情?
$parsed_grammar.run_action( $action_class.new );
Run Code Online (Sandbox Code Playgroud) 我的模块t/目录中有一个测试文件,它对包含一些变量和例程的文件执行useaTestUtils操作:
use Test;
use TestUtils;
plan 4;
check_cmd_output('No arguments');
check_cmd_output('Successfully ingested', test_md_file);
check_cmd_output('Successfully ingested', test_md_file, 1);
check_cmd_output('Successfully ingested', vimwiki_arg_sim());
Run Code Online (Sandbox Code Playgroud)
效果很好。然而,Comma 抱怨TestUtils没有在“生态系统中”找到,并且抛出来自TestUtils未加载模块的标识符的错误:
我能够通过以下方式阻止逗号抱怨:
TestUtils导出文件中的标识符TestUtils::check_cmd_output(...)TestUtils到providesMETA6.json 文件中的哈希值。我想可能有更好的方法。我尝试做类似use lib 't'和 之类的事情use lib '.',但这没有帮助。谢谢。
我在类中有一个方法:
method options(*@opt) {
if !@!valid-options {
my $out = (cmd 'bin/md2html -h').out;
my @matches = $out ~~ m:g/\s'--'(<-[\s]>+)/;
for @matches -> $opt {
push @!valid-options, $opt[0].Str;
}
}
for @opt -> $opt {
when !($opt (elem) @!valid-options) {
warn "'$opt' is not a valid option";
}
push @!options, '--' ~ $opt;
}
}
Run Code Online (Sandbox Code Playgroud)
该方法检查选项以查看它们是否有效,如果有效,则将它们放入属性中。
我将参数传递到options方法中,如下所示:
$obj.options: <ftables ftasklists github>;
这有效。但这让我想知道是否可以将选项作为命名标志传递,如下所示:
$obj.options: :ftables, :ftasklists, :github
但由于我事先不知道命令的所有选项,因此我需要动态生成命名参数。这可能吗?我尝试过这个但没有运气:
# create a signature
my @params = Parameter.new(name => ':$option', type => …Run Code Online (Sandbox Code Playgroud) 在尝试使用 App::Mi6 命令将新模块上传到 zef 时,出现了我以前从未见过的奇怪错误mi6 release:
==> Step 9. UploadToZef
Are you sure you want to upload Directory-0.0.1.tar.gz to Zef ecosystem? (y/N) y
Executing /Users/steve/.rakubrew/versions/moar-2022.12/bin/rakudo -e use Fez::CLI --file=Directory-0.0.1.tar.gz upload
>>= Looking in "Directory-0.0.1.tar.gz" for META6.json
=<< No single root directory found, all dists must extract to a single directory
Failed
in method upload at /Users/steve/.rakubrew/versions/moar-2022.12/share/perl6/site/sources/12D2D4FC78FDF40E8B7DEC72AF31ECED31A67D08 (App::Mi6::Fez) line 19
in method run at /Users/steve/.rakubrew/versions/moar-2022.12/share/perl6/site/sources/A4949DB54562D3B5154DD447B5CC2C730F09B0E5 (App::Mi6::Release::UploadToZef) line 24
in method run at /Users/steve/.rakubrew/versions/moar-2022.12/share/perl6/site/sources/BDF7095037EE976677901A8557FD533DCDC6FD65 (App::Mi6::Release) line 49
in method cmd …Run Code Online (Sandbox Code Playgroud)