public override IDensity <FieldType <int, PType>, int, PType> VisitVariable(DensityExpressionGrammarParser.VariableContext ctx)
        {
            var variableStr = ctx.VARIABLE().GetText();

            if (_variableMatch.IsMatch(variableStr))
            {
                var match     = _variableMatch.Match(variableStr);
                var matchDict = Enumerable.Range(0, match.Groups.Count)
                                .Where(i => !match.Groups[i].Name.All(char.IsDigit))
                                .ToDictionary(
                    i => match.Groups[i].Name,
                    i => match.Groups[i].Value);

                var hasPrefixNum = !string.IsNullOrEmpty(matchDict["prefixNumMatch"]);
                var prefixNum    = matchDict["prefixNum"];
                var nPrefixNum   = matchDict["nPrefixNum"];
                var prefix       = matchDict["prefix"];
                var baseType     = matchDict["baseType"];
                var nStr         = matchDict["n"];
                var postfix      = matchDict["postfix"];

                var hasPrefix  = hasPrefixNum || !string.IsNullOrEmpty(prefix);
                var hasPostFix = !string.IsNullOrEmpty(postfix);
                if (hasPostFix)
                {
                    throw new NotImplementedException();
                }
                if (baseType != "d")
                {
                    throw new NotImplementedException();
                }
                var n           = int.Parse(nStr);
                var baseDensity = new Die(n);
                if (hasPrefix)
                {
                    var prefixType = hasPrefixNum ? prefixNum : prefix;
                    var nPrefix    = hasPrefixNum ? int.Parse(nPrefixNum) : 1;
                    if (prefixType == "a")
                    {
                        return(baseDensity.WithAdvantage(nPrefix));
                    }
                    if (prefixType == "d")
                    {
                        return(baseDensity.WithDisadvantage(nPrefix));
                    }
                    throw new NotImplementedException();
                }
                else
                {
                    return(baseDensity);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Exemple #2
0
 abstract public IDensity <G, M, RF> VisitVariable(DensityExpressionGrammarParser.VariableContext ctx);
Exemple #3
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="DensityExpressionGrammarParser.variable"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitVariable([NotNull] DensityExpressionGrammarParser.VariableContext context)
 {
 }