Skip to content

Instantly share code, notes, and snippets.

@tony-o
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tony-o/501440a2e7182db2beb3 to your computer and use it in GitHub Desktop.
Save tony-o/501440a2e7182db2beb3 to your computer and use it in GitHub Desktop.
sub perform(Str $statement?, @args?, $cb?) is export {
  'here'.say;
  $statement.say;
  @args.say;
}

sub EXPORT(|) {
  role SQL::Grammar {
    rule statement_control:sym<with> {
      <sym>
      '('
        <arglist>
      ')'
      <sql>
      <block=.block>
    }
    token sql {
      .*? <?before '{'>
    }
  }
  role SQL::Actions {
    method statement_control:sym<with>(Mu $/) {
      #make $<sym>;
      say(~$<sym>);
      #say($<args>);
      #QAST::Op.new(:op('call'), :name('&perform'), QAST::SVal.new(:value('sql')));
    }
  }
  nqp::bindkey(%*LANG, 'MAIN', %*LANG<MAIN>.HOW.mixin(%*LANG<MAIN>, SQL::Grammar));
  nqp::bindkey(%*LANG, 'MAIN-actions', %*LANG<MAIN>.HOW.mixin(%*LANG<MAIN-actions>, SQL::Actions));
  {}
}

test:

#!/usr/bin/env perl6

use lib 'lib';
use Slang::SQL;

my @a = 5;
with (@a) select * from stuff where id >= ? {
  'hello'.say;
};

results:

