Giter Site home page Giter Site logo

tree-sitter-bash's Introduction

tree-sitter-bash's People

Contributors

ahelwer avatar ahlinc avatar amaanq avatar aryx avatar curusarn avatar darangi avatar dav1dde avatar dependabot[bot] avatar domq avatar dundargoc avatar jaopaulolc avatar jasonrudolph avatar kelly-lin avatar lukepistrol avatar mads-hartmann avatar maxbrunsfeld avatar mjambon avatar nokome avatar nordlow avatar observeroftime avatar oxalica avatar ryaminal avatar sighery avatar skovhus avatar verhovsky avatar wingrunr21 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tree-sitter-bash's Issues

||, &&, <, > in conditions are handled incorrectly

Example:

if [[ "$lsb_dist" != 'Ubuntu' || $(ver_to_int "$lsb_release") < $(ver_to_int '14.04') ]]; then
	return 1
fi

Double pipes, double ampersand less then and greater than signs will get "Failed to parse expression" errors.

parse error when negating a variable assignment in an if statement

I was sent over here after filing this issue: bash-lsp/bash-language-server#135

I'm getting a parse error when I have an if statement where I negate a variable assignement. For example:

#! /usr/bin/env bash

bar() {
  return 1
}

foo=''

if ! foo="$(bar)"; then # <-- Syntax error: expected "word" somewhere in the file
  echo "ok."
fi

The error message in the comment is coming from the language server that's implementing your library.

Hopefully this is enough info for a fix. thanks so much!

Can't find bash-language-server on your PATH

I have bash-language-server installed globally, and the global bin directory is in PATH, declared both in my shell (fish), and other installed shells .bashrc and .zshrc.

With all this done, I still get a "Can't find bash-language-server on your PATH" error in VSCode.

Could the path to the language server be configurable as a VSCode setting?

Heredoc redirect to file is not handled properly

Example:

#!/usr/bin/env bash

tmpfile="/tmp/fix-smb.reg"

cat <<EOF > $tmpfile
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management]
"LargeSystemCache"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters]
"Size"=dword:00000003
EOF

The heredoc redirect above is valid and should not be reported as an issue.

Parse error for override redirection

Hey πŸ‘‹,

The redirection operator >| overrides the specified file. See Bash Redirections for further details.

If the redirection operator is β€˜>’, and the noclobber option to the set builtin has been enabled, the redirection will fail if the file whose name results from the expansion of word exists and is a regular file. If the redirection operator is β€˜>|’, or the redirection operator is β€˜>’ and the noclobber option is not enabled, the redirection is attempted even if the file named by word exists.

tree-sitter-bash is currently not able to parse this syntax. Here's an example:

echo "foo" >| foo.txt

Installation errors, too few arguments to function call, macOS 10.14.4, node 12.1.0

macOS 10.14.4

Β§ uname -a
Darwin EPUSPRIW1129 18.5.0 Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64
Β§ node --version
v12.1.0
Β§ npm i -g tree-sitter

> [email protected] install /usr/local/lib/node_modules/tree-sitter
> prebuild-install || node-gyp rebuild

prebuild-install WARN install No prebuilt binaries found (target=12.1.0 runtime=node arch=x64 libc= platform=darwin)
  CC(target) Release/obj.target/tree_sitter/vendor/tree-sitter/lib/src/lib.o
  LIBTOOL-STATIC Release/tree_sitter.a
  CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/binding.o
  CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/conversions.o
../src/conversions.cc:32:12: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  exports->Set(Nan::New("pointTransferArray").ToLocalChecked(), Uint32Array::New(js_point_transfer_buffer, 0, 2));
           ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:3358:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/conversions.cc:42:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  result->Set(Nan::New(start_position_key), PointToJS(range.start_point));
          ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:3358:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/conversions.cc:43:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  result->Set(Nan::New(start_index_key), ByteCountToJS(range.start_byte));
          ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:3358:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/conversions.cc:44:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  result->Set(Nan::New(end_position_key), PointToJS(range.end_point));
          ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:3358:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/conversions.cc:45:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  result->Set(Nan::New(end_index_key), ByteCountToJS(range.end_byte));
          ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:3358:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/conversions.cc:68:3: warning: 'Get' is deprecated: Use maybe version [-Wdeprecated-declarations]
  INIT(start_point, start_position_key, PointFromJS);
  ^
