Use skylark-preferred quote char for string literal
We currently have no need to discern between strings quoted with ' or ". While it could be
nice for something one day (and may have been in the past), it's yagni now. Removing the
distinction simplifies string concatenation.
--
PiperOrigin-RevId: 148273400
MOS_MIGRATED_REVID=148273400
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java b/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java
index b5cbc92..5135dd3 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java
@@ -840,16 +840,6 @@
}
/**
- * Returns the character in the input buffer at the given position.
- *
- * @param at the position to get the character at.
- * @return the character at the given position.
- */
- public char charAt(int at) {
- return buffer[at];
- }
-
- /**
* Returns the string at the current line, minus the new line.
*
* @param line the line from which to retrieve the String, 1-based
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
index e499907..fd97117 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
@@ -606,9 +606,8 @@
private StringLiteral parseStringLiteral() {
Preconditions.checkState(token.kind == TokenKind.STRING);
int end = token.right;
- char quoteChar = lexer.charAt(token.left);
StringLiteral literal =
- setLocation(new StringLiteral((String) token.value, quoteChar), token.left, end);
+ setLocation(new StringLiteral((String) token.value), token.left, end);
nextToken();
if (token.kind == TokenKind.STRING) {
@@ -957,9 +956,7 @@
if (expr instanceof StringLiteral && secondary instanceof StringLiteral) {
StringLiteral left = (StringLiteral) expr;
StringLiteral right = (StringLiteral) secondary;
- if (left.getQuoteChar() == right.getQuoteChar()) {
- return new StringLiteral(left.getValue() + right.getValue(), left.getQuoteChar());
- }
+ return new StringLiteral(left.getValue() + right.getValue());
}
}
return new BinaryOperatorExpression(operator, expr, secondary);
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/StringLiteral.java b/src/main/java/com/google/devtools/build/lib/syntax/StringLiteral.java
index b2526a0..640d007 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/StringLiteral.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/StringLiteral.java
@@ -18,16 +18,13 @@
*/
public final class StringLiteral extends Literal<String> {
- private final char quoteChar;
-
- public StringLiteral(String value, char quoteChar) {
+ public StringLiteral(String value) {
super(value);
- this.quoteChar = quoteChar;
}
@Override
public String toString() {
- return quoteChar + value.replace(Character.toString(quoteChar), "\\" + quoteChar) + quoteChar;
+ return Printer.repr(value);
}
@Override
@@ -35,16 +32,6 @@
visitor.visit(this);
}
- /**
- * Gets the quote character that was used for this string. For example, if
- * the string was 'hello, world!', then this method returns '\''.
- *
- * @return the character used to quote the string.
- */
- public char getQuoteChar() {
- return quoteChar;
- }
-
@Override
void validate(ValidationEnvironment env) throws EvalException {
}