all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* tree-sitter shell script changes
       [not found] <87356chi3i.fsf.ref@yahoo.com>
@ 2023-03-10 13:05 ` Po Lu
  2023-03-11  3:09   ` Randy Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Po Lu @ 2023-03-10 13:05 UTC (permalink / raw)
  To: emacs-devel

I would like to install the following two changes to avoid POSIX-isms
and bashisms in admin/notes/tree-sitter.  Would people please try them
first, to make sure that I did not break something obscure?

Thanks in advance.

diff --git a/admin/notes/tree-sitter/build-module/batch.sh b/admin/notes/tree-sitter/build-module/batch.sh
index 58272c74549..7ed57206619 100755
--- a/admin/notes/tree-sitter/build-module/batch.sh
+++ b/admin/notes/tree-sitter/build-module/batch.sh
@@ -1,27 +1,27 @@
-#!/bin/bash
+#!/bin/sh
 
-languages=(
-    'bash'
-    'c'
-    'cmake'
-    'cpp'
-    'css'
-    'c-sharp'
-    'dockerfile'
-    'go'
-    'go-mod'
-    'html'
-    'javascript'
-    'json'
-    'python'
-    'rust'
-    'toml'
-    'tsx'
-    'typescript'
-    'yaml'
-)
+languages='
+    bash
+    c
+    cmake
+    cpp
+    css
+    c-sharp
+    dockerfile
+    go
+    go-mod
+    html
+    javascript
+    json
+    python
+    rust
+    toml
+    tsx
+    typescript
+    yaml
+'
 
-for language in "${languages[@]}"
+for treesit_word in $languages
 do
-    ./build.sh $language
+    ./build.sh $treesit_word
 done
diff --git a/admin/notes/tree-sitter/build-module/build.sh b/admin/notes/tree-sitter/build-module/build.sh
index 9dc674237ca..1ab3e3aa4a2 100755
--- a/admin/notes/tree-sitter/build-module/build.sh
+++ b/admin/notes/tree-sitter/build-module/build.sh
@@ -1,13 +1,13 @@
-#!/bin/bash
+#!/bin/sh
 
 lang=$1
-topdir="$PWD"
+topdir=`pwd`
 
-case $(uname) in
-    "Darwin")
+case `uname` in
+    Darwin)
         soext="dylib"
         ;;
-    *"MINGW"*)
+    *MINGW*)
         soext="dll"
         ;;
     *)
@@ -25,27 +25,27 @@ sourcedir=
 grammardir="tree-sitter-${lang}"
 
 case "${lang}" in
-    "dockerfile")
+    dockerfile)
         org="camdencheek"
         ;;
-    "cmake")
+    cmake)
         org="uyha"
         ;;
-    "go-mod")
+    go-mod)
         # The parser is called "gomod".
         lang="gomod"
         org="camdencheek"
         ;;
-    "typescript")
+    typescript)
         sourcedir="tree-sitter-typescript/typescript/src"
         grammardir="tree-sitter-typescript/typescript"
         ;;
-    "tsx")
+    tsx)
         repo="tree-sitter-typescript"
         sourcedir="tree-sitter-typescript/tsx/src"
         grammardir="tree-sitter-typescript/tsx"
         ;;
-    "yaml")
+    yaml)
         org="ikatyang"
         ;;
 esac
@@ -61,18 +61,15 @@ grammardir=
 
 cc -fPIC -c -I. parser.c
 # Compile scanner.c.
-if test -f scanner.c
-then
+if test -f scanner.c; then
     cc -fPIC -c -I. scanner.c
 fi
 # Compile scanner.cc.
-if test -f scanner.cc
-then
+if test -f scanner.cc; then
     c++ -fPIC -I. -c scanner.cc
 fi
 # Link.
