aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google
diff options
context:
space:
mode:
authorGravatar Michajlo Matijkiw <michajlo@google.com>2017-02-22 23:02:46 +0000
committerGravatar Yue Gan <yueg@google.com>2017-02-23 11:31:11 +0000
commit8c539ea7fb1fd55c6e6902004fbdcd4081fa6a65 (patch)
tree3c74ca5ab3e992097f7d3a6a37c2206205b7af24 /src/main/java/com/google
parent19e126a1a7643e170ceec65a11f6a4d330ae1b3b (diff)
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
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/Lexer.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/Parser.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/StringLiteral.java17
3 files changed, 4 insertions, 30 deletions
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 b5cbc92aef..5135dd3573 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 @@ public final class Lexer {
}
/**
- * 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 e499907777..fd9711737a 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 @@ public class Parser {
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 @@ public class Parser {
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 b2526a0646..640d007454 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 @@ package com.google.devtools.build.lib.syntax;
*/
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 @@ public final class StringLiteral extends Literal<String> {
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 {
}