diff --git a/examples/fibonacci.reid b/examples/fibonacci.reid index 1b6b1db..9aad4c7 100644 --- a/examples/fibonacci.reid +++ b/examples/fibonacci.reid @@ -1,12 +1,13 @@ -// Main -fn main() -> bool { - return 144 == fibonacci(0xc); -} - -// Fibonacci -fn fibonacci(value: u16) -> u16 { - if value <= 2 { - return 1; - } - fibonacci(value - 1) + fibonacci(value - 2) -} +a +( + b +) +x +( + ( + c + xyz + ) +) +( +a diff --git a/reid-lsp/package.json b/reid-lsp/package.json index aa4d0ec..80723b1 100644 --- a/reid-lsp/package.json +++ b/reid-lsp/package.json @@ -43,11 +43,18 @@ "description": "Traces the communication between VS Code and the language server." } } - } + }, + "grammars": [ + { + "language": "reid", + "scopeName": "source.reid", + "path": "./syntaxes/grammar.json" + } + ] }, "scripts": { "vscode:prepublish": "pnpm run package", - "compile": "webpack", + "compile": "npx js-yaml syntaxes/grammar.yaml > syntaxes/grammar.json && webpack", "watch": "webpack --watch", "package": "webpack --mode production --devtool hidden-source-map", "compile-tests": "tsc -p . --outDir out", @@ -65,6 +72,7 @@ "@vscode/test-cli": "^0.0.11", "@vscode/test-electron": "^2.5.2", "eslint": "^9.25.1", + "js-yaml": "^4.1.0", "ts-loader": "^9.5.2", "typescript": "^5.8.3", "webpack": "^5.99.7", diff --git a/reid-lsp/syntaxes/grammar.json b/reid-lsp/syntaxes/grammar.json new file mode 100644 index 0000000..6478785 --- /dev/null +++ b/reid-lsp/syntaxes/grammar.json @@ -0,0 +1,44 @@ +{ + "scopeName": "source.reid", + "patterns": [ + { + "include": "#expression" + } + ], + "repository": { + "expression": { + "patterns": [ + { + "include": "#letter" + }, + { + "include": "#paren-expression" + } + ] + }, + "letter": { + "match": "a|b|c", + "name": "keyword.letter" + }, + "paren-expression": { + "begin": "\\(", + "end": "\\)", + "beginCaptures": { + "0": { + "name": "punctuation.paren.open" + } + }, + "endCaptures": { + "0": { + "name": "punctuation.paren.close" + } + }, + "name": "expression.group", + "patterns": [ + { + "include": "#expression" + } + ] + } + } +} diff --git a/reid-lsp/syntaxes/grammar.yaml b/reid-lsp/syntaxes/grammar.yaml new file mode 100644 index 0000000..493ac98 --- /dev/null +++ b/reid-lsp/syntaxes/grammar.yaml @@ -0,0 +1,23 @@ +scopeName: source.reid +patterns: + - include: "#expression" +repository: + expression: + patterns: + - include: "#letter" + - include: "#paren-expression" + letter: + match: "a|b|c" + name: "keyword.letter" + paren-expression: + begin: "\\(" + end: "\\)" + beginCaptures: + 0: + name: "punctuation.paren.open" + endCaptures: + 0: + name: "punctuation.paren.close" + name: "expression.group" + patterns: + - include: "#expression"