Published
Edited
Jul 26, 2022
Importers
1 star
Insert cell
Insert cell
Insert cell
viewof e = {
return editor({
value: "x + 1 + 2*y",
options: {
gutter: true,
},
grammar: testGrammar,
on: {
beforeSelectionChange(marks) {
console.log("beforeSelectionChange", marks)
}
},
marks: {
endOfLine: {
_markText: true,
_bookmarkEnd: (existing, value, node) => ({insertLeft: true, widget: html`<span style="background: #fee5c1; border-radius: 2px; border: 2px rgba(0, 0, 0, 0.05) solid; color: #888; padding: 0 0.25em; margin-left: 1em; display: inline-block;">› ${node.sourceString}</span>`}),
Exp: true,
},
cursorNumber: {
number: {},
},
syntaxHighlighting: {
_markText: (doc, start, end, value, node) => doc.markText(start, end, value),
_terminal: {
"+": {className: 'cm-meta'},
},
number: {className: 'cm-number'},
ident: {className: 'cm-keyword'},
},
},
})

}
Insert cell
Insert cell
Insert cell
testGrammar = ohm.grammar(`
Arithmetic {
Exp
= AddExp*
AddExp
= AddExp "+" MulExp -- plus
| AddExp "-" MulExp -- minus
| MulExp
MulExp
= MulExp "*" ExpExp -- times
| MulExp "/" ExpExp -- divide
| ExpExp
ExpExp
= PriExp "^" ExpExp -- power
| PriExp
PriExp
= "(" Exp ")" -- paren
| "+" PriExp -- pos
| "-" PriExp -- neg
| ident
| number

ident (an identifier)
= letter alnum*
number (a number)
= digit* "." digit+ -- fract
| digit+ -- whole
}
`)
Insert cell
Insert cell
CodeMirror = {
const CodeMirror = await require('codemirror@5.46.0')
definePlaceholderOption(CodeMirror)
return CodeMirror
}
Insert cell
ohm = require("https://unpkg.com/ohm-js@15/dist/ohm.min.js")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more