Skip to content

Commit

Permalink
[sql mode] Simplify patch 3e6aafd
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh authored and cone56 committed Jan 6, 2020
1 parent 39fbcd8 commit e6b2547
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions mode/sql/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ CodeMirror.defineMode("sql", function(config, parserConfig) {
&& (stream.peek() == "'" || (stream.peek() == '"' && support.doubleQuote))) {
// escape constant: E'str', e'str'
// ref: https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE
state.tokenize = tokenLiteral(stream.peek(), true);
state.tokenize = function(stream, state) {
return (state.tokenize = tokenLiteral(stream.next(), true))(stream, state);
}
return "keyword";
} else if (support.commentSlashSlash && ch == "/" && stream.eat("/")) {
// 1-line comment
Expand Down Expand Up @@ -128,19 +130,15 @@ CodeMirror.defineMode("sql", function(config, parserConfig) {
}

// 'string', with char specified in quote escaped by '\'
function tokenLiteral(quote, withEscapeConst) {
function tokenLiteral(quote, backslashEscapes) {
return function(stream, state) {
var escaped = false, ch;
/* eat the first quote in case of escape constant */
if(withEscapeConst) {
ch = stream.eat(quote)
}
while ((ch = stream.next()) != null) {
if (ch == quote && !escaped) {
state.tokenize = tokenBase;
break;
}
escaped = (backslashStringEscapes || withEscapeConst) && !escaped && ch == "\\";
escaped = (backslashStringEscapes || backslashEscapes) && !escaped && ch == "\\";
}
return "string";
};
Expand Down

0 comments on commit e6b2547

Please sign in to comment.