diff --git a/docs/language-spec.json b/docs/language-spec.json new file mode 100644 index 0000000..16c03ee --- /dev/null +++ b/docs/language-spec.json @@ -0,0 +1,184 @@ +{ + "name": "php-script", + "version": "1.0.0", + "keywords": [ + "if", + "else", + "for", + "foreach", + "as", + "echo", + "return", + "true", + "false", + "null", + "LINEBREAK" + ], + "operators": [ + "==", + "===", + "!=", + "!==", + "=", + ".", + "+", + "-", + "*", + "/", + ">", + "<" + ], + "symbols": "[=>](?!@symbols)", + "@brackets" + ], + [ + "@symbols", + { + "cases": { + "@operators": "operator", + "@default": "" + } + } + ], + [ + "\\\\d+(\\\\.\\\\d+)?", + "number" + ], + [ + "\\"", + "string.quote", + "@string_double" + ], + [ + "'", + "string.quote", + "@string_single" + ] + ], + "whitespace": [ + [ + "[ \\t\\r\\n]+", + "" + ], + [ + "\\\\/\\\\/.*$", + "comment" + ] + ], + "string_double": [ + [ + "[^\\\\\\\\"]+", + "string" + ], + [ + "\\\\\\\\.", + "string.escape" + ], + [ + "\\"", + "string.quote", + "@pop" + ] + ], + "string_single": [ + [ + "[^\\\\\\\\']+", + "string" + ], + [ + "\\\\\\\\.", + "string.escape" + ], + [ + "'", + "string.quote", + "@pop" + ] + ] + }, + "completionItems": { + "globalFunctions": [], + "globalVariables": [], + "classes": [], + "controlFlows": [ + { + "label": "for", + "kind": "Snippet", + "snippet": "for (${1:i} = ${2:0}; ${1} < ${3:count}(${4}); ${1}++) {\\n $0\\n}", + "doc": "For-Loop", + "detail": "for (int $i = 0; $i < count($items); $i++) {" + }, + { + "label": "foreach", + "kind": "Snippet", + "snippet": "foreach (${1:items} as ${2:item}) {\\n $0\\n}", + "doc": "Foreach-Loop", + "detail": "foreach ($items as $item) {" + }, + { + "label": "foreach (key, value)", + "kind": "Snippet", + "snippet": "foreach (${1:map} as ${2:key}, ${3:value}) {\\n $0\\n}", + "doc": "Foreach-Loop for Key/Value Pairs", + "detail": "foreach ($map as $key => $value) {" + }, + { + "label": "if", + "kind": "Snippet", + "snippet": "if (${1:condition}) {\\n $0\\n}", + "doc": "If-Condition", + "detail": "if ($condition) {" + }, + { + "label": "ifelse", + "kind": "Snippet", + "snippet": "if (${1:condition}) {\\n $2\\n} else {\\n $0\\n}", + "doc": "If-Else-Condition", + "detail": "if ($condition) { ... } else { ... }" + } + ], + "loopControls": [ + { + "label": "break 2", + "kind": "Snippet", + "snippet": "break ${1:2};", + "doc": "Break from nested loops", + "detail": "break N;" + }, + { + "label": "continue 2", + "kind": "Snippet", + "snippet": "continue ${1:2};", + "doc": "Continue outer loop from nested loops", + "detail": "continue N;" + } + ], + "loopKeywords": [ + "break", + "continue" + ] + } +} diff --git a/src/Monarch/LanguageSpecificationService.php b/src/Monarch/LanguageSpecificationService.php new file mode 100644 index 0000000..fc707dc --- /dev/null +++ b/src/Monarch/LanguageSpecificationService.php @@ -0,0 +1,32 @@ + + */ + public function getSpecification(): array + { + $definition = $this->monarchLanguageDefinitionService->getDefinition(); + $completionItems = $this->monarchLanguageDefinitionService->getCompletionItems(); + + return [ + 'name' => 'php-script', + 'version' => '1.0.0', + 'keywords' => $definition['keywords'], + 'operators' => $definition['operators'], + 'symbols' => $definition['symbols'], + 'tokenizer' => $definition['tokenizer'], + 'completionItems' => $completionItems, + ]; + } +} diff --git a/tools/generate-language-spec.php b/tools/generate-language-spec.php new file mode 100644 index 0000000..3948e88 --- /dev/null +++ b/tools/generate-language-spec.php @@ -0,0 +1,19 @@ +getSpecification(); + +$json = json_encode($specification, JSON_PRETTY_PRINT); + +file_put_contents(__DIR__.'/../docs/language-spec.json', $json); + +echo "Language specification generated successfully.\n";