Skip to content

Commit

Permalink
xLang markers
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Dec 5, 2019
1 parent 468eff2 commit f019616
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ export function InputHighlightRules() {
// regexps are ordered -> the first match is used
/*jshint -W015 */
this.$rules = {
'start-sql': [
{ token: 'whitespace', regex: '\\s+' },
{ token: 'paren.lparen', regex: '{', next: 'json-sql', push: true },
{ regex: '', next: 'start' }
],
'start': mergeTokens([
{ 'token': 'warning', 'regex': '#!.*$' },
{ token: 'comment', regex: /^#.*$/ },
Expand All @@ -71,7 +66,6 @@ export function InputHighlightRules() {
addEOL(['whitespace'], /(\s+)/, 'start', 'url')
),
'url': mergeTokens(
addEOL(['url.part'], /(_sql)/, 'start-sql', 'url-sql'),
addEOL(['url.part'], /([^?\/,\s]+)/, 'start'),
addEOL(['url.comma'], /(,)/, 'start'),
addEOL(['url.slash'], /(\/)/, 'start'),
Expand All @@ -82,16 +76,6 @@ export function InputHighlightRules() {
addEOL(['url.param'], /([^&=]+)/, 'start'),
addEOL(['url.amp'], /(&)/, 'start')
),
'url-sql': mergeTokens(
addEOL(['url.comma'], /(,)/, 'start-sql'),
addEOL(['url.slash'], /(\/)/, 'start-sql'),
addEOL(['url.questionmark'], /(\?)/, 'start-sql', 'urlParams-sql')
),
'urlParams-sql': mergeTokens(
addEOL(['url.param', 'url.equal', 'url.value'], /([^&=]+)(=)([^&]*)/, 'start-sql'),
addEOL(['url.param'], /([^&=]+)/, 'start-sql'),
addEOL(['url.amp'], /(&)/, 'start-sql')
),
};

addToRules(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,21 @@ const { ScriptHighlightRules } = require('./script_highlight_rules');
const jsonRules = function (root) {
root = root ? root : 'json';
const rules = {};
const xJsonRules = [
rules[root] = [
{
token: ['variable', 'whitespace', 'ace.punctuation.colon', 'whitespace', 'punctuation.start_triple_quote'],
regex: '("(?:[^"]*_)?script"|"inline"|"source")(\\s*?)(:)(\\s*?)(""")',
next: 'script-start',
merge: false,
push: true
},
{
token: 'punctuation.start_triple_quote',
regex: '"""sql',
next: 'sql-start',
merge: false,
push: true
},
{
token: 'variable', // single line
regex: '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]\\s*(?=:)'
Expand Down Expand Up @@ -110,15 +117,6 @@ const jsonRules = function (root) {
}
];

rules[root] = xJsonRules;
rules[root + '-sql'] = [{
token: ['variable', 'whitespace', 'ace.punctuation.colon', 'whitespace', 'punctuation.start_triple_quote'],
regex: '("query")(\\s*?)(:)(\\s*?)(""")',
next: 'sql-start',
merge: false,
push: true
}].concat(xJsonRules);

rules.string_literal = [
{
token: 'punctuation.end_triple_quote',
Expand Down
19 changes: 13 additions & 6 deletions src/legacy/core_plugins/console/public/quarantined/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,20 @@ utils.reformatData = function (data, indent) {
};
};

utils.collapseLiteralStrings = function (data) {
const splitData = data.split(`"""`);
for (let idx = 1; idx < splitData.length - 1; idx += 2) {
splitData[idx] = JSON.stringify(splitData[idx]);
// For now just a dumb removal of any """sql strings. Eventually we want some why to reverse
// this operation can probably bundle A -> B with the B -> A functionality.
const collapseXLangMarkers = text => text.replace(`"""sql`, `"""`);

utils.collapseLiteralStrings = _.pipe(
collapseXLangMarkers,
function (data) {
const splitData = data.split(`"""`);
for (let idx = 1; idx < splitData.length - 1; idx += 2) {
splitData[idx] = JSON.stringify(splitData[idx]);
}
return splitData.join('');
}
return splitData.join('');
};
);

/*
The following regex describes global match on:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"query": {
"__template": {
"__raw": true,
"value": "\"\"\"\nSELECT * FROM \"TABLE\"\n\"\"\""
"value": "\"\"\"sql\nSELECT * FROM \"TABLE\"\n\"\"\""
}
}
},
Expand All @@ -19,6 +19,6 @@
"smile"
]
},
"template": "_sql?format=json\n{\n \"query\": \"\"\"\n SELECT * FROM \"${1:TABLE}\"\n \"\"\"\n}\n"
"template": "_sql?format=json\n{\n \"query\": \"\"\"sql\n SELECT * FROM \"${1:TABLE}\"\n \"\"\"\n}\n"
}
}

0 comments on commit f019616

Please sign in to comment.