../src/conversions.cc:60:33: note: expanded from macro 'INIT'
    auto field = Type(js_range->Get(Nan::New(key))); \
                                ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:3412:3: note: 'Get' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/conversions.cc:69:3: warning: 'Get' is deprecated: Use maybe version [-Wdeprecated-declarations]
  INIT(end_point, end_position_key, PointFromJS);
  ^
../src/conversions.cc:60:33: note: expanded from macro 'INIT'
    auto field = Type(js_range->Get(Nan::New(key))); \
                                ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:3412:3: note: 'Get' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/conversions.cc:70:3: warning: 'Get' is deprecated: Use maybe version [-Wdeprecated-declarations]
  INIT(start_byte, start_index_key, ByteCountFromJS);
  ^
../src/conversions.cc:60:33: note: expanded from macro 'INIT'
    auto field = Type(js_range->Get(Nan::New(key))); \
                                ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:3412:3: note: 'Get' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/conversions.cc:71:3: warning: 'Get' is deprecated: Use maybe version [-Wdeprecated-declarations]
  INIT(end_byte, end_index_key, ByteCountFromJS);
  ^
../src/conversions.cc:60:33: note: expanded from macro 'INIT'
    auto field = Type(js_range->Get(Nan::New(key))); \
                                ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:3412:3: note: 'Get' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/conversions.cc:80:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  result->Set(Nan::New(row_key), Nan::New<Number>(point.row));
          ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:3358:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/conversions.cc:81:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  result->Set(Nan::New(column_key), ByteCountToJS(point.column));
          ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:3358:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/conversions.cc:92:35: warning: 'Get' is deprecated: Use maybe version [-Wdeprecated-declarations]
  Local<Value> js_row = js_point->Get(Nan::New(row_key));
                                  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:3412:3: note: 'Get' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/conversions.cc:98:38: warning: 'Get' is deprecated: Use maybe version [-Wdeprecated-declarations]
  Local<Value> js_column = js_point->Get(Nan::New(column_key));
                                     ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:3412:3: note: 'Get' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/conversions.cc:105:41: error: too few arguments to function call, single argument 'context' was not specified
  if (std::isfinite(js_row->NumberValue())) {
                    ~~~~~~~~~~~~~~~~~~~ ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:2564:3: note: 'NumberValue' declared here
  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:347:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/conversions.cc:106:52: error: too few arguments to function call, single argument 'context' was not specified
    row = static_cast<uint32_t>(js_row->Int32Value());
                                ~~~~~~~~~~~~~~~~~~ ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:2569:3: note: 'Int32Value' declared here
  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:347:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/conversions.cc:111:44: error: too few arguments to function call, single argument 'context' was not specified
  if (std::isfinite(js_column->NumberValue())) {
                    ~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:2564:3: note: 'NumberValue' declared here
  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:347:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/conversions.cc:112:58: error: too few arguments to function call, single argument 'context' was not specified
    column = static_cast<uint32_t>(js_column->Int32Value()) * BYTES_PER_CHARACTER;
                                   ~~~~~~~~~~~~~~~~~~~~~ ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:2569:3: note: 'Int32Value' declared here
  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:347:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/conversions.cc:130:47: error: too few arguments to function call, single argument 'context' was not specified
  return Nan::Just<uint32_t>(arg->Uint32Value() * BYTES_PER_CHARACTER);
                             ~~~~~~~~~~~~~~~~ ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8.h:2567:3: note: 'Uint32Value' declared here
  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
  ^
/Users/oleksii_chekulaiev/.node-gyp/12.1.0/include/node/v8config.h:347:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
13 warnings and 5 errors generated.
make: *** [Release/obj.target/tree_sitter_runtime_binding/src/conversions.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:196:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:256:12)
gyp ERR! System Darwin 18.5.0
gyp ERR! command "/usr/local/Cellar/node/12.1.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/tree-sitter
gyp ERR! node -v v12.1.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/oleksii_chekulaiev/.npm/_logs/2019-05-01T15_52_34_814Z-debug.log

2019-05-01T15_52_34_814Z-debug.log

2019-05-01T15_52_34_814Z-debug.log

Support regular expression operator

Currently the parser will be unhappy with the following expression

[[ "35d8b" =~ ^[0-9a-fA-F]{5}$ ]] && echo "It's a hash"

My initial idea was to simple create $.regex rule and add that to $._expression but given that there aren't any marker characters for regular expressions (like /abc/ in javascript) in Bash I think we have to go another route. I'm not sure what the best approach is at the moment so I'll just leave the issue open πŸ˜„

Handle escaped backticks

Stumbled upon an escaped backtick in one my scripts which seems to trip up the parser

echo "Escape backtick\`"

Haven't investigated the issue yet so just adding it here for later.

Issues parsing closing curly brace followed by symbols in conditions

Here are examples of conditional expressions that show errors but are actually valid.
With comments which part is highlighted in "red". All of them seem to stumble upon closing curly brace.

# from expression start till first closing curly brace highlighted
if [[ "$1" =~ ^${var}${var}*=..* ]]; then
  echo 1
fi

# closing curly brace highlighted
if [[ "$1" =~ ^\-${var}+ ]]; then
  echo 1
fi

# closing curly brace and * highlighted
if [[ ${var1} == *${var2}* ]]; then
  echo 1
fi

# from expression start till first closing curly brace highlighted
if [[ "$server" =~ [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} ]]; then
  echo 1
fi

# from expression start till first closing curly brace highlighted
if [[ "$primary_wins" =~ ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) ]]; then
  echo 1
fi

# dollar sign after closing curly brace highlighted
if ( grep ^${var}$ ); then
  echo 1
fi

p.s. Thanks for great work fixing other issues! These curly braces are the last errors left in our 6k+ lines bash code.

Arrays support

Currently this snippet fails to be parsed

if ((${#aaa[@]} == 0)); then
fi

Parsing issue in here doc

I have a script that produces another script using a here document, here's a snippet:

cat  << EOF > job.conf
...
DEV_NAME=\$(lsblk --nodeps -no name,serial | grep $SERIAL | awk '{printf \$1}')
...
EOF

The parser chokes on it but I can't see why.

Case statements

It seems like the current grammar for case_item is a bit too strict. I've found two variants that are interesting

One line case lines

In this case it's okay for the statement itself not to be terminated.

case "a" in
  a) echo a ;;
  *) echo other ;;
esac

Optional terminator in case line

It seems that the last ;; can be omitted as it's inferred by the esac

case "a" in 
  a) echo a ;; 
  *) echo other
