summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWu Tingfeng <wu.tingfeng@u.nus.edu>2023-04-25 15:42:32 +0800
committerGitHub <noreply@github.com>2023-04-25 09:42:32 +0200
commit8f286cc669f0d0af56487b76be1ed62bd579ac87 (patch)
tree6cbcaf9b917176f6935da86aa40d56bfbf3cce50
parentebf199b341e9901cbd607e6d85095c11919722ec (diff)
Add JSON5 support for languages.json (#986)
-rw-r--r--Cargo.lock12
-rw-r--r--Cargo.toml1
-rw-r--r--build.rs6
3 files changed, 17 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a9634b9..c12f597 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -609,6 +609,17 @@ dependencies = [
]
[[package]]
+name = "json5"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1"
+dependencies = [
+ "pest",
+ "pest_derive",
+ "serde",
+]
+
+[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1338,6 +1349,7 @@ dependencies = [
"grep-searcher",
"hex",
"ignore",
+ "json5",
"log",
"num-format",
"once_cell",
diff --git a/Cargo.toml b/Cargo.toml
index dd2a581..f1a6874 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -35,6 +35,7 @@ panic = "abort"
tera = "1.15"
ignore = "0.4"
serde_json = "1"
+json5 = "0.4"
[dependencies]
aho-corasick = "0.7"
diff --git a/build.rs b/build.rs
index f692220..73ce01f 100644
--- a/build.rs
+++ b/build.rs
@@ -1,8 +1,9 @@
extern crate ignore;
extern crate serde_json;
+extern crate json5;
use std::ffi::OsStr;
-use std::fs::{self, File};
+use std::fs;
use std::path::Path;
use std::{cmp, env, error};
@@ -20,7 +21,8 @@ fn main() -> Result<(), Box<dyn error::Error>> {
fn generate_languages(out_dir: &OsStr) -> Result<(), Box<dyn error::Error>> {
let mut tera = tera::Tera::default();
- let mut json: Value = serde_json::from_reader(File::open(&"languages.json")?)?;
+ let json_string: String = fs::read_to_string("languages.json")?.parse()?;
+ let mut json: Value = json5::from_str(&json_string)?;
for (_key, ref mut item) in json
.get_mut("languages")