This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as worker from 'monaco-editor-core/esm/vs/editor/editor.worker'; | |
import { TodoLangWorker } from './todoLangWorker'; | |
self.onmessage = () => { | |
worker.initialize((ctx) => { | |
return new TodoLangWorker(ctx) | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as monaco from "monaco-editor-core"; | |
import IWorkerContext = monaco.worker.IWorkerContext; | |
import TodoLangLanguageService from "../language-service/LanguageService"; | |
import { ITodoLangError } from "../language-service/TodoLangErrorListener"; | |
export class TodoLangWorker { | |
private _ctx: IWorkerContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TodoExpressionsContext } from "../ANTLR/TodoLangGrammarParser"; | |
import { parseAndGetASTRoot, parseAndGetSyntaxErrors } from "./Parser"; | |
import { ITodoLangError } from "./TodoLangErrorListener"; | |
export default class TodoLangLanguageService { | |
validate(code: string): ITodoLangError[] { | |
const syntaxErrors: ITodoLangError[] = parseAndGetSyntaxErrors(code); | |
//Later we will append semantic errors | |
return syntaxErrors; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TodoLangGrammarParser, TodoExpressionsContext } from "../ANTLR/TodoLangGrammarParser"; | |
import { TodoLangGrammarLexer } from "../ANTLR/TodoLangGrammarLexer"; | |
import { ANTLRInputStream, CommonTokenStream } from "antlr4ts"; | |
import TodoLangErrorListener, { ITodoLangError } from "./TodoLangErrorListener"; | |
function parse(code: string): {ast:TodoExpressionsContext, errors: ITodoLangError[]} { | |
const inputStream = new ANTLRInputStream(code); | |
const lexer = new TodoLangGrammarLexer(inputStream); | |
lexer.removeErrorListeners() | |
const todoLangErrorsListner = new TodoLangErrorListener(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ANTLRErrorListener, RecognitionException, Recognizer } from "antlr4ts"; | |
export interface ITodoLangError { | |
startLineNumber: number; | |
startColumn: number; | |
endLineNumber: number; | |
endColumn: number; | |
message: string; | |
code: string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TodoLangGrammarParser, TodoExpressionsContext } from "../ANTLR/TodoLangGrammarParser"; | |
import { TodoLangGrammarLexer } from "../ANTLR/TodoLangGrammarLexer"; | |
import { ANTLRInputStream, CommonTokenStream } from "antlr4ts"; | |
export default function parseAndGetASTRoot(code: string): TodoExpressionsContext { | |
const inputStream = new ANTLRInputStream(code); | |
const lexer = new TodoLangGrammarLexer(inputStream); | |
const tokenStream = new CommonTokenStream(lexer); | |
const parser = new TodoLangGrammarParser(tokenStream); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar TodoLangGrammar; | |
todoExpressions : (addExpression)* (completeExpression)*; | |
addExpression : ADD TODO STRING; | |
completeExpression : COMPLETE TODO STRING; | |
ADD : 'ADD'; | |
TODO : 'TODO'; | |
COMPLETE: 'COMPLETE'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as monaco from "monaco-editor-core"; | |
import { languageExtensionPoint, languageID } from "./config"; | |
import { monarchLanguage } from "./TodoLang"; | |
export function setupLanguage() { | |
(window as any).MonacoEnvironment = { | |
getWorkerUrl: function (moduleId, label) { | |
return './editor.worker.js'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as monaco from "monaco-editor-core"; | |
import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration; | |
import ILanguage = monaco.languages.IMonarchLanguage; | |
export const monarchLanguage = <ILanguage>{ | |
// Set defaultToken to invalid to see what you do not tokenize yet | |
defaultToken: 'invalid', | |
keywords: [ | |
'COMPLETE', 'ADD', | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const htmlWebpackPlugin = require('html-webpack-plugin'); | |
module.exports = { | |
mode: 'development', | |
entry: { | |
app: './src/index.tsx', | |
"editor.worker": 'monaco-editor-core/esm/vs/editor/editor.worker.js' | |
}, | |
output: { | |
globalObject: 'self', |