Skip to content

Commit

Permalink
ported script to help with vscode extension (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdncred committed Mar 8, 2022
1 parent 09abce0 commit 6645c7f
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions make_release/gen-js-ext.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
def gen_keywords [] {
let cmds = ($nu.scope.commands
| where is_extern == false
&& is_custom == false
&& category !~ deprecated
&& ($it.command | str contains -n ' ')
| get command
| str collect '|')

let var_with_dash_or_under_regex = '(([a-zA-Z]+[\\-_]){1,}[a-zA-Z]+\\s)'
let preamble = '\\b('
let postamble = ')\\b'
$'"match": "($var_with_dash_or_under_regex)|($preamble)($cmds)($postamble)",'
}
$"Generating keywords(char nl)"
gen_keywords
char nl
char nl

def gen_sub_keywords [] {
let sub_cmds = ($nu.scope.commands
| where is_extern == false
&& is_custom == false
&& category !~ deprecated
&& ($it.command | str contains ' ')
| get command)

let preamble = '\\b('
let postamble = ')\\b'
let cmds = (for x in $sub_cmds {
let parts = ($x | split row ' ')
$'($parts.0)\\s($parts.1)'
} | str collect '|')
$'"match": "($preamble)($cmds)($postamble)",'
}
$"Generating sub keywords(char nl)"
gen_sub_keywords
char nl

def gen_keywords_alphabetically [] {
let alphabet = [a b c d e f g h i j k l m n o p q r s t u v w x y z]
let cmds = ($nu.scope.commands
| where is_extern == false
&& is_custom == false
&& category !~ deprecated
&& ($it.command | str contains -n ' ')
| get command)

let preamble = '\\b('
let postamble = ')\\b'


for alpha in $alphabet {
let letter_cmds = (for cmd in $cmds {
if ($cmd | str starts-with $alpha) {
$cmd
} else {
$nothing
}
} | str collect '|')
if ($letter_cmds | str trim | str length) > 0 {
$'"match": "($preamble)($letter_cmds)($postamble)",'
}
} | str collect "\n"
}

"Generating keywords alphabetically\n"
gen_keywords_alphabetically
char nl

def gen_sub_keywords_alphabetically [] {
let alphabet = [a b c d e f g h i j k l m n o p q r s t u v w x y z]
let sub_cmds = ($nu.scope.commands
| where is_extern == false
&& is_custom == false
&& category !~ deprecated
&& ($it.command | str contains ' ')
| get command)

let preamble = '\\b('
let postamble = ')\\b'


for alpha in $alphabet {
let letter_cmds = (for cmd in $sub_cmds {
if ($cmd | str starts-with $alpha) {
let parts = ($cmd | split row ' ')
$'($parts.0)\\s($parts.1)'
} else {
$nothing
}
} | str collect '|')
if ($letter_cmds | str trim | str length) > 0 {
$'"match": "($preamble)($letter_cmds)($postamble)",'
}
} | str collect "\n"
}

"Generating sub keywords alphabetically\n"
gen_sub_keywords_alphabetically
char nl

0 comments on commit 6645c7f

Please sign in to comment.