feat: simplify public api

This commit is contained in:
PoiScript 2023-11-17 13:34:06 +08:00
parent 394c013fd2
commit e924359df6
No known key found for this signature in database
GPG key ID: 22C2B1249D99985E
10 changed files with 586 additions and 356 deletions

View file

@ -27,43 +27,17 @@ const nodes = [
first_child: [
["title", "HeadlineTitle"],
["section", "Section"],
["tags", "HeadlineTags"],
["planning", "Planning"],
["priority", "HeadlinePriority"],
],
children: [["headlines", "Headline"]],
token: [
["stars", "HEADLINE_STARS"],
["keyword", "HEADLINE_KEYWORD"],
],
token: [["keyword", "HEADLINE_KEYWORD"]],
post_blank: true,
},
{
struct: "HeadlineStars",
kind: ["HEADLINE_STARS"],
parent: [["headline", "Headline"]],
},
{
struct: "HeadlineTitle",
kind: ["HEADLINE_TITLE"],
parent: [["headline", "Headline"]],
},
{
struct: "HeadlineKeyword",
kind: ["HEADLINE_KEYWORD"],
parent: [["headline", "Headline"]],
},
{
struct: "HeadlinePriority",
kind: ["HEADLINE_PRIORITY"],
parent: [["headline", "Headline"]],
token: [["text", "TEXT"]],
},
{
struct: "HeadlineTags",
kind: ["HEADLINE_TAGS"],
parent: [["headline", "Headline"]],
},
{
struct: "PropertyDrawer",
kind: ["PROPERTY_DRAWER"],
@ -76,23 +50,6 @@ const nodes = [
{
struct: "Planning",
kind: ["PLANNING"],
last_child: [
["deadline", "PlanningDeadline"],
["scheduled", "PlanningScheduled"],
["closed", "PlanningClosed"],
],
},
{
struct: "PlanningDeadline",
kind: ["PLANNING_DEADLINE"],
},
{
struct: "PlanningScheduled",
kind: ["PLANNING_SCHEDULED"],
},
{
struct: "PlanningClosed",
kind: ["PLANNING_CLOSED"],
},
{
struct: "OrgTable",
@ -118,26 +75,6 @@ const nodes = [
struct: "ListItem",
kind: ["LIST_ITEM"],
first_child: [["content", "ListItemContent"]],
token: [
["indent", "LIST_ITEM_INDENT"],
["bullet", "LIST_ITEM_BULLET"],
],
},
{
struct: "ListItemIndent",
kind: ["LIST_ITEM_INDENT"],
},
{
struct: "ListItemTag",
kind: ["LIST_ITEM_TAG"],
},
{
struct: "ListItemBullet",
kind: ["LIST_ITEM_BULLET"],
},
{
struct: "ListItemContent",
kind: ["LIST_ITEM_CONTENT"],
},
{
struct: "Drawer",
@ -357,7 +294,14 @@ impl AstNode for ${node.struct} {
}> { Self::can_cast(node.kind()).then(|| ${node.struct} { syntax: node }) }
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl ${node.struct} {\n`;
impl ${node.struct} {
pub fn begin(&self) -> u32 {
self.syntax.text_range().start().into()
}
pub fn end(&self) -> u32 {
self.syntax.text_range().end().into()
}
`;
for (const [method, kind] of node.token || []) {
content += ` pub fn ${method}(&self) -> Option<SyntaxToken> { support::token(&self.syntax, ${kind}) }\n`;
}