public string BaseToPrefix(NumberLiteralBase @base) { string prefix; if (baseToPrefix.TryGetValue(@base, out prefix)) { return(prefix); } else if (@base == defaultNumberLiteralBase) { return(string.Empty); } else { throw new UnparseException(string.Format("NumberLiteral error: no prefix for non-default base '{0}'", @base)); } }
public NumberLiteralInfo AddPrefix(string prefix, NumberLiteralBase @base) { if (NumberLiteral != null) { NumberLiteral.AddPrefix(prefix, NumberLiteralBaseToNumberOptions(@base)); } prefixToBase.Add(prefix, @base); // the same base can belong to different prefixes -> we store the first prefix into the baseToPrefix dictionary if (!baseToPrefix.ContainsKey(@base)) { baseToPrefix.Add(@base, prefix); } ClearSortedPrefixesByDescLength(); return(this); }
private static NumberOptions NumberLiteralBaseToNumberOptions(NumberLiteralBase @base) { switch (@base) { case NumberLiteralBase.Decimal: return(NumberOptions.Default); case NumberLiteralBase.Hexadecimal: return(NumberOptions.Hex); case NumberLiteralBase.Octal: return(NumberOptions.Octal); case NumberLiteralBase.Binary: return(NumberOptions.Binary); default: throw new ArgumentException("Unknown numberLiteralBase: " + @base, "@base"); } }
public static BnfiTermConversion <TNumberLiteral> IntroNumberLiteral <TNumberLiteral>(NumberLiteral numberLiteral, NumberLiteralInfo numberLiteralInfo) where TNumberLiteral : INumberLiteral, new() { var _numberLiteral = Intro( numberLiteral, (context, parseNode) => { string tokenText = parseNode.FindTokenAndGetText(); bool hasExplicitTypeModifier = numberLiteralInfo.HasTokenTextExplicitTypeSuffix(tokenText); NumberLiteralBase @base = numberLiteralInfo.GetBaseFromTokenText(tokenText); return(new TNumberLiteral() { Value = parseNode.FindToken().Value, HasExplicitTypeModifier = hasExplicitTypeModifier, Base = @base }); }, NoUnparseByInverse <TNumberLiteral>(), astForChild: false ); _numberLiteral.UtokenizerForUnparse = (formatProvider, reference, astValue) => numberLiteralInfo.NumberLiteralToText(reference, formatProvider); return(_numberLiteral.MarkLiteral()); }
public string BaseToPrefix(NumberLiteralBase @base) { string prefix; if (baseToPrefix.TryGetValue(@base, out prefix)) return prefix; else if (@base == defaultNumberLiteralBase) return string.Empty; else throw new UnparseException(string.Format("NumberLiteral error: no prefix for non-default base '{0}'", @base)); }
private static NumberOptions NumberLiteralBaseToNumberOptions(NumberLiteralBase @base) { switch (@base) { case NumberLiteralBase.Decimal: return NumberOptions.Default; case NumberLiteralBase.Hexadecimal: return NumberOptions.Hex; case NumberLiteralBase.Octal: return NumberOptions.Octal; case NumberLiteralBase.Binary: return NumberOptions.Binary; default: throw new ArgumentException("Unknown numberLiteralBase: " + @base, "@base"); } }
public NumberLiteralInfo AddPrefix(string prefix, NumberLiteralBase @base) { if (NumberLiteral != null) NumberLiteral.AddPrefix(prefix, NumberLiteralBaseToNumberOptions(@base)); prefixToBase.Add(prefix, @base); // the same base can belong to different prefixes -> we store the first prefix into the baseToPrefix dictionary if (!baseToPrefix.ContainsKey(@base)) baseToPrefix.Add(@base, prefix); ClearSortedPrefixesByDescLength(); return this; }