Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
first hacky shot at Version and version literals
  • Loading branch information
moritz committed May 12, 2012
1 parent 5f9d1ad commit 85f636b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
20 changes: 20 additions & 0 deletions src/Perl6/Actions.pm
Expand Up @@ -4151,6 +4151,26 @@ class Perl6::Actions is HLL::Actions {
method value:sym<number>($/) {
make $<number>.ast;
}
method value:sym<version>($/) {
make $<version>.ast;
}
method vnum($/) {
if $<decint> {
make $<decint>.ast;
}
else {
make $*W.find_symbol(['Whatever']).new;
}
}
method version($/) {
my @vnums;
for $<vnum> -> $v {
nqp::push(@vnums, $v.ast);
}
my $v := $*W.find_symbol(['Version']).new(|@vnums, :plus(?$/[0]));
$*W.add_object($v);
make $*W.get_ref($v);
}

method decint($/) { make string_to_bigint( $/, 10); }
method hexint($/) { make string_to_bigint( $/, 16); }
Expand Down
19 changes: 11 additions & 8 deletions src/Perl6/Grammar.pm
Expand Up @@ -387,6 +387,16 @@ grammar Perl6::Grammar is HLL::Grammar {

token install_doc_phaser { <?> }

token vnum {
<decint> | '*'
}

token version {
'v' {} <?before \d+> <vnum> ** '.' ('+')?
<!before '-'|\'> # cheat because of LTM fail
}


## Top-level rules

token comp_unit {
Expand Down Expand Up @@ -686,14 +696,6 @@ grammar Perl6::Grammar is HLL::Grammar {
<block>
}

token vnum {
\d+ | '*'
}

token version {
'v' <?before \d+> <vnum> ** '.' '+'?
}

token statement_control:sym<need> {
<sym> <.ws>
[
Expand Down Expand Up @@ -2066,6 +2068,7 @@ grammar Perl6::Grammar is HLL::Grammar {
proto token value { <...> }
token value:sym<quote> { <quote> }
token value:sym<number> { <number> }
token value:sym<version> { <version> }

proto token number { <...> }
token number:sym<complex> { <im=.numish>'\\'?'i' }
Expand Down
16 changes: 16 additions & 0 deletions src/core/Version.pm
@@ -0,0 +1,16 @@
class Version is List {
has Bool $.plus = False;
method new(*@positional, :$plus) {
my $new := nextwith(@positional);
nqp::bindattr($new, Version, '$!plus', so $plus);
$new;
}
multi method Str(Version:D:) {
'v' ~ self.join('.');
}
multi method gist(Version:D:) { self.Str }
multi method perl(Version:D:) {
self.^name ~ '.new(' ~ self.List::perl ~ ', :plus(' ~ $!plus.perl ~ '))';

}
}
1 change: 1 addition & 0 deletions tools/build/Makefile.in
Expand Up @@ -228,6 +228,7 @@ CORE_SOURCES = \
src/core/Set.pm \
src/core/Bag.pm \
src/core/ObjAt.pm \
src/core/Version.pm \
src/core/operators.pm \
src/core/metaops.pm \
src/core/terms.pm \
Expand Down

0 comments on commit 85f636b

Please sign in to comment.