From d0e425cf35d94320e8273e989e25b1f0e4ebaf2f Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sun, 27 Apr 2014 21:52:52 -0500 Subject: [PATCH] Fix string.Format syntax (fixes #40) --- .../Antlr4.Runtime/Atn/ATNDeserializer.cs | 8 +++---- .../Antlr4.Runtime/Atn/ATNSerializer.cs | 6 ++--- .../Antlr4.Runtime/Atn/LexerChannelAction.cs | 2 +- .../Antlr4.Runtime/Atn/LexerModeAction.cs | 2 +- .../Antlr4.Runtime/Atn/LexerPushModeAction.cs | 2 +- .../Antlr4.Runtime/Atn/LexerTypeAction.cs | 2 +- .../Misc/RuleDependencyProcessor.cs | 24 +++++++++---------- .../Antlr4.Runtime/ParserInterpreter.cs | 2 +- .../Tree/Pattern/ParseTreeMatch.cs | 2 +- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs b/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs index 2cf15eceb..3f1aad59a 100644 --- a/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs +++ b/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs @@ -151,14 +151,14 @@ namespace Antlr4.Runtime.Atn int version = ToInt(data[p++]); if (version != SerializedVersion) { - string reason = string.Format(CultureInfo.CurrentCulture, "Could not deserialize ATN with version %d (expected %d).", version, SerializedVersion); + string reason = string.Format(CultureInfo.CurrentCulture, "Could not deserialize ATN with version {0} (expected {1}).", version, SerializedVersion); throw new NotSupportedException(reason); } Guid uuid = ToUUID(data, p); p += 8; if (!SupportedUuids.Contains(uuid)) { - string reason = string.Format(CultureInfo.CurrentCulture, "Could not deserialize ATN with UUID %s (expected %s or a legacy UUID).", uuid, SerializedUuid); + string reason = string.Format(CultureInfo.CurrentCulture, "Could not deserialize ATN with UUID {0} (expected {1} or a legacy UUID).", uuid, SerializedUuid); throw new NotSupportedException(reason); } bool supportsLexerActions = IsFeatureSupported(AddedLexerActions, uuid); @@ -1263,7 +1263,7 @@ nextState_break: ; default: { - string message = string.Format(CultureInfo.CurrentCulture, "The specified state type %d is not valid.", type); + string message = string.Format(CultureInfo.CurrentCulture, "The specified state type {0} is not valid.", type); throw new ArgumentException(message); } } @@ -1317,7 +1317,7 @@ nextState_break: ; default: { - string message = string.Format(CultureInfo.CurrentCulture, "The specified lexer action type %d is not valid.", type); + string message = string.Format(CultureInfo.CurrentCulture, "The specified lexer action type {0} is not valid.", type); throw new ArgumentException(message); } } diff --git a/runtime/CSharp/Antlr4.Runtime/Atn/ATNSerializer.cs b/runtime/CSharp/Antlr4.Runtime/Atn/ATNSerializer.cs index 27d218b71..3a9e91926 100644 --- a/runtime/CSharp/Antlr4.Runtime/Atn/ATNSerializer.cs +++ b/runtime/CSharp/Antlr4.Runtime/Atn/ATNSerializer.cs @@ -445,7 +445,7 @@ namespace Antlr4.Runtime.Atn default: { - string message = string.Format(CultureInfo.CurrentCulture, "The specified lexer action type %s is not valid.", action.GetActionType()); + string message = string.Format(CultureInfo.CurrentCulture, "The specified lexer action type {0} is not valid.", action.GetActionType()); throw new ArgumentException(message); } } @@ -477,14 +477,14 @@ namespace Antlr4.Runtime.Atn int version = ATNDeserializer.ToInt(data[p++]); if (version != ATNDeserializer.SerializedVersion) { - string reason = string.Format("Could not deserialize ATN with version %d (expected %d).", version, ATNDeserializer.SerializedVersion); + string reason = string.Format("Could not deserialize ATN with version {0} (expected {1}).", version, ATNDeserializer.SerializedVersion); throw new NotSupportedException(new InvalidClassException(typeof(ATN).FullName, reason)); } UUID uuid = ATNDeserializer.ToUUID(data, p); p += 8; if (!uuid.Equals(ATNDeserializer.SerializedUuid)) { - string reason = string.Format(CultureInfo.CurrentCulture, "Could not deserialize ATN with UUID %s (expected %s).", uuid, ATNDeserializer.SerializedUuid); + string reason = string.Format(CultureInfo.CurrentCulture, "Could not deserialize ATN with UUID {0} (expected {1}).", uuid, ATNDeserializer.SerializedUuid); throw new NotSupportedException(new InvalidClassException(typeof(ATN).FullName, reason)); } p++; diff --git a/runtime/CSharp/Antlr4.Runtime/Atn/LexerChannelAction.cs b/runtime/CSharp/Antlr4.Runtime/Atn/LexerChannelAction.cs index 3210f1200..c31788116 100644 --- a/runtime/CSharp/Antlr4.Runtime/Atn/LexerChannelAction.cs +++ b/runtime/CSharp/Antlr4.Runtime/Atn/LexerChannelAction.cs @@ -139,7 +139,7 @@ namespace Antlr4.Runtime.Atn public override string ToString() { - return string.Format("channel(%d)", channel); + return string.Format("channel({0})", channel); } } } diff --git a/runtime/CSharp/Antlr4.Runtime/Atn/LexerModeAction.cs b/runtime/CSharp/Antlr4.Runtime/Atn/LexerModeAction.cs index ba4afbcdb..05a3a3379 100644 --- a/runtime/CSharp/Antlr4.Runtime/Atn/LexerModeAction.cs +++ b/runtime/CSharp/Antlr4.Runtime/Atn/LexerModeAction.cs @@ -137,7 +137,7 @@ namespace Antlr4.Runtime.Atn public override string ToString() { - return string.Format("mode(%d)", mode); + return string.Format("mode({0})", mode); } } } diff --git a/runtime/CSharp/Antlr4.Runtime/Atn/LexerPushModeAction.cs b/runtime/CSharp/Antlr4.Runtime/Atn/LexerPushModeAction.cs index b0abe71c1..07997b7e6 100644 --- a/runtime/CSharp/Antlr4.Runtime/Atn/LexerPushModeAction.cs +++ b/runtime/CSharp/Antlr4.Runtime/Atn/LexerPushModeAction.cs @@ -136,7 +136,7 @@ namespace Antlr4.Runtime.Atn public override string ToString() { - return string.Format("pushMode(%d)", mode); + return string.Format("pushMode({0})", mode); } } } diff --git a/runtime/CSharp/Antlr4.Runtime/Atn/LexerTypeAction.cs b/runtime/CSharp/Antlr4.Runtime/Atn/LexerTypeAction.cs index d05d9d55c..6d7a59103 100644 --- a/runtime/CSharp/Antlr4.Runtime/Atn/LexerTypeAction.cs +++ b/runtime/CSharp/Antlr4.Runtime/Atn/LexerTypeAction.cs @@ -132,7 +132,7 @@ namespace Antlr4.Runtime.Atn public override string ToString() { - return string.Format("type(%d)", type); + return string.Format("type({0})", type); } } } diff --git a/runtime/CSharp/Antlr4.Runtime/Misc/RuleDependencyProcessor.cs b/runtime/CSharp/Antlr4.Runtime/Misc/RuleDependencyProcessor.cs index 5b8a1a92c..64c9c17ea 100644 --- a/runtime/CSharp/Antlr4.Runtime/Misc/RuleDependencyProcessor.cs +++ b/runtime/CSharp/Antlr4.Runtime/Misc/RuleDependencyProcessor.cs @@ -80,7 +80,7 @@ namespace Antlr4.Runtime.Misc } foreach (KeyValuePair>> entry in recognizerDependencies.EntrySet()) { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Note, string.Format("ANTLR 4: Validating %d dependencies on rules in %s.", entry.Value.Count, entry.Key.ToString())); + processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Note, string.Format("ANTLR 4: Validating {0} dependencies on rules in {1}.", entry.Value.Count, entry.Key.ToString())); CheckDependencies(entry.Value, entry.Key); } return true; @@ -100,7 +100,7 @@ namespace Antlr4.Runtime.Misc Args.NotNull("clazz", clazz); if (!className.Equals(clazz.GetCanonicalName())) { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, string.Format("Unable to process rule dependencies due to class name mismatch: %s != %s", className, clazz.GetCanonicalName())); + processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, string.Format("Unable to process rule dependencies due to class name mismatch: {0} != {1}", className, clazz.GetCanonicalName())); return false; } return true; @@ -111,7 +111,7 @@ namespace Antlr4.Runtime.Misc try { dependency.Recognizer(); - string message = string.Format("Expected %s to get the %s.", typeof(MirroredTypeException).Name, typeof(ITypeMirror).Name); + string message = string.Format("Expected {0} to get the {1}.", typeof(MirroredTypeException).Name, typeof(ITypeMirror).Name); throw new NotSupportedException(message); } catch (MirroredTypeException ex) @@ -138,7 +138,7 @@ namespace Antlr4.Runtime.Misc if (effectiveRule < 0 || effectiveRule >= ruleVersions.Length) { Tuple ruleReferenceElement = FindRuleDependencyProperty(dependency, RuleDependencyProcessor.RuleDependencyProperty.Rule); - string message = string.Format("Rule dependency on unknown rule %d@%d in %s", dependency.Item1.Rule(), dependency.Item1.Version(), GetRecognizerType(dependency.Item1).ToString()); + string message = string.Format("Rule dependency on unknown rule {0}@{1} in {2}", dependency.Item1.Rule(), dependency.Item1.Version(), GetRecognizerType(dependency.Item1).ToString()); if (ruleReferenceElement != null) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency.Item2, ruleReferenceElement.Item1, ruleReferenceElement.Item2); @@ -213,7 +213,7 @@ namespace Antlr4.Runtime.Misc if (declaredVersion > highestRequiredDependency) { Tuple versionElement = FindRuleDependencyProperty(dependency, RuleDependencyProcessor.RuleDependencyProperty.Version); - string message = string.Format("Rule dependency version mismatch: %s has maximum dependency version %d (expected %d) in %s", ruleNames[dependency.Item1.Rule()], highestRequiredDependency, declaredVersion, GetRecognizerType(dependency.Item1).ToString()); + string message = string.Format("Rule dependency version mismatch: {0} has maximum dependency version {1} (expected {2}) in {3}", ruleNames[dependency.Item1.Rule()], highestRequiredDependency, declaredVersion, GetRecognizerType(dependency.Item1).ToString()); if (versionElement != null) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency.Item2, versionElement.Item1, versionElement.Item2); @@ -226,7 +226,7 @@ namespace Antlr4.Runtime.Misc } catch (AnnotationTypeMismatchException) { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, string.Format("Could not validate rule dependencies for element %s", dependency.Item2.ToString()), dependency.Item2); + processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, string.Format("Could not validate rule dependencies for element {0}", dependency.Item2.ToString()), dependency.Item2); } } } @@ -244,7 +244,7 @@ namespace Antlr4.Runtime.Misc { dependentsElement = FindRuleDependencyProperty(dependency, RuleDependencyProcessor.RuleDependencyProperty.Rule); } - string message = string.Format("Cannot validate the following dependents of rule %d: %s", dependency.Item1.Rule(), unimplemented); + string message = string.Format("Cannot validate the following dependents of rule {0}: {1}", dependency.Item1.Rule(), unimplemented); if (dependentsElement != null) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, message, dependency.Item2, dependentsElement.Item1, dependentsElement.Item2); @@ -267,14 +267,14 @@ namespace Antlr4.Runtime.Misc else { string mismatchedRuleName = ruleNames[relatedRule]; - path = string.Format("rule %s (%s of %s)", mismatchedRuleName, relation, ruleName); + path = string.Format("rule {0} ({1} of {2})", mismatchedRuleName, relation, ruleName); } int declaredVersion = dependency.Item1.Version(); int actualVersion = ruleVersions[relatedRule]; if (actualVersion > declaredVersion) { Tuple versionElement = FindRuleDependencyProperty(dependency, RuleDependencyProcessor.RuleDependencyProperty.Version); - string message = string.Format("Rule dependency version mismatch: %s has version %d (expected <= %d) in %s", path, actualVersion, declaredVersion, GetRecognizerType(dependency.Item1).ToString()); + string message = string.Format("Rule dependency version mismatch: {0} has version {1} (expected <= {2}) in {3}", path, actualVersion, declaredVersion, GetRecognizerType(dependency.Item1).ToString()); if (versionElement != null) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency.Item2, versionElement.Item1, versionElement.Item2); @@ -314,7 +314,7 @@ namespace Antlr4.Runtime.Misc int index = (int)constantValue; if (index < 0 || index >= versions.Length) { - string message = string.Format("Rule index %d for rule '%s' out of bounds for recognizer %s.", index, name, recognizerClass.ToString()); + string message = string.Format("Rule index {0} for rule '{1}' out of bounds for recognizer {2}.", index, name, recognizerClass.ToString()); processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, element); continue; } @@ -326,7 +326,7 @@ namespace Antlr4.Runtime.Misc IExecutableElement ruleMethod = GetRuleMethod(recognizerClass, name); if (ruleMethod == null) { - string message = string.Format("Could not find rule method for rule '%s' in recognizer %s.", name, recognizerClass.ToString()); + string message = string.Format("Could not find rule method for rule '{0}' in recognizer {1}.", name, recognizerClass.ToString()); processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, element); continue; } @@ -507,7 +507,7 @@ namespace Antlr4.Runtime.Misc } else { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, string.Format("Unexpected annotation property %s.", value.Key.ToString()), dependency.Item2, annotationMirror, value.Value); + processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, string.Format("Unexpected annotation property {0}.", value.Key.ToString()), dependency.Item2, annotationMirror, value.Value); } } } diff --git a/runtime/CSharp/Antlr4.Runtime/ParserInterpreter.cs b/runtime/CSharp/Antlr4.Runtime/ParserInterpreter.cs index 9d27180f8..dfeb1b6d1 100644 --- a/runtime/CSharp/Antlr4.Runtime/ParserInterpreter.cs +++ b/runtime/CSharp/Antlr4.Runtime/ParserInterpreter.cs @@ -277,7 +277,7 @@ namespace Antlr4.Runtime { if (!Precpred(_ctx, ((PrecedencePredicateTransition)transition).precedence)) { - throw new FailedPredicateException(this, string.Format("precpred(_ctx, %d)", ((PrecedencePredicateTransition)transition).precedence)); + throw new FailedPredicateException(this, string.Format("precpred(_ctx, {0})", ((PrecedencePredicateTransition)transition).precedence)); } break; } diff --git a/runtime/CSharp/Antlr4.Runtime/Tree/Pattern/ParseTreeMatch.cs b/runtime/CSharp/Antlr4.Runtime/Tree/Pattern/ParseTreeMatch.cs index bd6eef790..ee96f704a 100644 --- a/runtime/CSharp/Antlr4.Runtime/Tree/Pattern/ParseTreeMatch.cs +++ b/runtime/CSharp/Antlr4.Runtime/Tree/Pattern/ParseTreeMatch.cs @@ -298,7 +298,7 @@ namespace Antlr4.Runtime.Tree.Pattern /// public override string ToString() { - return string.Format("Match %s; found %d labels", Succeeded() ? "succeeded" : "failed", GetLabels().Count); + return string.Format("Match {0}; found {1} labels", Succeeded() ? "succeeded" : "failed", GetLabels().Count); } } }