Skip to content

Commit

Permalink
Add Nuget Config, Bazel and EdgeQL Support, Fix Output Formatter (#999)
Browse files Browse the repository at this point in the history
* add nuget configuration support

* fix test file

* add bazel language

* fix output format

* add languages to readme

* fix serialize

* add edgeql

* edit readme

* add test file

* fix edgedb
  • Loading branch information
Embers-of-the-Fire authored May 24, 2023
1 parent 3b3ea97 commit 21be04c
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 6 deletions.
7 changes: 4 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,13 @@ fn foo() {
Please include the error message and a minimum working example
including the file or file structure.

```
````
This file crashes the program:
<filename>
\`\`\`
\`\`\`
```
<file/file structure>
```
````

[Rust's enum style]: https://github.com/rust-lang/rfcs/blob/master/text/0430-finalizing-naming-conventions.md#general-naming-conventions
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ Automake
AWK
Bash
Batch
Bazel
Bean
Bitbake
BrightScript
C
Cabal
Expand Down Expand Up @@ -355,6 +358,8 @@ Dockerfile
DotNetResource
DreamMaker
Dust
Ebuild
EdgeDB
Edn
Elisp
Elixir
Expand Down Expand Up @@ -430,6 +435,7 @@ Mustache
Nim
Nix
NotQuitePerl
NuGetConfig
Nushell
ObjectiveC
ObjectiveCpp
Expand Down
25 changes: 25 additions & 0 deletions languages.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@
"line_comment": ["REM", "::"],
"extensions": ["bat", "btm", "cmd"]
},
"Bazel": {
"line_comment": ["#"],
"doc_quotes": [["\\\"\\\"\\\"", "\\\"\\\"\\\""], ["'''", "'''"]],
"quotes": [["\\\"", "\\\""], ["'", "'"]],
"extensions": ["bzl", "bazel"],
"filenames": ["build", "workspace"]
},
"Bean": {
"line_comment": [";"],
"quotes": [["\\\"", "\\\""]],
Expand Down Expand Up @@ -368,6 +375,18 @@
"quotes": [["\\\"", "\\\""], ["'", "'"]],
"extensions": ["ebuild", "eclass"]
},
"EdgeQL": {
"name": "EdgeQL",
"line_comment": ["#"],
"quotes": [["'", "'"], ["\\\"", "\\\""], ["$", "$"]],
"extensions": ["edgeql"]
},
"ESDL": {
"name": "EdgeDB Schema Definition",
"line_comment": ["#"],
"quotes": [["'", "'"], ["\\\"", "\\\""]],
"extensions": ["esdl"]
},
"Edn": {
"line_comment": [";"],
"extensions": ["edn"]
Expand Down Expand Up @@ -953,6 +972,12 @@
"quotes": [["\\\"", "\\\""], ["'", "'"]],
"extensions": ["nqp"]
},
"NuGetConfig": {
"name": "NuGet Config",
"multi_line_comments": [["<!--", "-->"]],
"quotes": [["\\\"", "\\\""], ["'", "'"]],
"filenames": ["nuget.config", "packages.config", "nugetdefaults.config"]
},
"Nushell": {
"line_comment": ["#"],
"quotes": [
Expand Down
9 changes: 9 additions & 0 deletions src/language/language_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ use crate::{
use encoding_rs_io::DecodeReaderBytesBuilder;
use grep_searcher::{LineIter, LineStep};
use rayon::prelude::*;
use serde::Serialize;

use self::LanguageType::*;

include!(concat!(env!("OUT_DIR"), "/language_type.rs"));

impl Serialize for LanguageType {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer {
serializer.serialize_str(self.name())
}
}

impl LanguageType {
/// Parses a given [`Path`] using the [`LanguageType`]. Returning [`Report`]
/// on success and giving back ownership of [`PathBuf`] on error.
Expand Down
6 changes: 3 additions & 3 deletions src/language/language_type.tera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use arbitrary::Arbitrary;
/// information about the language, such as multi line comments, single line
/// comments, string literal syntax, whether a given language allows nesting
/// comments.
#[derive(Deserialize, Serialize)]
#[derive(Deserialize)]
#[derive(Arbitrary, Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[non_exhaustive]
#[allow(clippy::upper_case_acronyms)]
pub enum LanguageType {
{% for key, _ in languages -%}
#[allow(missing_docs)] {{key}},
{% for key, value in languages -%}
#[allow(missing_docs)] {% if value.name is defined %} #[serde(alias = "{{value.name}}")] {% else %} #[serde(alias = "{{key}}")] {% endif %} {{key}},
{% endfor %}
}

Expand Down
24 changes: 24 additions & 0 deletions tests/data/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- 24 lines 13 code 8 comments 3 blanks -->

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- defaultPushSource key works like the 'defaultPushSource' key of NuGet.Config files. -->
<!-- This can be used by administrators to prevent accidental publishing of packages to nuget.org. -->
<config>
<add key="defaultPushSource" value="https://contoso.com/packages/" />
</config>

<!-- Default Package Sources; works like the 'packageSources' section of NuGet.Config files. -->
<!-- This collection cannot be deleted or modified but can be disabled/enabled by users. -->
<packageSources>
<add key="Contoso Package Source" value="https://contoso.com/packages/" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>

<!-- Default Package Sources that are disabled by default. -->
<!-- Works like the 'disabledPackageSources' section of NuGet.Config files. -->
<!-- Sources cannot be modified or deleted either but can be enabled/disabled by users. -->
<disabledPackageSources>
<add key="nuget.org" value="true" />
</disabledPackageSources>
</configuration>
18 changes: 18 additions & 0 deletions tests/data/bazel.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 18 lines 13 code 3 comments 2 blanks

# build hello-greet
cc_library(
name = "hello-greet",
srcs = ["hello-greet.cc"],
hdrs = ["hello-greet.h"],
)

# build hello-world
cc_binary(
name = "hello-world",
srcs = ["hello-world.cc"],
deps = [
":hello-greet",
"//lib:hello-time",
],
)
28 changes: 28 additions & 0 deletions tests/data/edgeql.edgeql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 28 lines 21 code 3 comments 4 blanks

select User {
name,
friends: {
name
},
has_i := .friends.name ilike '%i%',
has_o := .friends.name ilike '%o%',
} filter .has_i or .has_o;

select <User>{} ?? User {name};

# update the user with the name 'Alice Smith'
with module example
update User
filter .name = 'Alice Smith'
set {
name := 'Alice J. Smith'
};

# update all users whose name is 'Bob'
with module example
update User
filter .name like 'Bob%'
set {
name := User.name ++ '*'
};
20 changes: 20 additions & 0 deletions tests/data/esdl.esdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 20 lines 13 code 4 comments 3 blanks

# no module block
type default::Movie {
required property title -> str;
# the year of release
property year -> int64;
required link director -> default::Person;
required multi link actors -> default::Person;
}

type default::Person {
required property first_name -> str;
required property last_name -> str;
}

abstract link friends_base {
# declare a specific title for the link
annotation title := 'Close contacts';
}

0 comments on commit 21be04c

Please sign in to comment.