Skip to content

Commit

Permalink
refactor(before_v0.60): fix gen-js-ext.nu
Browse files Browse the repository at this point in the history
It has already been moved but not ported from the old version

- replace pipeline `for` with `each`
- explicit print
- port `$nu.scope` to `scope commands`
  • Loading branch information
39555 committed May 5, 2024
1 parent 5a85fb3 commit 661ade2
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions make_release/gen-js-ext.nu
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
def gen_keywords [] {
let cmds = ($nu.scope.commands
let cmds = (scope commands
| where is_extern == false
and is_custom == false
and category !~ deprecated
and ($it.command | str contains -n ' ')
| get command
and ($it.name | str contains -n ' ')
| get name
| str join '|')

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
print $"Generating keywords(char nl)"
print (gen_keywords)
print (char nl)
print (char nl)

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

let preamble = '\\b('
let postamble = ')\\b'
let cmds = (for x in $sub_cmds {
let cmds = ($sub_cmds | each {|x|
let parts = ($x | split row ' ')
$'($parts.0)\\s($parts.1)'
} | str join '|')
$'"match": "($preamble)($cmds)($postamble)",'
}
$"Generating sub keywords(char nl)"
gen_sub_keywords
char nl
print $"Generating sub keywords(char nl)"
print (gen_sub_keywords)
print (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
let cmds = (scope commands
| where is_extern == false
and is_custom == false
and category !~ deprecated
and ($it.command | str contains -n ' ')
| get command)
and ($it.name | str contains -n ' ')
| get name)

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


for alpha in $alphabet {
let letter_cmds = (for cmd in $cmds {
$alphabet | each {|alpha|
let letter_cmds = ($cmds | each {|cmd|
if ($cmd | str starts-with $alpha) {
$cmd
} else {
Expand All @@ -64,25 +64,25 @@ def gen_keywords_alphabetically [] {
} | str join "\n"
}

"Generating keywords alphabetically\n"
gen_keywords_alphabetically
char nl
print "Generating keywords alphabetically\n"
print (gen_keywords_alphabetically)
print (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
let sub_cmds = (scope commands |
| where is_extern == false
and is_custom == false
and category !~ deprecated
and ($it.command | str contains ' ')
| get command)
and ($it.name | str contains ' ')
| get name)

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


for alpha in $alphabet {
let letter_cmds = (for cmd in $sub_cmds {
$alphabet | each {|alpha|
let letter_cmds = ($sub_cmds | each {|cmd|
if ($cmd | str starts-with $alpha) {
let parts = ($cmd | split row ' ')
$'($parts.0)\\s($parts.1)'
Expand All @@ -96,6 +96,6 @@ def gen_sub_keywords_alphabetically [] {
} | str join "\n"
}

"Generating sub keywords alphabetically\n"
gen_sub_keywords_alphabetically
char nl
print "Generating sub keywords alphabetically\n"
print (gen_sub_keywords_alphabetically)
print (char nl)

0 comments on commit 661ade2

Please sign in to comment.