Skip to content

Commit

Permalink
Fix run: highlighting (#1363)
Browse files Browse the repository at this point in the history
* Fix `run:` highlighting

* Add a visual tester

* Add eslintignore

* eslintignore can't be nested apparently
  • Loading branch information
Chris Swenson authored Sep 28, 2023
1 parent badb59f commit 14ca96f
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build/
packages/malloy-malloy-sql/src/grammar
packages/malloy-malloy-sql/src/grammar
packages/malloy-syntax-highlight/**/*.monarch.ts
147 changes: 147 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions packages/malloy-syntax-highlight/grammars/malloy/malloy.monarch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import {languages as Monaco} from 'monaco-editor';

export const monarch: Monaco.IMonarchLanguage = {
'includeLF': true,
'defaultToken': '',
'tokenPostfix': '.malloy',
'ignoreCase': true,
'tokenizer': {
includeLF: true,
defaultToken: '',
tokenPostfix: '.malloy',
ignoreCase: true,
tokenizer: {
root: [{include: '@malloy_language'}],
malloy_language: [
{include: '@sql_string'},
Expand Down Expand Up @@ -91,8 +91,8 @@ export const monarch: Monaco.IMonarchLanguage = {
],
comment_block_end: [
[/\*\//, {next: '@pop', token: 'comment.block'}],
[/[^*]+/, 'comment.block'],
[/[*]/, 'comment.block'],
[/[^\*]+/, 'comment.block'],
[/[\*]/, 'comment.block'],
],
comment_line_double_slash_end: [
[/\n/, {next: '@pop', token: 'comment.line.double.slash'}],
Expand Down Expand Up @@ -145,7 +145,7 @@ export const monarch: Monaco.IMonarchLanguage = {
[/'/, {next: '@string_quoted_single_end', token: 'string.quoted'}],
[/"/, {next: '@string_quoted_double_end', token: 'string.quoted'}],
[/"""/, {next: '@string_quoted_triple_end', token: 'string.quoted'}],
[/[r|/]'/, {next: '@string_regexp_end', token: 'string.regexp'}],
[/[r|\/]'/, {next: '@string_regexp_end', token: 'string.regexp'}],
],
string_quoted_single_end: [
[/'/, {next: '@pop', token: 'string.quoted'}],
Expand Down Expand Up @@ -199,7 +199,7 @@ export const monarch: Monaco.IMonarchLanguage = {
[/\bsql\b/, 'keyword.control.sql'],
[/\bselect\b/, 'keyword.control.select'],
[/\bconnection\b/, 'keyword.control.connection'],
[/\brun\b/, 'keyword'],
[/\brun\b/, 'keyword.control.run'],
[/\bextend\b/, 'keyword.control.extend'],
[/\brefine\b/, 'keyword.control.refine'],
[/\baggregate\b/, 'keyword.control.aggregate'],
Expand All @@ -225,6 +225,7 @@ export const monarch: Monaco.IMonarchLanguage = {
[/\bquery\b/, 'keyword.control.query'],
[/\brename\b/, 'keyword.control.rename'],
[/\btop\b/, 'keyword.control.top'],
[/\bview\b/, 'keyword.control.view'],
[/\bwhere\b/, 'keyword.control.where'],
[/\bdeclare\b/, 'keyword.control.declare'],
],
Expand All @@ -245,7 +246,7 @@ export const monarch: Monaco.IMonarchLanguage = {
],
datetimes: [
[
/@[0-9]{4}-[0-9]{2}-[0-9]{2}[ T][0-9]{2}:[0-9]{2}((:[0-9]{2})(([.,][0-9]+)(\[[A-Za-z_/]+\])?)?)?/,
/@[0-9]{4}-[0-9]{2}-[0-9]{2}[ T][0-9]{2}:[0-9]{2}((:[0-9]{2})(([\.,][0-9]+)(\[[A-Za-z_\/]+\])?)?)?/,
'constant.numeric.timestamp',
],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@
},
{
"match": "(?i)\\brun\\b",
"name": "keyword"
"name": "keyword.control.run"
},
{
"match": "(?i)\\bextend\\b",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,8 @@ export default [
tokens: [
{
startIndex: 0,
type: ['source.malloy', 'keyword'],
color: '#569CD6',
type: ['source.malloy', 'keyword.control.run'],
color: '#C586C0',
},
{startIndex: 3, type: ['source.malloy'], color: '#000000'},
{
Expand Down
4 changes: 3 additions & 1 deletion packages/malloy-syntax-highlight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"gen-malloy-tokens": "ts-node scripts/generateLanguageTokenizationFile grammars/malloy/tokenizations/darkPlus.ts",
"test-monarch-grammars": "rimraf ./dist && tsc && karma start",
"test-textmate-grammars": "jest",
"gen-monaco-darkplus": "ts-node scripts/generateMonarchTheme themes/textmate/dark_plus.json themes/monaco/darkPlus.ts"
"gen-monaco-darkplus": "ts-node scripts/generateMonarchTheme themes/textmate/dark_plus.json themes/monaco/darkPlus.ts",
"serve-visual": "http-server test/visual -p 2222"
},
"license": "MIT",
"devDependencies": {
"@types/jasmine": "^4.3.5",
"http-server": "^14.1.1",
"jasmine-core": "^5.1.1",
"json5": "^2.2.3",
"karma": "^6.4.2",
Expand Down
76 changes: 76 additions & 0 deletions packages/malloy-syntax-highlight/test/visual/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<html>
<head>
<style>
body {
display: flex;
flex-direction: row;
}
.left {
width: 50%;
border: 1px solid #efefef;
margin: 10px;
border-radius: 10px;
overflow: hidden;
padding: 3px;
}
#input {
width: 100%;
height: 100%;
border: none;
resize: none;
}
#input:focus {
border: none;
outline: none;
}
.right {
padding: 3px;
width: 50%;
border: 1px solid #efefef;
margin: 10px;
border-radius: 10px;
}
pre {
white-space: pre-wrap;
margin: 0;
}
</style>
</head>
<body>
<div class="left"><textarea id="input">
source: flights is duckdb.table('flights.parquet') extend {
dimension: foo is 1
}
</textarea></div>
<div class="right"><div id="output"></div></div>
<script src="https://unpkg.com/shiki"></script>
<script>
fetch("./malloy.tmGrammar.json").then(response => {
const malloyGrammar = response.json();
const update = (el) => {
shiki
.getHighlighter({
theme: 'light-plus',
langs: [
"sql",
"json",
{
id: "malloy",
scopeName: "source.malloy",
embeddedLangs: ["sql"],
grammar: malloyGrammar,
},
],
})
.then(highlighter => {
const code = highlighter.codeToHtml(el.value, { lang: 'malloy' })
document.getElementById('output').innerHTML = code
})
}
const inp = document.getElementById("input");
inp.addEventListener('input', (ev) => update(ev.target));
update(inp);
});
</script>
</body>
</html>
Loading

0 comments on commit 14ca96f

Please sign in to comment.