esac

I don't have any suggestions regarding how to fix it right now though πŸ˜‰

Parameter substitution case

Not sure if this is covered by #9 but I found a parameter substitution case in one of my Bash files that the parser doesn't like. A minimal example is the following:

echo ${var1#*#}

It will remove everything from the beginning of var1 until it reaches an #. Here's a valid example

var1=foobar-#123
echo ${var1#*#}

How to use this parser in the main tree-sitter?

Hello, documentation is really fuzzy regarding how to use specific language parser functions. Is describing example code, what is doing but not how to integrate a plugin and easily use it. Moreover, I use the suggestion to just add source code and header to my project, but I don't understand how I can do the same for the bash parser. I think it is really appreciated to have a doc describing this in details, also to spread the use of this nice project.
Thanks

Parse error for compound expression while loops

When calling while a loop with multiple statements before the do, I get a parse error:

loop_assign() {
  while local name="$1" val="$2"; shift 2; do # <-- Failed to parse expression
    printf "%s (%s)\n" "$val" "$name"
  done
}

loop_assign foo bar baz bing thing thang thong

Variables in functions missing type

First of all sorry if the report is not detailed enough. I've been asked to report it here by bash-language server author . So variables in functions like:

#!/bin/sh
# A simple script with a function...

add_a_user()
{
  USER=$1
  PASSWORD=$2
  shift; shift;
  # Having shifted twice, the rest is now comments ...
  COMMENTS=$@
  echo "Adding user $USER ..."
  echo useradd -c "$COMMENTS" $USER
  echo passwd $USER $PASSWORD
  echo "Added user $USER ($COMMENTS) with pass $PASSWORD"
}

###
# Main body of script starts here
###
echo "Start of script..."
add_a_user bob letmein Bob Holness the presenter
add_a_user fred badpassword Fred Durst the singer
add_a_user bilko worsepassword Sgt. Bilko the role model
echo "End of script..."

are missing something from grammar side as indicated to me in bash-lsp/bash-language-server#101 .
Please let me know how I can help in mediating the conversation between the two projects I'm not developer of so the issue gets resolved.

0.13.2 missing parsing errors

0.13.1 error on a file like this with a missing fi:

PATH_INPUT=src/in.js
PATH_OUTPUT=src/out.js

if [[ $PATH_INPUT -nt $PATH_OUTPUT ]]; then
  babel --compact false ${PATH_INPUT} > ${PATH_OUTPUT}
f

I guess this is a regression from 0.13.1? Didn't investigate if this is due to 6ff7fe3

Unable to parse ${#}

I am having similar issue as #21. Sample code:

if [[ ${#} -ne 3 ]]; then
    tpcp::utils::usage
    tpcp::utils::terminate
fi

SnΓ­mek obrazovky 2019-08-24 vΒ 16 32 24

Grammar does not support case fallthrough terminators

I'm using tree-sitter-bash through bash-language-server => w0rp/ale on VIM and I have a case statement that uses a fallthrough terminator similar to the following.

case "$1" in
    init) echo "here is where I would do some init"
        exit;;

    --help | -h)
        ;;&
 
    *) print_usage
        exit;;
esac

Perhaps there is a better way to do the above but this is just a simple example to reproduce the issue. I should also note that the script runs fine when executed in the terminal.

The errors that are reported are:
Syntax error: expected "esac" somewhere in the file (on line ;;&) and
Failed to parse expression (on line *) print_usage)

I'm not sure if these are coming from bash-language-server/tree-sitter or are generic ALE errors (I ran :ALEInfo and do not see these errors printed anywhere)

Parse error for arithmetic expression and comma operator in for loop

In VS Code I get parse errors for a code snippet like this:

#!/bin/bash

f()
{
  local x wc=0 wcx=0 k=0 N=1 w cx c d=1 pf=1
  x=$(( ( $wcx - $k ) / $N ))
  for (( cx=0, w=1;  c=$cx/$pf, c<$wc-$k;  cx+=$d, w++ )); do
    echo "$cx"
  done
}

f

The code has been trimmed down to show the problem. See this screenshot for the squiggly lines. tree-sitter-bash version is 0.13.7, indirect dependency of the VS Code bash-ide extension.

Multi-line sub-shell throws an error

Example

#!/bin/bash

_path=$(
    while [[ ! -f $1 ]] && [[ ! -d $1 ]] && [[ $(pwd) != / ]]; do
        cd ".."
    done;
    if [[ -f $1 ]] || [[ -d $1 ]]; then echo $(pwd); exit; fi
)

Above script is valid and should not throw any errors.

Corpus of shell scripts

Hi I just learned of this project through a reddit comment [1]

I saw that you have some example shell scripts as test cases for the parser. FWIW I have a corpus of 11,568 shell scripts here:

http://www.oilshell.org/blob/wild/

Here's a report from running the Oil parser over this corpus (which I wrote):

http://www.oilshell.org/release/0.6.pre6/test/wild.wwz/index.html

There is a bunch of background on the blog, for example: http://www.oilshell.org/blog/2017/11/10.html

I put a link to your parser here, along with 3-4 other parsers (although it's not clear how complete they are.)

https://github.com/oilshell/oil/wiki/ExternalResources

[1] https://www.reddit.com/r/commandline/comments/9p6nb2/complete_command_line_flags_in_vimemacs_or/?utm_content=full_comments&utm_medium=message&utm_source=reddit&utm_name=frontpage

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.