feat(init): add a title field to grammars
This commit is contained in:
parent
4820d50336
commit
46f8d1267c
7 changed files with 32 additions and 6 deletions
|
|
@ -167,6 +167,8 @@ pub struct Grammar {
|
|||
pub name: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub camelcase: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub title: Option<String>,
|
||||
pub scope: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub path: Option<PathBuf>,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ const ABI_VERSION_MAX_PLACEHOLDER: &str = "ABI_VERSION_MAX";
|
|||
|
||||
const PARSER_NAME_PLACEHOLDER: &str = "PARSER_NAME";
|
||||
const CAMEL_PARSER_NAME_PLACEHOLDER: &str = "CAMEL_PARSER_NAME";
|
||||
const TITLE_PARSER_NAME_PLACEHOLDER: &str = "TITLE_PARSER_NAME";
|
||||
const UPPER_PARSER_NAME_PLACEHOLDER: &str = "UPPER_PARSER_NAME";
|
||||
const LOWER_PARSER_NAME_PLACEHOLDER: &str = "LOWER_PARSER_NAME";
|
||||
const KEBAB_PARSER_NAME_PLACEHOLDER: &str = "KEBAB_PARSER_NAME";
|
||||
|
|
@ -119,6 +120,7 @@ pub fn path_in_ignore(repo_path: &Path) -> bool {
|
|||
pub struct JsonConfigOpts {
|
||||
pub name: String,
|
||||
pub camelcase: String,
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub repository: Option<Url>,
|
||||
|
|
@ -143,6 +145,7 @@ impl JsonConfigOpts {
|
|||
grammars: vec![Grammar {
|
||||
name: self.name.clone(),
|
||||
camelcase: Some(self.camelcase),
|
||||
title: Some(self.title),
|
||||
scope: self.scope,
|
||||
path: None,
|
||||
external_files: PathsJSON::Empty,
|
||||
|
|
@ -188,6 +191,7 @@ impl Default for JsonConfigOpts {
|
|||
Self {
|
||||
name: String::new(),
|
||||
camelcase: String::new(),
|
||||
title: String::new(),
|
||||
description: String::new(),
|
||||
repository: None,
|
||||
funding: None,
|
||||
|
|
@ -212,6 +216,7 @@ struct GenerateOpts<'a> {
|
|||
funding: Option<&'a str>,
|
||||
version: &'a Version,
|
||||
camel_parser_name: &'a str,
|
||||
title_parser_name: &'a str,
|
||||
class_name: &'a str,
|
||||
}
|
||||
|
||||
|
|
@ -254,6 +259,10 @@ pub fn generate_grammar_files(
|
|||
.camelcase
|
||||
.clone()
|
||||
.unwrap_or_else(|| language_name.to_upper_camel_case());
|
||||
let title_name = tree_sitter_config.grammars[0]
|
||||
.title
|
||||
.clone()
|
||||
.unwrap_or_else(|| language_name.to_upper_camel_case());
|
||||
let class_name = tree_sitter_config.grammars[0]
|
||||
.class_name
|
||||
.clone()
|
||||
|
|
@ -283,6 +292,7 @@ pub fn generate_grammar_files(
|
|||
.and_then(|l| l.funding.as_ref().map(|f| f.as_str())),
|
||||
version: &tree_sitter_config.metadata.version,
|
||||
camel_parser_name: &camel_name,
|
||||
title_parser_name: &title_name,
|
||||
class_name: &class_name,
|
||||
};
|
||||
|
||||
|
|
@ -702,6 +712,10 @@ fn generate_file(
|
|||
CAMEL_PARSER_NAME_PLACEHOLDER,
|
||||
generate_opts.camel_parser_name,
|
||||
)
|
||||
.replace(
|
||||
TITLE_PARSER_NAME_PLACEHOLDER,
|
||||
generate_opts.title_parser_name,
|
||||
)
|
||||
.replace(
|
||||
UPPER_PARSER_NAME_PLACEHOLDER,
|
||||
&language_name.to_shouty_snake_case(),
|
||||
|
|
|
|||
|
|
@ -534,6 +534,13 @@ impl Init {
|
|||
.interact_text()
|
||||
};
|
||||
|
||||
let title = |name: &str| {
|
||||
Input::<String>::with_theme(&ColorfulTheme::default())
|
||||
.with_prompt("Title (human-readable name)")
|
||||
.default(name.to_upper_camel_case())
|
||||
.interact_text()
|
||||
};
|
||||
|
||||
let description = |name: &str| {
|
||||
Input::<String>::with_theme(&ColorfulTheme::default())
|
||||
.with_prompt("Description")
|
||||
|
|
@ -656,6 +663,7 @@ impl Init {
|
|||
let choices = [
|
||||
"name",
|
||||
"camelcase",
|
||||
"title",
|
||||
"description",
|
||||
"repository",
|
||||
"funding",
|
||||
|
|
@ -674,6 +682,7 @@ impl Init {
|
|||
match $choice {
|
||||
"name" => opts.name = name()?,
|
||||
"camelcase" => opts.camelcase = camelcase_name(&opts.name)?,
|
||||
"title" => opts.title = title(&opts.name)?,
|
||||
"description" => opts.description = description(&opts.name)?,
|
||||
"repository" => opts.repository = Some(repository(&opts.name)?),
|
||||
"funding" => opts.funding = funding()?,
|
||||
|
|
|
|||
|
|
@ -10,6 +10,6 @@ import (
|
|||
func TestCanLoadGrammar(t *testing.T) {
|
||||
language := tree_sitter.NewLanguage(tree_sitter_LOWER_PARSER_NAME.Language())
|
||||
if language == nil {
|
||||
t.Errorf("Error loading CAMEL_PARSER_NAME grammar")
|
||||
t.Errorf("Error loading TITLE_PARSER_NAME grammar")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
//! let language = tree_sitter_PARSER_NAME::LANGUAGE;
|
||||
//! parser
|
||||
//! .set_language(&language.into())
|
||||
//! .expect("Error loading CAMEL_PARSER_NAME parser");
|
||||
//! .expect("Error loading TITLE_PARSER_NAME parser");
|
||||
//! let tree = parser.parse(code, None).unwrap();
|
||||
//! assert!(!tree.root_node().has_error());
|
||||
//! ```
|
||||
|
|
@ -48,6 +48,6 @@ mod tests {
|
|||
let mut parser = tree_sitter::Parser::new();
|
||||
parser
|
||||
.set_language(&super::LANGUAGE.into())
|
||||
.expect("Error loading CAMEL_PARSER_NAME parser");
|
||||
.expect("Error loading TITLE_PARSER_NAME parser");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from unittest import TestCase
|
||||
|
||||
import tree_sitter, tree_sitter_LOWER_PARSER_NAME
|
||||
import tree_sitter
|
||||
import tree_sitter_LOWER_PARSER_NAME
|
||||
|
||||
|
||||
class TestLanguage(TestCase):
|
||||
|
|
@ -8,4 +9,4 @@ class TestLanguage(TestCase):
|
|||
try:
|
||||
tree_sitter.Language(tree_sitter_LOWER_PARSER_NAME.language())
|
||||
except Exception:
|
||||
self.fail("Error loading CAMEL_PARSER_NAME grammar")
|
||||
self.fail("Error loading TITLE_PARSER_NAME grammar")
|
||||
|
|
|
|||
|
|
@ -7,6 +7,6 @@ final class PARSER_CLASS_NAMETests: XCTestCase {
|
|||
let parser = Parser()
|
||||
let language = Language(language: tree_sitter_LOWER_PARSER_NAME())
|
||||
XCTAssertNoThrow(try parser.setLanguage(language),
|
||||
"Error loading CAMEL_PARSER_NAME grammar")
|
||||
"Error loading TITLE_PARSER_NAME grammar")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue