From e27408c6622559fb7725fe340e012d32e42e9ff5 Mon Sep 17 00:00:00 2001 From: Dustin Wilson Date: Mon, 28 Jun 2021 16:52:38 -0500 Subject: [PATCH] Improvements to run command, starting on Grammar --- data/lua/tree-sitter-lua.json | 136 ---------------------------------- lib/Grammar.php | 16 ++++ lib/Grammar/Registry.php | 12 +-- run | 68 +++++++++++------ 4 files changed, 66 insertions(+), 166 deletions(-) delete mode 100644 data/lua/tree-sitter-lua.json create mode 100644 lib/Grammar.php diff --git a/data/lua/tree-sitter-lua.json b/data/lua/tree-sitter-lua.json deleted file mode 100644 index 8a375d8..0000000 --- a/data/lua/tree-sitter-lua.json +++ /dev/null @@ -1,136 +0,0 @@ -{ - "name": "Lua", - "scopeName": "source.lua", - "type": "tree-sitter", - "parser": "tree-sitter-lua", - - "fileTypes": [ "lua" ], - - "folds": [ - { - "type": [ - "do_statement", - "while_statement", - "repeat_statement", - "for_statement", - "for_in_statement", - "function", - "local_function", - "function_definition", - "table" - ], - "end": { "index": -1 } - }, - { - "type": ["if_statement","elseif"], - "start": { "index": 1 }, - "end": { "type": [ "else", "elseif" ] } - }, - { - "type": "if_statement", - "start": { "index": 1 }, - "end": { "index": -1 } - }, - { - "type": "elseif", - "start": { "index": 1 } - }, - { - "type": "else", - "start": { "index": 0 } - } - ], - - "comments": { - "start": "-- " - }, - - "scopes": { - "program": "source.lua", - - "comment": "comment", - "string": "string", - "number": "constant.numeric", - - "function > function_name > identifier": "entity.name.function", - "function > function_name > property_identifier": "entity.name.function", - "function > function_name > method": "entity.name.function", - "function > parameters > identifier": "variable.parameter", - - "local_function > identifier": "entity.name.function", - "local_function > parameters > identifier": "variable.parameter", - - "function_call > identifier": "entity.name.function", - "function_call > property_identifier": "entity.name.function", - "function_call > method": "entity.name.function", - - "function_definition > parameters > identifier": "variable.parameter", - - "self": "variable.language", - "next": "entity.name.function", - "spread": "variable.parameter", - "global_variable": "variable.language", - - "nil": "constant.language.nil", - "true": "constant.language.boolean", - "false": "constant.language.boolean", - - "'local'": "storage.modifier", - "'function'": "storage.type.function", - "label_statement": "storage.type.label", - - "'{'": "punctuation.definition.table.begin", - "'}'": "punctuation.definition.table.end", - "'('": "punctuation.definition.parameters.begin", - "')'": "punctuation.definition.parameters.end", - - "'do'": "keyword.control", - "'return'": "keyword.control", - "'if'": "keyword.control", - "'then'": "keyword.control", - "'elseif'": "keyword.control", - "'else'": "keyword.control", - "'while'": "keyword.control", - "'repeat'": "keyword.control", - "'until'": "keyword.control", - "'for'": "keyword.control", - "'in'": "keyword.control", - "'goto'": "keyword.control", - "'end'": "keyword.control", - - "'or'": "keyword.operator.logical", - "'and'": "keyword.operator.logical", - "'not'": "keyword.operator.logical", - "'|'": "keyword.operator.logical", - "'&'": "keyword.operator.logical", - "'~'": "keyword.operator.logical", - - "'='": "keyword.operator.assignment", - - "'<'": "keyword.operator.comparison", - "'<='": "keyword.operator.comparison", - "'=='": "keyword.operator.comparison", - "'~='": "keyword.operator.comparison", - "'>='": "keyword.operator.comparison", - "'>'": "keyword.operator.comparison", - - "'<<'": "keyword.operator.arithmetic.bitwise", - "'>>'": "keyword.operator.arithmetic.bitwise", - "'+'": "keyword.operator.arithmetic", - "'-'": "keyword.operator.arithmetic", - "'*'": "keyword.operator.arithmetic", - "'/'": "keyword.operator.arithmetic", - "'//'": "keyword.operator.arithmetic", - "'%'": "keyword.operator.arithmetic", - - "'..'": "keyword.operator.arithmetic", - "'^'": "keyword.operator.arithmetic", - - "'#'": "keyword.operator.arithmetic", - - "'.'": "punctuation.separator.object", - "','": "punctuation.separator.object", - "':'": "punctuation.separator.method", - "';'": "punctuation.separator.statement" - } -} diff --git a/lib/Grammar.php b/lib/Grammar.php new file mode 100644 index 0000000..f45c8ee --- /dev/null +++ b/lib/Grammar.php @@ -0,0 +1,16 @@ +=5.0 ##? * composer >=2.0.6 ##? * docopts >=0.6.3 -##? * gnu awk >=5.1.0 -##? * gnu coreutils >=8.0 -##? * gnu parallel >=20180922 +##? * GNU awk >=5.1.0 +##? * GNU coreutils >=8.0 +##? * GNU parallel >=20180922 ##? * yarn >=1.22.10 ##? ##? Arch Linux: -##? ``` -##? pacman -S composer docopts parallel yarn -##? ``` +##? ``` +##? pacman -S composer docopts parallel yarn +##? ``` ##? ##? macOS: -##? ``` -##? brew install bash composer coreutils docopts gawk parallel yarn -##? echo \"/usr/local/bin/bash\" >> /etc/shells -##? chsh -s /usr/local/bin/bash -##? ``` +##? ``` +##? brew install bash composer coreutils docopts gawk parallel yarn +##? echo \"/usr/local/bin/bash\" >> /etc/shells +##? chsh -s /usr/local/bin/bash +##? ``` ##? ##? Building the grammars is then a matter of running the following commands ##? from the project folder: ##? -##? ``` -##? ./run init -##? ./run build -##? ``` +##? ``` +##? ./run init +##? ./run build +##? ``` ##? ##? ##? Commands: @@ -57,29 +57,41 @@ ##? needed ##? List the language grammars that are included in the current grammars ##? but are not in the data/ folder. +##? +set -e cwd=$(pwd) PATH="$cwd/node_modules/.bin:$PATH" help=$(grep "^##?" "$0" | cut -c 5-) -eval "$(docopts -h "$help" : "$@")" +eval "$(docopts -A args -h "$help" : "$@")" fail() { echo $help exit 1 } -# Check for bash 4+ -shopt -s globstar extglob || help +# Check for bash 4+ and set extra glob options +shopt -s globstar extglob || fail +# macOS uses the BSD version of awk which isn't compatible with the linux +# version, so this script requires Mac users to install the GNU version; it +# therefore has a different name on macOS. awkcmd="awk" if [ "$(uname)" == "Darwin" ]; then awkcmd="gawk" fi # Check for presence of dependencies -if (( $(which $awkcmd composer parallel yarn | wc -l) < 4 )); then help; fi +if (( $(which $awkcmd composer parallel yarn | wc -l) < 4 )); then fail; fi + +# Process the subcommand +subcmd="build" +subcmd=$([ "${args[init]}" == "true" ] && echo "init" || echo "$subcmd") +subcmd=$([ "${args[needed]}" == "true" ] && echo "needed" || echo "$subcmd") -read -r -d '' grammarList <<'EOF' +# Grammar table of the github repository location followed by its local folder +# name +read -r -d '' grammarTable <<'EOF' franzheidl/atom-applescript applescript atom/language-c c atom/language-coffee-script coffeescript @@ -102,14 +114,14 @@ atom/language-typescript typescript atom/language-xml xml EOF -case $1 in +case $subcmd in init) yarn install mkdir -p "$cwd"/deps rm -rf "$cwd"/deps/* cd "$cwd"/deps - printf "$grammarList" | parallel --colsep ' ' "git clone https://github.com/{1}.git" + printf "$grammarTable" | parallel --colsep ' ' "git clone https://github.com/{1}.git" cd "$cwd" ;; @@ -122,14 +134,22 @@ needed) build | *) rm -rf "$cwd"/data/* + # Copy grammars folders from all the local language grammar repositories to a + # temporary folder with the names provided in the table above temp=$(mktemp -d) - printf "$grammarList" | parallel --colsep ' ' "mkdir -p $temp/{2} && + printf "$grammarTable" | parallel --colsep ' ' "mkdir -p $temp/{2} && cp -r \"$cwd\"/deps/\$(basename {1})/grammars/* $temp/{2}/" + # Convert all relevant CSON files to a format that can actually be used :) ls -1 $temp/**/!(tree-sitter-*).cson | parallel "csonc --output={.}.json {} && rm {}" - rm -rf $temp/**/*.cson + # Remove any remaining tree sitter files; will also remove JSON ones from + # packages that didn't use CSON + rm $temp/**/tree-sitter-* + # Lastly, move everything over to the project's data folder and delete the + # temporary folder mv $temp/* "$cwd"/data/ + rmdir $temp ;; esac \ No newline at end of file