Cannot call 'postcircumfix:<{ }>'; none of these signatures match:
:(Any \SELF, Any \key)
:(Any \SELF, Any \key, \ASSIGN)
:(Any \SELF, Any \key, :BIND($BIND)!)
:(Any \SELF, Any \key, Any :SINK($SINK)!, *%other)
:(Any \SELF, Any \key, Any :delete($delete)!, *%other)
:(Any \SELF, Any \key, Any :exists($exists)!, *%other)
:(Any \SELF, Any \key, Any :kv($kv)!, *%other)
:(Any \SELF, Any \key, Any :p($p)!, *%other)
:(Any \SELF, Any \key, Any :k($k)!, *%other)
:(Any \SELF, Any \key, Any :v($v)!, *%other)
:(Any \SELF, Positional \key)
:(Any \SELF, Positional \key, \ASSIGN)
:(Any \SELF, Positional \key, Any :BIND($BIND)!)
:(Any \SELF, Positional \key, Any :SINK($SINK)!, *%other)
:(Any \SELF, Positional \key, Any :delete($delete)!, *%other)
:(Any \SELF, Positional \key, Any :exists($exists)!, *%other)
:(Any \SELF, Positional \key, Any :kv($kv)!, *%other)
:(Any \SELF, Positional \key, Any :p($p)!, *%other)
:(Any \SELF, Positional \key, Any :k($k)!, *%other)
Press ENTER or type command to continue
:(Any \SELF, Positional \key, Any :v($v)!, *%other)
:(Any \SELF, Whatever)
:(Any \SELF, Whatever, \ASSIGN)
:(Any \SELF, Whatever, Any :BIND($BIND)!)
:(Any \SELF, Whatever, Any :SINK($SINK)!, *%other)
:(Any \SELF, Whatever, Any :delete($delete)!, *%other)
:(Any \SELF, Whatever, Any :exists($exists)!, *%other)
:(Any \SELF, Whatever, Any :kv($kv)!, *%other)
:(Any \SELF, Whatever, Any :p($p)!, *%other)
:(Any \SELF, Whatever, Any :k($k)!, *%other)
:(Any \SELF, Whatever, Any :p($p)!, *%other)
:(Any \SELF)
:(Any \SELF, Any :BIND($BIND)!)
:(Any \SELF, Any :SINK($SINK)!, *%other)
:(Any \SELF, Any :delete($delete)!, *%other)
:(Any \SELF, Any :exists($exists)!, *%other)
:(Any \SELF, Any :kv($kv)!, *%other)
:(Any \SELF, Any :p($p)!, *%other)
:(Any \SELF, Any :k($k)!, *%other)
:(Any \SELF, Any :p($p)!, *%other)
:(Any \SELF is rw, LoL \keys, *%adv)
:(Any \SELF is rw, LoL \keys, \assignee, *%adv)
:(VM $d, Str $ where { ... })
:(VM $d, Str $ where { ... })
:(Compiler $d, Str $ where { ... })
:(Compiler $d, Str $ where { ... })
:(Compiler $d, Str $ where { ... })
:(Compiler $d, Str $ where { ... })
:(Compiler $d, Str $ where { ... })
:(Perl $d, Str $ where { ... })
:(Perl $d, Str $ where { ... })
:(CompUnit:D \c, Str $ where { ... })
:(CompUnit:D \c, Str $ where { ... })
:(CompUnit:D \c, Str $ where { ... })
   at src/gen/m-CORE.setting:12159  (/Users/tony/Downloads/rakudo/install/languages/perl6/runtime/CORE.setting.moarvm:throw:88)
 from src/gen/m-CORE.setting:13646  (/Users/tony/Downloads/rakudo/install/languages/perl6/runtime/CORE.setting.moarvm::33)
 from src/gen/m-BOOTSTRAP.nqp:2137  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/Perl6/BOOTSTRAP.moarvm::627)
 from src/gen/m-CORE.setting:2896  (/Users/tony/Downloads/rakudo/install/languages/perl6/runtime/CORE.setting.moarvm:postcircumfix:<{ }>:22)
 from /Users/tony/projects/perl6-slang-sql/lib/Slang/SQL.pm6:24  (<ephemeral file>:statement_control:sym<with>:40)
 from gen/moar/stage2/QRegex.nqp:779  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/QRegex.moarvm:!reduce:29)
 from gen/moar/stage2/QRegex.nqp:740  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/QRegex.moarvm:!cursor_pass:47)
 from /Users/tony/projects/perl6-slang-sql/lib/Slang/SQL.pm6:9  (<ephemeral file>:statement_control:sym<with>:407)
 from gen/moar/stage2/QRegex.nqp:816  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/QRegex.moarvm:!protoregex:110)
 from <unknown>:1  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/Perl6/Grammar.moarvm:statement_control:10)
 from src/Perl6/Grammar.nqp:1302  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/Perl6/Grammar.moarvm:statement:325)
 from src/Perl6/Grammar.nqp:1237  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/Perl6/Grammar.moarvm:statementlist:241)
 from gen/moar/stage2/NQPHLL.nqp:855  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/NQPHLL.moarvm:LANG:146)
 from src/Perl6/Grammar.nqp:1644  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/Perl6/Grammar.moarvm:FOREIGN_LANG:67)
 from src/Perl6/Grammar.nqp:1095  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/Perl6/Grammar.moarvm:comp_unit:2818)
 from src/Perl6/Grammar.nqp:356  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/Perl6/Grammar.moarvm:TOP:487)
 from gen/moar/stage2/QRegex.nqp:1410  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/QRegex.moarvm:parse:44)
 from gen/moar/stage2/NQPHLL.nqp:1515  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/NQPHLL.moarvm:parse:80)
 from gen/moar/stage2/NQPHLL.nqp:1471  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/NQPHLL.moarvm:compile:199)
 from gen/moar/stage2/NQPHLL.nqp:1217  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/NQPHLL.moarvm:eval:53)
 from gen/moar/stage2/NQPHLL.nqp:1427  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/NQPHLL.moarvm:evalfiles:87)
 from gen/moar/stage2/NQPHLL.nqp:1330  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/NQPHLL.moarvm:command_eval:211)
 from src/Perl6/Compiler.nqp:17  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/Perl6/Compiler.moarvm:command_eval:93)
 from gen/moar/stage2/NQPHLL.nqp:1305  (/Users/tony/Downloads/rakudo/install/languages/nqp/lib/NQPHLL.moarvm:command_line:116)
 from src/gen/m-main.nqp:39  (/Users/tony/Downloads/rakudo/install/languages/perl6/runtime/perl6.moarvm:MAIN:18)
 from src/gen/m-main.nqp:35  (/Users/tony/Downloads/rakudo/install/languages/perl6/runtime/perl6.moarvm:<mainline>:197)
 from <unknown>:1  (/Users/tony/Downloads/rakudo/install/languages/perl6/runtime/perl6.moarvm:<main>:8)
 from <unknown>:1  (/Users/tony/Downloads/rakudo/install/languages/perl6/runtime/perl6.moarvm:<entry>:9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment