Skip to content

Commit

Permalink
0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Sep 22, 2023
1 parent 02f9045 commit 7ce3abb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ Revision history for Slang::Roman

{{$NEXT}}

0.5 2023-09-22T11:16:56+02:00
- Fix issue with "to-roman" introduced in 0.3
- Add support for running under RakuAST, including deparsing

0.4 2023-09-22T00:36:47+02:00
- Add dependency on Slangify

Expand Down
2 changes: 1 addition & 1 deletion META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
],
"test-depends": [
],
"version": "0.4"
"version": "0.5"
}
23 changes: 20 additions & 3 deletions lib/Slang/Roman.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ my constant %char-map =
;

# Convert a given integer value to a Roman numeral string
my constant @nums = %num-map.keys.sort.reverse;
my constant @nums = %num-map.keys.sort(*.Int).reverse;
my sub to-roman(Int:D $val) is export {
my $current = $val;
my str @parts;
Expand Down Expand Up @@ -98,9 +98,26 @@ my role Grammar {
my role Actions {
method number:sym<roman>(Mu $/) {
CATCH { OUTER::<$/>.panic: .message }
my $value := to-number($/.Str);

# Running under the Raku grammar
if self.^name.starts-with('Raku::') {
use experimental :rakuast;
my class RakuAST::RomanLiteral is RakuAST::IntLiteral {
my class Roman {
has $.value;
method raku() { '0r' ~ to-roman($!value) }
}
method value() { Roman.new(value => callsame) }
}
make RakuAST::RomanLiteral.new($value);
}

use QAST:from<NQP>;
make QAST::IVal.new(:value(to-number($/.Str)));
# Running under the legacy grammar
else {
use QAST:from<NQP>;
make QAST::IVal.new(:$value);
}
}
}

Expand Down

0 comments on commit 7ce3abb

Please sign in to comment.