forked from jasder/antlr
Specify locale for all format operations (fixes #158)
This commit is contained in:
parent
2ffb12028a
commit
e0e6e0a94c
|
@ -34,6 +34,8 @@ import org.antlr.v4.runtime.atn.PredicateTransition;
|
|||
import org.antlr.v4.runtime.misc.NotNull;
|
||||
import org.antlr.v4.runtime.misc.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/** A semantic predicate failed during validation. Validation of predicates
|
||||
* occurs when normally parsing the alternative just like matching a token.
|
||||
* Disambiguating predicate evaluation occurs when we test a predicate during
|
||||
|
@ -84,6 +86,6 @@ public class FailedPredicateException extends RecognitionException {
|
|||
return message;
|
||||
}
|
||||
|
||||
return String.format("failed predicate: {%s}?", predicate);
|
||||
return String.format(Locale.getDefault(), "failed predicate: {%s}?", predicate);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ import org.antlr.v4.runtime.misc.NotNull;
|
|||
import org.antlr.v4.runtime.misc.Nullable;
|
||||
import org.antlr.v4.runtime.misc.Utils;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class LexerNoViableAltException extends RecognitionException {
|
||||
/** Matching attempted at what input index? */
|
||||
private final int startIndex;
|
||||
|
@ -75,6 +77,6 @@ public class LexerNoViableAltException extends RecognitionException {
|
|||
symbol = Utils.escapeWhitespace(symbol, false);
|
||||
}
|
||||
|
||||
return String.format("%s('%s')", LexerNoViableAltException.class.getSimpleName(), symbol);
|
||||
return String.format(Locale.getDefault(), "%s('%s')", LexerNoViableAltException.class.getSimpleName(), symbol);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ import java.io.InvalidClassException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public abstract class ATNSimulator {
|
||||
public static final int SERIALIZED_VERSION;
|
||||
|
@ -110,7 +111,7 @@ public abstract class ATNSimulator {
|
|||
int p = 0;
|
||||
int version = toInt(data[p++]);
|
||||
if (version != SERIALIZED_VERSION) {
|
||||
String reason = String.format("Could not deserialize ATN with version %d (expected %d).", version, SERIALIZED_VERSION);
|
||||
String reason = String.format(Locale.getDefault(), "Could not deserialize ATN with version %d (expected %d).", version, SERIALIZED_VERSION);
|
||||
throw new UnsupportedOperationException(new InvalidClassException(ATN.class.getName(), reason));
|
||||
}
|
||||
|
||||
|
@ -420,7 +421,7 @@ public abstract class ATNSimulator {
|
|||
case ATNState.PLUS_LOOP_BACK : s = new PlusLoopbackState(); break;
|
||||
case ATNState.LOOP_END : s = new LoopEndState(); break;
|
||||
default :
|
||||
String message = String.format("The specified state type %d is not valid.", type);
|
||||
String message = String.format(Locale.getDefault(), "The specified state type %d is not valid.", type);
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* The following images show the relation of states and
|
||||
|
@ -182,7 +183,7 @@ public abstract class ATNState {
|
|||
epsilonOnlyTransitions = e.isEpsilon();
|
||||
}
|
||||
else if (epsilonOnlyTransitions != e.isEpsilon()) {
|
||||
System.err.format("ATN state %d has both epsilon and non-epsilon transitions.\n", stateNumber);
|
||||
System.err.format(Locale.getDefault(), "ATN state %d has both epsilon and non-epsilon transitions.\n", stateNumber);
|
||||
epsilonOnlyTransitions = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.antlr.v4.runtime.misc.NotNull;
|
|||
import org.antlr.v4.runtime.misc.Nullable;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.util.Locale;
|
||||
|
||||
/** "dup" of ParserInterpreter */
|
||||
public class LexerATNSimulator extends ATNSimulator {
|
||||
|
@ -171,7 +172,7 @@ public class LexerATNSimulator extends ATNSimulator {
|
|||
ATNState startState = atn.modeToStartState.get(mode);
|
||||
|
||||
if ( debug ) {
|
||||
System.out.format("matchATN mode %d start: %s\n", mode, startState);
|
||||
System.out.format(Locale.getDefault(), "matchATN mode %d start: %s\n", mode, startState);
|
||||
}
|
||||
|
||||
int old_mode = mode;
|
||||
|
@ -188,7 +189,7 @@ public class LexerATNSimulator extends ATNSimulator {
|
|||
int predict = execATN(input, next);
|
||||
|
||||
if ( debug ) {
|
||||
System.out.format("DFA after matchATN: %s\n", decisionToDFA[old_mode].toLexerString());
|
||||
System.out.format(Locale.getDefault(), "DFA after matchATN: %s\n", decisionToDFA[old_mode].toLexerString());
|
||||
}
|
||||
|
||||
return predict;
|
||||
|
@ -197,7 +198,7 @@ public class LexerATNSimulator extends ATNSimulator {
|
|||
protected int execATN(@NotNull CharStream input, @NotNull DFAState ds0) {
|
||||
//System.out.println("enter exec index "+input.index()+" from "+ds0.configs);
|
||||
if ( debug ) {
|
||||
System.out.format("start state closure=%s\n", ds0.configs);
|
||||
System.out.format(Locale.getDefault(), "start state closure=%s\n", ds0.configs);
|
||||
}
|
||||
|
||||
int t = input.LA(1);
|
||||
|
@ -206,7 +207,7 @@ public class LexerATNSimulator extends ATNSimulator {
|
|||
|
||||
while ( true ) { // while more work
|
||||
if ( debug ) {
|
||||
System.out.format("execATN loop starting closure: %s\n", s.configs);
|
||||
System.out.format(Locale.getDefault(), "execATN loop starting closure: %s\n", s.configs);
|
||||
}
|
||||
|
||||
// As we move src->trg, src->trg, we keep track of the previous trg to
|
||||
|
@ -316,7 +317,7 @@ public class LexerATNSimulator extends ATNSimulator {
|
|||
}
|
||||
|
||||
if ( debug ) {
|
||||
System.out.format("testing %s at %s\n", getTokenName(t), c.toString(recog, true));
|
||||
System.out.format(Locale.getDefault(), "testing %s at %s\n", getTokenName(t), c.toString(recog, true));
|
||||
}
|
||||
|
||||
int n = c.state.getNumberOfTransitions();
|
||||
|
@ -339,7 +340,7 @@ public class LexerATNSimulator extends ATNSimulator {
|
|||
int index, int line, int charPos)
|
||||
{
|
||||
if ( debug ) {
|
||||
System.out.format("ACTION %s:%d\n", recog != null ? recog.getRuleNames()[ruleIndex] : ruleIndex, actionIndex);
|
||||
System.out.format(Locale.getDefault(), "ACTION %s:%d\n", recog != null ? recog.getRuleNames()[ruleIndex] : ruleIndex, actionIndex);
|
||||
}
|
||||
|
||||
if ( actionIndex>=0 && recog!=null ) recog.action(null, ruleIndex, actionIndex);
|
||||
|
@ -394,10 +395,10 @@ public class LexerATNSimulator extends ATNSimulator {
|
|||
if ( config.state instanceof RuleStopState ) {
|
||||
if ( debug ) {
|
||||
if ( recog!=null ) {
|
||||
System.out.format("closure at %s rule stop %s\n", recog.getRuleNames()[config.state.ruleIndex], config);
|
||||
System.out.format(Locale.getDefault(), "closure at %s rule stop %s\n", recog.getRuleNames()[config.state.ruleIndex], config);
|
||||
}
|
||||
else {
|
||||
System.out.format("closure at rule stop %s\n", config);
|
||||
System.out.format(Locale.getDefault(), "closure at rule stop %s\n", config);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ package org.antlr.v4.runtime.tree.gui;
|
|||
|
||||
import java.awt.Font;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostScriptDocument {
|
||||
|
@ -83,7 +84,7 @@ public class PostScriptDocument {
|
|||
public void boundingBox(int w, int h) {
|
||||
boundingBoxWidth = w;
|
||||
boundingBoxHeight = h;
|
||||
boundingBox = String.format("%%%%BoundingBox: %d %d %d %d\n", 0,0,
|
||||
boundingBox = String.format(Locale.US, "%%%%BoundingBox: %d %d %d %d\n", 0,0,
|
||||
boundingBoxWidth,boundingBoxHeight);
|
||||
}
|
||||
|
||||
|
@ -134,7 +135,7 @@ public class PostScriptDocument {
|
|||
psname = this.fontName;
|
||||
}
|
||||
|
||||
ps.append(String.format("/%s findfont %d scalefont setfont\n", psname, fontSize));
|
||||
ps.append(String.format(Locale.US, "/%s findfont %d scalefont setfont\n", psname, fontSize));
|
||||
}
|
||||
|
||||
public void lineWidth(double w) {
|
||||
|
@ -143,11 +144,11 @@ public class PostScriptDocument {
|
|||
}
|
||||
|
||||
public void move(double x, double y) {
|
||||
ps.append(String.format("%1.3f %1.3f moveto\n", x, y));
|
||||
ps.append(String.format(Locale.US, "%1.3f %1.3f moveto\n", x, y));
|
||||
}
|
||||
|
||||
public void lineto(double x, double y) {
|
||||
ps.append(String.format("%1.3f %1.3f lineto\n", x, y));
|
||||
ps.append(String.format(Locale.US, "%1.3f %1.3f lineto\n", x, y));
|
||||
}
|
||||
|
||||
public void line(double x1, double y1, double x2, double y2) {
|
||||
|
@ -164,7 +165,7 @@ public class PostScriptDocument {
|
|||
|
||||
/** Make red box */
|
||||
public void highlight(double x, double y, double width, double height) {
|
||||
ps.append(String.format("%1.3f %1.3f %1.3f %1.3f highlight\n", x, y, width, height));
|
||||
ps.append(String.format(Locale.US, "%1.3f %1.3f %1.3f %1.3f highlight\n", x, y, width, height));
|
||||
}
|
||||
|
||||
public void stroke() {
|
||||
|
@ -172,11 +173,11 @@ public class PostScriptDocument {
|
|||
}
|
||||
|
||||
// public void rarrow(double x, double y) {
|
||||
// ps.append(String.format("%1.3f %1.3f rarrow\n", x,y));
|
||||
// ps.append(String.format(Locale.US, "%1.3f %1.3f rarrow\n", x,y));
|
||||
// }
|
||||
//
|
||||
// public void darrow(double x, double y) {
|
||||
// ps.append(String.format("%1.3f %1.3f darrow\n", x,y));
|
||||
// ps.append(String.format(Locale.US, "%1.3f %1.3f darrow\n", x,y));
|
||||
// }
|
||||
|
||||
public void text(String s, double x, double y) {
|
||||
|
@ -197,7 +198,7 @@ public class PostScriptDocument {
|
|||
}
|
||||
s = buf.toString();
|
||||
move(x,y);
|
||||
ps.append(String.format("(%s) show\n", s));
|
||||
ps.append(String.format(Locale.US, "(%s) show\n", s));
|
||||
stroke();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue