Merge branch 'master' into node-fields

This commit is contained in:
Max Brunsfeld 2019-02-14 09:35:47 -08:00
commit 4f069fbe3b
9 changed files with 40 additions and 37 deletions

View file

@ -1,7 +1,7 @@
[package]
name = "tree-sitter-cli"
description = "CLI tool for developing, testing, and using Tree-sitter parsers"
version = "0.14.3"
version = "0.14.4"
authors = ["Max Brunsfeld <maxbrunsfeld@gmail.com>"]
edition = "2018"
license = "MIT"

View file

@ -168,6 +168,6 @@ fn parse(parser: &mut Parser, example_path: &Path, max_path_length: usize) -> us
fn get_language(name: &str) -> Language {
let src_dir = GRAMMARS_DIR.join(name).join("src");
TEST_LOADER
.load_language_at_path(name, &src_dir, &src_dir)
.load_language_at_path(&src_dir, &src_dir)
.unwrap()
}

View file

@ -1,5 +1,5 @@
{
"name": "tree-sitter-cli",
"version": "0.14.3",
"version": "0.14.4",
"lockfileVersion": 1
}

View file

@ -1,6 +1,6 @@
{
"name": "tree-sitter-cli",
"version": "0.14.3",
"version": "0.14.4",
"author": "Max Brunsfeld",
"license": "MIT",
"repository": {

View file

@ -3,6 +3,7 @@ use libloading::{Library, Symbol};
use regex::{Regex, RegexBuilder};
use serde_derive::Deserialize;
use std::collections::HashMap;
use std::io::BufReader;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::time::SystemTime;
@ -18,7 +19,6 @@ const DYLIB_EXTENSION: &'static str = "dll";
const BUILD_TARGET: &'static str = env!("BUILD_TARGET");
struct LanguageRepo {
name: String,
path: PathBuf,
language: Option<Language>,
configurations: Vec<LanguageConfiguration>,
@ -109,35 +109,42 @@ impl Loader {
language
} else {
let src_path = repo.path.join("src");
let language = self.load_language_at_path(&repo.name, &src_path, &src_path)?;
let language = self.load_language_at_path(&src_path, &src_path)?;
self.language_repos[id].language = Some(language);
language
};
Ok((language, &self.language_repos[id].configurations))
}
pub fn load_language_at_path(
&self,
name: &str,
src_path: &Path,
header_path: &Path,
) -> Result<Language> {
pub fn load_language_at_path(&self, src_path: &Path, header_path: &Path) -> Result<Language> {
let grammar_path = src_path.join("grammar.json");
let parser_path = src_path.join("parser.c");
let mut scanner_path = src_path.join("scanner.c");
let scanner_path;
let scanner_c_path = src_path.join("scanner.c");
if scanner_c_path.exists() {
scanner_path = Some(scanner_c_path);
} else {
let scanner_cc_path = src_path.join("scanner.cc");
if scanner_cc_path.exists() {
scanner_path = Some(scanner_cc_path);
} else {
scanner_path = None;
}
#[derive(Deserialize)]
struct GrammarJSON {
name: String,
}
let mut grammar_file = fs::File::open(grammar_path)?;
let grammar_json: GrammarJSON = serde_json::from_reader(BufReader::new(&mut grammar_file))?;
self.load_language_from_sources(name, &header_path, &parser_path, &scanner_path)
let scanner_path = if scanner_path.exists() {
Some(scanner_path)
} else {
scanner_path.set_extension("cc");
if scanner_path.exists() {
Some(scanner_path)
} else {
None
}
};
self.load_language_from_sources(
&grammar_json.name,
&header_path,
&parser_path,
&scanner_path,
)
}
pub fn load_language_from_sources(
@ -236,7 +243,6 @@ impl Loader {
#[derive(Deserialize)]
struct PackageJSON {
name: String,
#[serde(rename = "tree-sitter")]
tree_sitter: Option<Vec<LanguageConfigurationJSON>>,
}
@ -272,11 +278,6 @@ impl Loader {
}
self.language_repos.push(LanguageRepo {
name: package_json
.name
.split_at("tree-sitter-".len())
.1
.to_string(),
path: parser_path.to_owned(),
language: None,
configurations,

View file

@ -16,7 +16,7 @@ pub fn fixtures_dir<'a>() -> &'static Path {
pub fn get_language(name: &str) -> Language {
TEST_LOADER
.load_language_at_path(name, &GRAMMARS_DIR.join(name).join("src"), &HEADER_DIR)
.load_language_at_path(&GRAMMARS_DIR.join(name).join("src"), &HEADER_DIR)
.unwrap()
}