Repository: cassandra Updated Branches: refs/heads/trunk f5b3962a7 -> 645fa06c0
cqlsh pg-style-strings broken patch by Robert Stupp; reviewed by Stefania for CASSANDRA-10484 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/87fa9be4 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/87fa9be4 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/87fa9be4 Branch: refs/heads/trunk Commit: 87fa9be46d0da30521c7d84673fca880aa17729c Parents: 4bdc7bd Author: Robert Stupp <sn...@snazy.de> Authored: Fri Oct 9 09:56:35 2015 +0200 Committer: Robert Stupp <sn...@snazy.de> Committed: Fri Oct 9 09:56:35 2015 +0200 ---------------------------------------------------------------------- CHANGES.txt | 1 + pylib/cqlshlib/cql3handling.py | 3 ++- pylib/cqlshlib/test/test_cql_parsing.py | 35 ++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/87fa9be4/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index d2510b6..4e64134 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 2.2.3 + * cqlsh pg-style-strings broken (CASSANDRA-10484) * Make Hadoop CF splits more polite to custom orderered partitioners (CASSANDRA-10400) Merged from 2.1: * Update internal python driver used by cqlsh (CASSANDRA-10161) http://git-wip-us.apache.org/repos/asf/cassandra/blob/87fa9be4/pylib/cqlshlib/cql3handling.py ---------------------------------------------------------------------- diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py index dcae173..40b7d6b 100644 --- a/pylib/cqlshlib/cql3handling.py +++ b/pylib/cqlshlib/cql3handling.py @@ -135,7 +135,7 @@ JUNK ::= /([ \t\r\f\v]+|(--|[/][/])[^\n\r]*([\n\r]|$)|[/][*].*?[*][/])/ ; <stringLiteral> ::= <quotedStringLiteral> | <pgStringLiteral> ; <quotedStringLiteral> ::= /'([^']|'')*'/ ; -<pgStringLiteral> ::= /\$\$.*\$\$/; +<pgStringLiteral> ::= /\$\$(?:(?!\$\$)|[^$])*\$\$/; <quotedName> ::= /"([^"]|"")*"/ ; <float> ::= /-?[0-9]+\.[0-9]+/ ; <uuid> ::= /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/ ; @@ -154,6 +154,7 @@ JUNK ::= /([ \t\r\f\v]+|(--|[/][/])[^\n\r]*([\n\r]|$)|[/][*].*?[*][/])/ ; | "false" ; +<unclosedPgString>::= /\$\$(?:(?!\$\$)|[^$])*/ ; <unclosedString> ::= /'([^']|'')*/ ; <unclosedName> ::= /"([^"]|"")*/ ; <unclosedComment> ::= /[/][*].*$/ ; http://git-wip-us.apache.org/repos/asf/cassandra/blob/87fa9be4/pylib/cqlshlib/test/test_cql_parsing.py ---------------------------------------------------------------------- diff --git a/pylib/cqlshlib/test/test_cql_parsing.py b/pylib/cqlshlib/test/test_cql_parsing.py index cb8e3a6..c011d94 100644 --- a/pylib/cqlshlib/test/test_cql_parsing.py +++ b/pylib/cqlshlib/test/test_cql_parsing.py @@ -31,6 +31,41 @@ class TestCqlParsing(TestCase): self.assertSequenceEqual(tokens_with_types(CqlRuleSet.lex("'eggs'")), [("'eggs'", 'quotedStringLiteral')]) + tokens = CqlRuleSet.lex("'spam\nspam\n\tsausage'") + tokens = CqlRuleSet.cql_massage_tokens(tokens) + self.assertEqual(tokens[0][0], "quotedStringLiteral") + + tokens = CqlRuleSet.lex("'spam\nspam\n") + tokens = CqlRuleSet.cql_massage_tokens(tokens) + self.assertEqual(tokens[0][0], "unclosedString") + + tokens = CqlRuleSet.lex("'foo bar' 'spam\nspam\n") + tokens = CqlRuleSet.cql_massage_tokens(tokens) + self.assertEqual(tokens[1][0], "unclosedString") + + def test_parse_pgstring_literals(self): + for n in ["$$eggs$$", "$$Sausage 1$$", "$$spam\nspam\n\tsausage$$", "$$$$"]: + self.assertSequenceEqual(tokens_with_types(CqlRuleSet.lex(n)), + [(n, 'pgStringLiteral')]) + self.assertSequenceEqual(tokens_with_types(CqlRuleSet.lex("$$eggs$$")), + [("$$eggs$$", 'pgStringLiteral')]) + + tokens = CqlRuleSet.lex("$$spam\nspam\n\tsausage$$") + tokens = CqlRuleSet.cql_massage_tokens(tokens) + # [('pgStringLiteral', '$$spam\nspam\n\tsausage$$', (0, 22))] + self.assertEqual(tokens[0][0], "pgStringLiteral") + + tokens = CqlRuleSet.lex("$$spam\nspam\n") + tokens = CqlRuleSet.cql_massage_tokens(tokens) + # [('unclosedPgString', '$$', (0, 2)), ('identifier', 'spam', (2, 6)), ('identifier', 'spam', (7, 11))] + self.assertEqual(tokens[0][0], "unclosedPgString") + + tokens = CqlRuleSet.lex("$$foo bar$$ $$spam\nspam\n") + tokens = CqlRuleSet.cql_massage_tokens(tokens) + # [('pgStringLiteral', '$$foo bar$$', (0, 11)), ('unclosedPgString', '$$', (12, 14)), ('identifier', 'spam', (14, 18)), ('identifier', 'spam', (19, 23))] + self.assertEqual(tokens[0][0], "pgStringLiteral") + self.assertEqual(tokens[1][0], "unclosedPgString") + def test_parse_numbers(self): for n in ['6', '398', '18018']: self.assertSequenceEqual(tokens_with_types(CqlRuleSet.lex(n)),