Resynced to master

This commit is contained in:
Matthew Paletta 2020-07-04 21:34:28 -07:00
commit 6e3d900c96
5 changed files with 22 additions and 1 deletions

View File

@ -1,5 +1,9 @@
ANTLR Project Contributors Certification of Origin and Rights ANTLR Project Contributors Certification of Origin and Rights
NOTE: This tool is mature and Terence is mostly occupied elsewhere. We
can't accept any changes that could have widespread effects on thousands
of existing projects. Sorry!
All contributors to ANTLR v4 must formally agree to abide by this All contributors to ANTLR v4 must formally agree to abide by this
certificate of origin by signing on the bottom with their github certificate of origin by signing on the bottom with their github
userid, full name, email address (you can obscure your e-mail, but it userid, full name, email address (you can obscure your e-mail, but it
@ -245,3 +249,4 @@ YYYY/MM/DD, github id, Full name, email
2020/04/30, TristonianJones, Tristan Swadell, tswadell@google.com 2020/04/30, TristonianJones, Tristan Swadell, tswadell@google.com
2020/05/31, d-markey, David Markey, dmarkey@free.fr 2020/05/31, d-markey, David Markey, dmarkey@free.fr
2020/06/15, mattpaletta, Matthew Paletta, mattpaletta@gmail.com 2020/06/15, mattpaletta, Matthew Paletta, mattpaletta@gmail.com
2020/07/01, sha-N, Shan M Mathews, admin@bluestarqatar.com

View File

@ -10,4 +10,5 @@ module.exports.InputMismatchException = require('./Errors').InputMismatchExcepti
module.exports.FailedPredicateException = require('./Errors').FailedPredicateException; module.exports.FailedPredicateException = require('./Errors').FailedPredicateException;
module.exports.DiagnosticErrorListener = require('./DiagnosticErrorListener'); module.exports.DiagnosticErrorListener = require('./DiagnosticErrorListener');
module.exports.BailErrorStrategy = require('./ErrorStrategy').BailErrorStrategy; module.exports.BailErrorStrategy = require('./ErrorStrategy').BailErrorStrategy;
module.exports.DefaultErrorStrategy = require('./ErrorStrategy').DefaultErrorStrategy;
module.exports.ErrorListener = require('./ErrorListener').ErrorListener; module.exports.ErrorListener = require('./ErrorListener').ErrorListener;

View File

@ -20,4 +20,6 @@ var pc = require('./PredictionContext');
exports.PredictionContextCache = pc.PredictionContextCache; exports.PredictionContextCache = pc.PredictionContextCache;
exports.ParserRuleContext = require('./ParserRuleContext'); exports.ParserRuleContext = require('./ParserRuleContext');
exports.Interval = require('./IntervalSet').Interval; exports.Interval = require('./IntervalSet').Interval;
exports.IntervalSet = require('./IntervalSet').IntervalSet;
exports.Utils = require('./Utils'); exports.Utils = require('./Utils');
exports.LL1Analyzer = require('./LL1Analyzer').LL1Analyzer;

View File

@ -282,7 +282,7 @@ public abstract class Target {
return sb.toString(); return sb.toString();
} }
private static boolean shouldUseUnicodeEscapeForCodePointInDoubleQuotedString(int codePoint) { protected boolean shouldUseUnicodeEscapeForCodePointInDoubleQuotedString(int codePoint) {
// We don't want anyone passing 0x0A (newline) or 0x22 // We don't want anyone passing 0x0A (newline) or 0x22
// (double-quote) here because Java treats \\u000A as // (double-quote) here because Java treats \\u000A as
// a literal newline and \\u0022 as a literal // a literal newline and \\u0022 as a literal

View File

@ -47,6 +47,7 @@ public class CppTarget extends Target {
public CppTarget(CodeGenerator gen) { public CppTarget(CodeGenerator gen) {
super(gen, "Cpp"); super(gen, "Cpp");
targetCharValueEscape['?'] = "\\?";
} }
public String getVersion() { public String getVersion() {
@ -69,6 +70,18 @@ public class CppTarget extends Target {
badWords.add("parserRule"); badWords.add("parserRule");
} }
@Override
protected boolean shouldUseUnicodeEscapeForCodePointInDoubleQuotedString(int codePoint) {
if (codePoint == '?') {
// in addition to the default escaped code points, also escape ? to prevent trigraphs
// ideally, we would escape ? with \?, but escaping as unicode \u003F works as well
return true;
}
else {
return super.shouldUseUnicodeEscapeForCodePointInDoubleQuotedString(codePoint);
}
}
@Override @Override
public String encodeIntAsCharEscape(int v) { public String encodeIntAsCharEscape(int v) {
return "0x" + Integer.toHexString(v) + ", "; return "0x" + Integer.toHexString(v) + ", ";