Skip to content

Commit

Permalink
Integrate bash parser
Browse files Browse the repository at this point in the history
  • Loading branch information
xaizek committed Aug 1, 2022
1 parent 8656c09 commit 159ad2d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/zograscope.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ LANGUAGE SUPPORT
|-----------|-------------------------------------------------------------------
| C | C11 and earlier with common extensions, but without K&R syntax
| C++ | C++14 and earlier with common extensions
| Bash | Not targeting a specific version
| GNU Make | Most of the syntax
| Lua | Version 5.3

Expand Down Expand Up @@ -56,6 +57,11 @@ Note the following:

* the tuning of comparison is in progress and will be refined over time

Bash
----

The source of the grammar doesn't explicitly specify the version.

GNU Make
--------

Expand Down
3 changes: 3 additions & 0 deletions docs/zs-diff.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ Makefile.am diff=zs-diff
Makefile.win diff=zs-diff

*.lua diff=zs-diff

*.bash diff=zs-diff
*.sh diff=zs-diff
```

This will make it work for `git diff` and `git show`, but `git log` and other
Expand Down
10 changes: 9 additions & 1 deletion man/zograscope.7
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
. ftr VB CB
. ftr VBI CBI
.\}
.TH "zograscope" "7" "July 30, 2022" "" ""
.TH "zograscope" "7" "July 31, 2022" "" ""
.hy
.SH NAME
.PP
Expand Down Expand Up @@ -52,6 +52,11 @@ T}@T{
C++14 and earlier with common extensions
T}
T{
Bash
T}@T{
Not targeting a specific version
T}
T{
GNU Make
T}@T{
Most of the syntax
Expand Down Expand Up @@ -95,6 +100,9 @@ parser that wasn\[cq]t that hard to integrate.
Note the following:
.IP \[bu] 2
the tuning of comparison is in progress and will be refined over time
.SS Bash
.PP
The source of the grammar doesn\[cq]t explicitly specify the version.
.SS GNU Make
.PP
It\[cq]s hard to measure level of support in case of GNU Make, because
Expand Down
5 changes: 4 additions & 1 deletion man/zs-diff.1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
. ftr VB CB
. ftr VBI CBI
.\}
.TH "zs-diff" "1" "July 30, 2022" "" ""
.TH "zs-diff" "1" "July 31, 2022" "" ""
.hy
.SH NAME
.PP
Expand Down Expand Up @@ -99,6 +99,9 @@ Makefile.am diff=zs-diff
Makefile.win diff=zs-diff

*.lua diff=zs-diff

*.bash diff=zs-diff
*.sh diff=zs-diff
\f[R]
.fi
.PP
Expand Down
11 changes: 11 additions & 0 deletions src/Language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "c/C11Language.hpp"
#include "make/MakeLanguage.hpp"
#include "srcml/cxx/SrcmlCxxLanguage.hpp"
#include "ts/bash/TSBashLanguage.hpp"
#include "ts/lua/TSLuaLanguage.hpp"
#include "tree.hpp"

Expand Down Expand Up @@ -65,6 +66,9 @@ Language::create(const std::string &fileName, const std::string &l)
if (lang == "cxx") {
return std::unique_ptr<SrcmlCxxLanguage>(new SrcmlCxxLanguage());
}
if (lang == "bash") {
return std::unique_ptr<TsBashLanguage>(new TsBashLanguage());
}
if (lang == "lua") {
return std::unique_ptr<TsLuaLanguage>(new TsLuaLanguage());
}
Expand Down Expand Up @@ -108,6 +112,9 @@ simplifyLanguage(const std::string &lang)
if (lang == "srcml:cxx") {
return "cxx";
}
if (lang == "ts:bash") {
return "bash";
}
if (lang == "ts:lua") {
return "lua";
}
Expand All @@ -131,6 +138,10 @@ detectLanguage(const std::string &stem, const std::string &ext)
return "lua";
}

if (ext == ".sh" || ext == ".bash") {
return "bash";
}

using boost::algorithm::ends_with;
if (ends_with(stem, "makefile") || ext == ".mk" || ext == ".mak") {
return "make";
Expand Down
2 changes: 1 addition & 1 deletion src/tooling/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ parseOptions(const std::vector<std::string> &args,
("color", "force colorization of output")
("lang", po::value<std::string>()->value_name("name")
->default_value({}),
"force specific language (c, cxx, make, lua)");
"force specific language (c, cxx, bash, lua, make)");

po::options_description allOptions;
allOptions.add(options).add(hiddenOpts);
Expand Down

0 comments on commit 159ad2d

Please sign in to comment.