Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser cleanup and preparation for improved testing setup #3027

Merged
merged 6 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion desktop/core/src/desktop/js/parse/hplsqlStatementsParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,4 +786,5 @@ function Parser () {
}
Parser.prototype = parser;parser.Parser = Parser;
return new Parser;
})();export default hplsqlStatementsParser;
})();
export default hplsqlStatementsParser;
179 changes: 179 additions & 0 deletions desktop/core/src/desktop/js/parse/jison/globalSearchParser.jison
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
// Licensed to Cloudera, Inc. under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Cloudera, Inc. licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

%lex
%x singleQuote doubleQuote
%%

\s+ { return 'WS' }

'\u2020' { parser.yy.cursorFound = yylloc; return 'CURSOR'; }

[a-zA-Z]+[:] { return 'FACET' }

\' { this.begin('singleQuote'); return 'QUOTE'; }

<singleQuote>(?:\\[']|[^'])+ {
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '\'')) {
return 'PARTIAL_VALUE';
}
return 'VALUE';
}

<singleQuote>\' { this.popState(); return 'QUOTE'; }

\" { this.begin('doubleQuote'); return 'QUOTE'; }

<doubleQuote>(?:\\["]|[^"])+ {
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '"')) {
return 'PARTIAL_VALUE';
}
return 'VALUE';
}

<doubleQuote>\" { this.popState(); return 'QUOTE'; }

[^"'\s\u2020]+ { return 'TEXT'; }

<<EOF>> { return 'EOF'; }

/lex

%start GlobalSearchAutocomplete

%%

GlobalSearchAutocomplete
: OptionalWhitespace SearchParts OptionalWhitespace 'EOF'
{
return $2;
}
| OptionalWhitespace SearchParts_EDIT 'EOF'
{
if (!$2.facets) {
$2.facets = {};
}
if (!$2.text) {
$2.text = [];
}
return $2;
}
| OptionalWhitespace 'EOF'
{
return { facets: {}, text: [] };
}
;

SearchParts
: SearchPart
| SearchParts WS SearchPart
{
parser.mergeFacets($1, $3);
parser.mergeText($1, $3);
}
;

SearchParts_EDIT
: SearchPart_EDIT
| SearchParts WS SearchPart_EDIT
{
parser.mergeFacets($1, $3);
parser.mergeText($1, $3);
$$ = $3;
$$.text = $1.text;
$$.facets = $1.facets;
}
| SearchPart_EDIT WS SearchParts
{
$$ = $1;
parser.mergeFacets($$, $3);
parser.mergeText($$, $3);
}
| SearchParts WS SearchPart_EDIT WS SearchParts
{
parser.mergeFacets($1, $3);
parser.mergeFacets($1, $5);
parser.mergeText($1, $3);
parser.mergeText($1, $5);
$$ = $3;
$$.text = $1.text;
$$.facets = $1.facets;
}
;

SearchPart
: Facet --> { text: [], facets: $1.facets }
| FreeText --> { text: [$1], facets: {} }
;

SearchPart_EDIT
: Facet_EDIT
| FreeText_EDIT
;

Facet
: 'FACET' OptionalWhitespace FreeText
{
var facet = {};
var facetName = $1.substring(0, $1.length - 1).toLowerCase();
facet[facetName] = {};
facet[facetName][$3.toLowerCase()] = true;
$$ = { facets: facet };
}
;

Facet_EDIT
: 'FACET' OptionalWhitespace 'CURSOR' --> { suggestFacetValues: $1.substring(0, $1.length - 1).toLowerCase() }
| 'FACET' OptionalWhitespace FreeText 'CURSOR'
{
var facet = {};
var facetName = $1.substring(0, $1.length - 1).toLowerCase();
facet[facetName] = {};
facet[facetName][$3.toLowerCase()] = true;
$$ = { suggestFacetValues: facetName, facets: facet }
}
;

FreeText
: 'TEXT'
| QuotedValue
;

FreeText_EDIT
: 'CURSOR' --> { suggestFacets: true, suggestResults: true }
| 'CURSOR' 'TEXT' --> { suggestFacets: true, suggestResults: true, text: [$2] }
| 'TEXT' 'CURSOR' 'TEXT' --> { suggestFacets: true, suggestResults: true, text: [$1+$3] }
| 'TEXT' 'CURSOR' --> { suggestFacets: true, suggestResults: true, text: [$1] }
| QuotedValue_EDIT
;

QuotedValue
: 'QUOTE' 'VALUE' 'QUOTE' --> $2
| 'QUOTE' 'QUOTE' --> ''
;

QuotedValue_EDIT
: 'QUOTE' 'PARTIAL_VALUE' --> $2
;

OptionalWhitespace
:
| WS
;

%%

SqlParseSupport.initGlobalSearchParser(parser);
Loading