module Dice

Included Modules

Defined in:

dice.cr

Constant Summary

NODES = {"number_digital" => {:super => ["Unions::Number"], :block => do getter(value : Int32) do raw.to_i end end}, "one" => {:super => ["Unions::NumberLiteral"], :block => do def value 1 end end}, "two" => {:super => ["Unions::NumberLiteral"], :block => do def value 2 end end}, "three" => {:super => ["Unions::NumberLiteral"], :block => do def value 3 end end}, "four" => {:super => ["Unions::NumberLiteral"], :block => do def value 4 end end}, "five" => {:super => ["Unions::NumberLiteral"], :block => do def value 5 end end}, "six" => {:super => ["Unions::NumberLiteral"], :block => do def value 6 end end}, "eight" => {:super => ["Unions::NumberLiteral"], :block => do def value 8 end end}, "ten" => {:super => ["Unions::NumberLiteral"], :block => do def value 10 end end}, "twelve" => {:super => ["Unions::NumberLiteral"], :block => do def value 12 end end}, "fourteen" => {:super => ["Unions::NumberLiteral"], :block => do def value 14 end end}, "sixteen" => {:super => ["Unions::NumberLiteral"], :block => do def value 16 end end}, "eighteen" => {:super => ["Unions::NumberLiteral"], :block => do def value 18 end end}, "twenty" => {:super => ["Unions::NumberLiteral"], :block => do def value 20 end end}, "one_hundred" => {:super => [], :block => do def value 100 end end}, "number_literal" => {:super => ["Unions::Number"], :block => do def onion [one?, two?, three?, four?, five?, six?, eight?, ten?, twelve?, fourteen?, sixteen?, eighteen?, twenty?].compact.first.as(Unions::NumberLiteral) end macro method_missing(call) {% if call.args.size >= 1 %} onion.{{ call.name }}({{ call.args }}) {% else %} onion.{{ call.name }}() {% end %} end end}, "number" => {:super => [], :block => do def onion [number_literal?, number_digital?].compact.first.as(Unions::Number) end macro method_missing(call) {% if call.args.size >= 1 %} onion.{{ call.name }}({{ call.args }}) {% else %} onion.{{ call.name }}() {% end %} end end}, "fudge" => {:super => ["Unions::Dice"], :block => do def value (rand(3)) - 1 end end}, "percent" => {:super => ["Unions::Dice"], :block => do def value rand(100) end end}, "faced" => {:super => ["Unions::Dice"], :block => do def value rand(number.onion.value) end end}, "dice" => {:super => [], :block => do def onion [faced?, percent?, fudge?].compact.first.as(Unions::Dice) end macro method_missing(call) {% if call.args.size >= 1 %} onion.{{ call.name }}({{ call.args }}) {% else %} onion.{{ call.name }}() {% end %} end end}, "compact_roll" => {:super => ["Unions::SingleRoll"], :block => do getter(values : Array(Int32)) do Array(Int32).new(number_digital.value) do dice.onion.value end end end}, "verbose_roll" => {:super => ["Unions::SingleRoll"], :block => do getter(values : Array(Int32)) do Array(Int32).new(number.onion.value) do dice.onion.value end end end}, "literal_roll" => {:super => ["Unions::SingleRoll"], :block => do getter(values : Array(Int32)) do [number.onion.value] end end}, "single_roll" => {:super => [], :block => do def onion [compact_roll?, verbose_roll?, literal_roll?].compact.first.as(Unions::SingleRoll) end macro method_missing(call) {% if call.args.size >= 1 %} onion.{{ call.name }}({{ call.args }}) {% else %} onion.{{ call.name }}() {% end %} end end}, "positive_roll_separator" => {:super => ["Unions::RollSeparator"]}, "negative_roll_separator" => {:super => ["Unions::RollSeparator"]}, "roll_separator" => {:super => [], :block => do def onion [positive_roll_separator?, negative_roll_separator?].compact.first.as(Unions::RollSeparator) end macro method_missing(call) {% if call.args.size >= 1 %} onion.{{ call.name }}({{ call.args }}) {% else %} onion.{{ call.name }}() {% end %} end end}, "many_rolls" => {:super => [], :block => do def positive_values single_rolls.map_with_index do |roll, index| {roll: roll, index: index} end.select do |entry| (entry[:index] == 0) || (roll_separators[entry[:index] - 1].positive_roll_separator?) end.map do |entry| entry[:roll].values end.flatten end def negative_values single_rolls.map_with_index do |roll, index| {roll: roll, index: index} end.select do |entry| (entry[:index] != 0) && (roll_separators[entry[:index] - 1].negative_roll_separator?) end.map do |entry| entry[:roll].values end.flatten end def values positive_values + negative_values.map(&.*(-1)) end end}, "keep_modifier" => {:super => ["Unions::Modifier"]}, "remove_modifier" => {:super => ["Unions::Modifier"]}, "modifier" => {:super => [], :block => do def onion [keep_modifier?, remove_modifier?].compact.first.as(Unions::Modifier) end macro method_missing(call) {% if call.args.size >= 1 %} onion.{{ call.name }}({{ call.args }}) {% else %} onion.{{ call.name }}() {% end %} end end}, "random_strategy" => {:super => ["Unions::Strategy"]}, "best_strategy" => {:super => ["Unions::Strategy"]}, "worst_strategy" => {:super => ["Unions::Strategy"]}, "strategy" => {:super => [], :block => do def onion [random_strategy?, best_strategy?, worst_strategy?].compact.first.as(Unions::Strategy) end macro method_missing(call) {% if call.args.size >= 1 %} onion.{{ call.name }}({{ call.args }}) {% else %} onion.{{ call.name }}() {% end %} end end}, "literal_modified_rolls" => {:super => ["Unions::ModifiedRolls"]}, "compact_modified_rolls" => {:super => ["Unions::ModifiedRolls"]}, "modified_rolls" => {:super => [], :block => do def onion [literal_modified_rolls?, compact_modified_rolls?].compact.first.as(Unions::ModifiedRolls) end macro method_missing(call) {% if call.args.size >= 1 %} onion.{{ call.name }}({{ call.args }}) {% else %} onion.{{ call.name }}() {% end %} end end}, "rolls" => {:super => [], :block => do def values modified_rolls? ? modified_rolls.values : many_rolls.values end end}} of Symbol => Object
ROOT = {:value => "rolls"} of Symbol => Object
RULES = {"w" => do ((((str(" ")) | (str("\t"))) | (str("\r"))) | (str("\n"))).repeat(0) end, "number_digital" => do match(/\d+/) end, "one" => do (str("one")) | (str("One")) end, "two" => do (str("two")) | (str("Two")) end, "three" => do (str("three")) | (str("Three")) end, "four" => do (str("four")) | (str("Four")) end, "five" => do (str("five")) | (str("Five")) end, "six" => do (str("six")) | (str("Six")) end, "eight" => do (str("eight")) | (str("Eight")) end, "ten" => do (str("ten")) | (str("Ten")) end, "twelve" => do (str("twelve")) | (str("Twelve")) end, "fourteen" => do (str("fourteen")) | (str("Fourteen")) end, "sixteen" => do (str("sixteen")) | (str("Sixteen")) end, "eighteen" => do (str("eighteen")) | (str("Eighteen")) end, "twenty" => do (str("twenty")) | (str("Twenty")) end, "one_hundred" => do (str("one_hundred")) | (str("One_hundred")) end, "number_literal" => do (((((((((((one | two) | three) | four) | five) | six) | eight) | ten) | twelve) | fourteen) | sixteen) | eighteen) | twenty end, "number" => do number_literal | number_digital end, "fudge" => do ((str("fudge")) | (str("fate"))) | (str("f")) end, "percent" => do (str("%")) | (str("percentile")) end, "faced" => do (number >> w) >> (str("faced")).maybe end, "dice" => do (faced | percent) | fudge end, "compact_roll" => do (number_digital >> (str("d"))) >> dice end, "verbose_roll" => do (((number >> w) >> dice) >> w) >> ((str("dice")) >> (str("s")).maybe).maybe end, "literal_roll" => do number end, "single_roll" => do (compact_roll | verbose_roll) | literal_roll end, "positive_roll_separator" => do (((str("and")) | (str("plus"))) | (str(","))) | (str("+")) end, "negative_roll_separator" => do (str("minus")) | (str("-")) end, "roll_separator" => do positive_roll_separator | negative_roll_separator end, "many_rolls" => do single_roll >> ((((w >> roll_separator) >> w) >> single_roll).repeat(0)) end, "keep_modifier" => do ((((((str("keep")) | (str("select"))) | (str("pick"))) | (str("Keep"))) | (str("Select"))) | (str("Pick"))) | (str("k")) end, "remove_modifier" => do ((str("Remove")) | (str("remove"))) | (str("r")) end, "modifier" => do keep_modifier | remove_modifier end, "random_strategy" => do (str("random")) | (str("r")) end, "best_strategy" => do ((str("bests")) | (str("best"))) | (str("b")) end, "worst_strategy" => do ((str("worsts")) | (str("worst"))) | (str("w")) end, "strategy" => do (random_strategy | best_strategy) | worst_strategy end, "literal_modified_rolls" => do (((((((modifier >> w) >> number) >> w) >> strategy.maybe) >> w) >> (str("from"))) >> w) >> many_rolls end, "compact_modified_rolls" => do ((many_rolls >> modifier) >> number_digital) >> strategy.maybe end, "modified_rolls" => do literal_modified_rolls | compact_modified_rolls end, "rolls" => do ((modified_rolls | many_rolls) >> w) >> (str(".")).maybe end} of Object => Object

Class Method Summary

Macro Summary

Class Method Detail

def self.parse(input) #

Macro Detail

macro _finished #

[View source]
macro build_numbers(numbers) #

########## NUMBERS


[View source]
macro node(symbol, &block) #

[View source]
macro onion(symbol, children, &block) #

[View source]
macro root(symbol) #

[View source]
macro rule(symbol, &block) #

[View source]