-if test -f scanner.cc
-then
+if test -f scanner.cc; then
     c++ -fPIC -shared *.o -o "libtree-sitter-${lang}.${soext}"
 else
     cc -fPIC -shared *.o -o "libtree-sitter-${lang}.${soext}"



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: tree-sitter shell script changes
  2023-03-10 13:05 ` tree-sitter shell script changes Po Lu
@ 2023-03-11  3:09   ` Randy Taylor
  2023-03-11  3:28     ` Po Lu
  0 siblings, 1 reply; 3+ messages in thread
From: Randy Taylor @ 2023-03-11  3:09 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel

On Friday, March 10th, 2023 at 08:05, Po Lu <luangruo@yahoo.com> wrote:
> 
> I would like to install the following two changes to avoid POSIX-isms
> and bashisms in admin/notes/tree-sitter. Would people please try them
> first, to make sure that I did not break something obscure?
> 
> Thanks in advance.
> 
> diff --git a/admin/notes/tree-sitter/build-module/batch.sh b/admin/notes/tree-sitter/build-module/batch.sh
> index 58272c74549..7ed57206619 100755
> --- a/admin/notes/tree-sitter/build-module/batch.sh
> +++ b/admin/notes/tree-sitter/build-module/batch.sh
> @@ -1,27 +1,27 @@
> -#!/bin/bash
> +#!/bin/sh
> 
> -languages=(
> - 'bash'
> - 'c'
> - 'cmake'
> - 'cpp'
> - 'css'
> - 'c-sharp'
> - 'dockerfile'
> - 'go'
> - 'go-mod'
> - 'html'
> - 'javascript'
> - 'json'
> - 'python'
> - 'rust'
> - 'toml'
> - 'tsx'
> - 'typescript'
> - 'yaml'
> -)
> +languages='
> + bash
> + c
> + cmake
> + cpp
> + css
> + c-sharp
> + dockerfile
> + go
> + go-mod
> + html
> + javascript
> + json
> + python
> + rust
> + toml
> + tsx
> + typescript
> + yaml
> +'
> 
> -for language in "${languages[@]}"
> +for treesit_word in $languages

Why treesit_word instead of language? language is much better IMO.

> do
> - ./build.sh $language
> + ./build.sh $treesit_word
> done
> diff --git a/admin/notes/tree-sitter/build-module/build.sh b/admin/notes/tree-sitter/build-module/build.sh
> index 9dc674237ca..1ab3e3aa4a2 100755
> --- a/admin/notes/tree-sitter/build-module/build.sh
> +++ b/admin/notes/tree-sitter/build-module/build.sh
> @@ -1,13 +1,13 @@
> -#!/bin/bash
> +#!/bin/sh
> 
> lang=$1
> -topdir="$PWD"
> +topdir=`pwd`
> 
> -case $(uname) in
> - "Darwin")
> +case `uname` in
> + Darwin)
> soext="dylib"
> ;;
> - "MINGW")
> + MINGW)
> soext="dll"
> ;;
> *)
> @@ -25,27 +25,27 @@ sourcedir=
> grammardir="tree-sitter-${lang}"
> 
> case "${lang}" in
> - "dockerfile")
> + dockerfile)
> org="camdencheek"
> ;;
> - "cmake")
> + cmake)
> org="uyha"
> ;;
> - "go-mod")
> + go-mod)
> # The parser is called "gomod".
> lang="gomod"
> org="camdencheek"
> ;;
> - "typescript")
> + typescript)
> sourcedir="tree-sitter-typescript/typescript/src"
> grammardir="tree-sitter-typescript/typescript"
> ;;
> - "tsx")
> + tsx)
> repo="tree-sitter-typescript"
> sourcedir="tree-sitter-typescript/tsx/src"
> grammardir="tree-sitter-typescript/tsx"
> ;;
> - "yaml")
> + yaml)
> org="ikatyang"
> ;;
> esac
> @@ -61,18 +61,15 @@ grammardir=
> 
> cc -fPIC -c -I. parser.c
> # Compile scanner.c.
> -if test -f scanner.c
> -then
> +if test -f scanner.c; then
> cc -fPIC -c -I. scanner.c
> fi
> # Compile scanner.cc.
> -if test -f scanner.cc
> -then
> +if test -f scanner.cc; then
> c++ -fPIC -I. -c scanner.cc
> fi
> # Link.
> -if test -f scanner.cc
> -then
> +if test -f scanner.cc; then
> c++ -fPIC -shared *.o -o "libtree-sitter-${lang}.${soext}"
> else
> cc -fPIC -shared *.o -o "libtree-sitter-${lang}.${soext}"

I tried it on Linux and it works fine.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: tree-sitter shell script changes
  2023-03-11  3:09   ` Randy Taylor
@ 2023-03-11  3:28     ` Po Lu
  0 siblings, 0 replies; 3+ messages in thread
From: Po Lu @ 2023-03-11  3:28 UTC (permalink / raw)
  To: Randy Taylor; +Cc: emacs-devel

Randy Taylor <dev@rjt.dev> writes:

> Why treesit_word instead of language? language is much better IMO.

Typically when you iterate over the words in a string separated by the
IFS, you name the variable ``FOO_word'', where FOO is the name of the
component performing the iteration.

It makes sourcing the script into another shell safer.  But I guess the
other variables in it have problems there too, so I won't insist.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-11  3:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <87356chi3i.fsf.ref@yahoo.com>
2023-03-10 13:05 ` tree-sitter shell script changes Po Lu
2023-03-11  3:09   ` Randy Taylor
2023-03-11  3:28     ` Po Lu

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.