فهرست منبع

HUE-4031 [editor] Fix for incorrect jison syntax error location

Johan Ahlen 8 سال پیش
والد
کامیت
5aaa25f

+ 15 - 2
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSyntaxParserSpec.js

@@ -56,11 +56,24 @@
       expect(result).toBeTruthy();
       expect(result.text).toEqual('SLELECT');
       expect(result.expected.length).toBeGreaterThan(0);
+      expect(result.loc.first_column).toEqual(0);
+      expect(result.loc.last_column).toEqual(7);
     });
 
-    it ('should find errors for "select * form ', function () {
-      var result = sqlSyntaxParser.parseSyntax('select * form ', '', 'hive', true);
+    it('should find errors for "alter tabel "', function() {
+      var result = sqlSyntaxParser.parseSyntax('alter tabel ', '');
       expect(result).toBeTruthy();
+      expect(result.text).toEqual('tabel');
+      expect(result.expected.length).toBeGreaterThan(0);
+      expect(result.loc.first_column).toEqual(6);
+      expect(result.loc.last_column).toEqual(11);
+    });
+
+    it ('should find errors for "select *  form ', function () {
+      var result = sqlSyntaxParser.parseSyntax('select *  form ', '');
+      expect(result).toBeTruthy();
+      expect(result.loc.first_column).toEqual(10);
+      expect(result.loc.last_column).toEqual(14);
     });
 
     it('should suggest expected words for "SLELECT "', function() {

+ 2 - 2
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlSyntaxParser.js

@@ -4589,7 +4589,7 @@ _handle_error:
                     text: lexer.match,
                     token: this.terminals_[symbol] || symbol,
                     line: lexer.yylineno,
-                    loc: yyloc,
+                    loc: lexer.yylloc,
                     expected: expected,
                     recoverable: (error_rule_depth !== false)
                 });
@@ -5977,4 +5977,4 @@ exports.main = function commonjsMain(args) {
 if (typeof module !== 'undefined' && require.main === module) {
   exports.main(process.argv.slice(1));
 }
-}
+}

+ 3 - 0
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -3589,6 +3589,9 @@
 
         self.aceSqlSyntaxWorker.onmessage = function(e) {
           if (e.data.syntaxError) {
+            if (hueDebug.showSyntaxParseResult) {
+              console.log(e.data.syntaxError);
+            }
             var token = self.editor.session.getTokenAt(e.data.syntaxError.loc.first_line - 1, e.data.syntaxError.loc.first_column);
             if (token && token.value && /`$/.test(token.value)) {
               // Ace getTokenAt() thinks the first ` is a token, column +1 will include the first and last.

+ 2 - 0
tools/jison/hue-jison.sh

@@ -44,6 +44,8 @@ cat syntax_header.jison sql_main.jison sql_valueExpression.jison  sql_alter.jiso
 
 echo "Creating SQL syntax parser..."
 jison sqlSyntaxParser.jison sql.jisonlex
+# Workaround for a parser bug where it reports the location of the previous token on error (pull-request submitted for jison)
+sed -i '' 's/loc: yyloc,/loc: lexer.yylloc,/' sqlSyntaxParser.js
 cat license.txt sqlSyntaxParser.js > ../sqlSyntaxParser.js
 rm sqlSyntaxParser.jison
 rm sqlSyntaxParser.js