Initial Dever 0.0.1
This commit is contained in:
commit
81233d098c
1479 files changed
+163782
No files matched your search
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1,8 @@
|
||||
# 集合处理
|
||||
|
||||
筛选已发布文章,整理标题并计算总长度。
|
||||
|
||||
- [文章汇总命令](doc/api.md)
|
||||
- [业务操作](doc/app.md)
|
||||
- [内部规则](doc/domain.md)
|
||||
- [调用流程](link.md)
|
||||
@@ -0,0 +1 @@
|
||||
cmd summarize = app.summarize
|
||||
@@ -0,0 +1,18 @@
|
||||
type Article {
|
||||
title: Text
|
||||
published: Bool
|
||||
}
|
||||
|
||||
type Summary {
|
||||
titles: List<Text>
|
||||
title_length: Int
|
||||
}
|
||||
|
||||
summarize(articles: List<Article>) (summary: Summary) {
|
||||
published = filter(domain.isPublished, articles)
|
||||
titles = each(domain.publishedTitle, published)
|
||||
summary = Summary {
|
||||
titles = titles
|
||||
title_length = reduce(domain.addTitleLength, titles, 0)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
# 文章汇总命令
|
||||
|
||||
## content.article.api.summarize
|
||||
|
||||
筛选已发布文章并统计标题。
|
||||
@@ -0,0 +1,13 @@
|
||||
# 业务操作
|
||||
|
||||
## content.article.Article
|
||||
|
||||
用于集合处理示例的文章标题和发布标记。
|
||||
|
||||
## content.article.Summary
|
||||
|
||||
筛选后的标题列表及标题总长度。
|
||||
|
||||
## content.article.summarize
|
||||
|
||||
选出已发布且标题非空白的文章,去掉标题两端空白,并累计标题长度。
|
||||
@@ -0,0 +1,13 @@
|
||||
# 内部规则
|
||||
|
||||
## content.article.domain.isPublished
|
||||
|
||||
检查文章已发布且标题不是空白。
|
||||
|
||||
## content.article.domain.publishedTitle
|
||||
|
||||
去掉文章标题两端空白。
|
||||
|
||||
## content.article.domain.addTitleLength
|
||||
|
||||
把当前标题的字符数加入累计值。
|
||||
@@ -0,0 +1,11 @@
|
||||
isPublished(article: app.Article) (selected: Bool) pure {
|
||||
selected = article.published and text.trim(article.title) != ""
|
||||
}
|
||||
|
||||
publishedTitle(article: app.Article) (title: Text) pure {
|
||||
title = text.trim(article.title)
|
||||
}
|
||||
|
||||
addTitleLength(title: Text, total: Int) (next: Int) pure {
|
||||
next = total + length(title)
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
<!-- Generated by dever inspect --links. Do not edit. -->
|
||||
<!-- source-sha256: 34a9b8f6199b0fb7fa26e50e29915dd0df8c9c5e142fa23a7f2a5fdd24572ef7 -->
|
||||
|
||||
# content.article
|
||||
|
||||
按求值顺序展示调用、分支和任务调度,包含 API 与自动 REST 入口。点击节点打开源码;双框为调用,虚线为调度或错误路径。外部库和驱动不展开。
|
||||
|
||||
图不是某次运行的日志,分句和 Adapter 按输入或配置选择。修改源码后运行 `dever inspect . --links`。
|
||||
|
||||
## 入口
|
||||
|
||||
- CMD [content.article.api.summarize](api.dever#L1) → [content.article.summarize](app.dever#L11)
|
||||
|
||||
## 外部调用方
|
||||
|
||||
当前加载的源码中没有已收录的外部调用。
|
||||
|
||||
## 能力与内部调用
|
||||
|
||||
### content.article.Article
|
||||
|
||||
定义:[app.dever:1:1](app.dever#L1,1)
|
||||
|
||||
没有已收录的下游调用。
|
||||
|
||||
### content.article.Summary
|
||||
|
||||
定义:[app.dever:6:1](app.dever#L6,1)
|
||||
|
||||
没有已收录的下游调用。
|
||||
|
||||
### content.article.api.summarize
|
||||
|
||||
定义:[api.dever:1:1](api.dever#L1,1)
|
||||
|
||||
<a id="flow-3c3fded4eed8bf7d-1"></a>
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
n0(["content.article.api.summarize"])
|
||||
click n0 href "api.dever#L1,17" "打开源码"
|
||||
n1[["content.article.summarize"]]
|
||||
click n1 href "api.dever#L1,17" "打开源码"
|
||||
n2(["返回命令结果;未捕获错误终止命令"])
|
||||
n0 --> n1
|
||||
n1 --> n2
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>源码与子流程</summary>
|
||||
|
||||
| 节点 | 源码 | 子流程 |
|
||||
| --- | --- | --- |
|
||||
| content.article.summarize | [api.dever:1:17](api.dever#L1,17) | [content.article.summarize](link.md#flow-61067b9f346a3099-1) |
|
||||
|
||||
</details>
|
||||
|
||||
| 目标 | 归属 | 方式 | 调用位置 |
|
||||
| --- | --- | --- | --- |
|
||||
| [content.article.summarize](app.dever#L11) | 领域内 | CMD 绑定 | [api.dever:1:17](api.dever#L1,17) |
|
||||
|
||||
### content.article.domain.addTitleLength
|
||||
|
||||
定义:[domain.dever:9:1](domain.dever#L9,1)
|
||||
|
||||
<a id="flow-ae94676d0264c9fd-1"></a>
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
n0(["addTitleLength"])
|
||||
click n0 href "domain.dever#L9,1" "打开源码"
|
||||
n1(["返回"])
|
||||
n3["赋值 next"]
|
||||
click n3 href "domain.dever#L10,10" "打开源码"
|
||||
n0 --> n3
|
||||
n3 --> n1
|
||||
```
|
||||
|
||||
没有已收录的下游调用。
|
||||
|
||||
### content.article.domain.isPublished
|
||||
|
||||
定义:[domain.dever:1:1](domain.dever#L1,1)
|
||||
|
||||
<a id="flow-424569accb37593c-1"></a>
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
n0(["isPublished"])
|
||||
click n0 href "domain.dever#L1,1" "打开源码"
|
||||
n1(["返回"])
|
||||
n3{"article.published"}
|
||||
click n3 href "domain.dever#L2,14" "打开源码"
|
||||
n4["求右侧值"]
|
||||
click n4 href "domain.dever#L2,36" "打开源码"
|
||||
n5["短路表达式结果"]
|
||||
click n5 href "domain.dever#L2,14" "打开源码"
|
||||
n6[["text.trim"]]
|
||||
click n6 href "domain.dever#L2,36" "打开源码"
|
||||
n7["赋值 selected"]
|
||||
click n7 href "domain.dever#L2,14" "打开源码"
|
||||
n0 --> n3
|
||||
n3 -->|"true"| n4
|
||||
n3 -->|"false:跳过右侧"| n5
|
||||
n4 --> n6
|
||||
n6 --> n5
|
||||
n5 --> n7
|
||||
n7 --> n1
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>源码与子流程</summary>
|
||||
|
||||
| 节点 | 源码 | 子流程 |
|
||||
| --- | --- | --- |
|
||||
| text.trim | [domain.dever:2:36](domain.dever#L2,36) | 依赖或生成的分派(本页不展开) |
|
||||
|
||||
</details>
|
||||
|
||||
| 目标 | 归属 | 方式 | 调用位置 |
|
||||
| --- | --- | --- | --- |
|
||||
| `text.trim` | 依赖 | 调用 | [domain.dever:2:36](domain.dever#L2,36) |
|
||||
|
||||
### content.article.domain.publishedTitle
|
||||
|
||||
定义:[domain.dever:5:1](domain.dever#L5,1)
|
||||
|
||||
<a id="flow-e1432830e4785e97-1"></a>
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
n0(["publishedTitle"])
|
||||
click n0 href "domain.dever#L5,1" "打开源码"
|
||||
n1(["返回"])
|
||||
n3[["text.trim"]]
|
||||
click n3 href "domain.dever#L6,11" "打开源码"
|
||||
n4["赋值 title"]
|
||||
click n4 href "domain.dever#L6,11" "打开源码"
|
||||
n0 --> n3
|
||||
n3 --> n4
|
||||
n4 --> n1
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>源码与子流程</summary>
|
||||
|
||||
| 节点 | 源码 | 子流程 |
|
||||
| --- | --- | --- |
|
||||
| text.trim | [domain.dever:6:11](domain.dever#L6,11) | 依赖或生成的分派(本页不展开) |
|
||||
|
||||
</details>
|
||||
|
||||
| 目标 | 归属 | 方式 | 调用位置 |
|
||||
| --- | --- | --- | --- |
|
||||
| `text.trim` | 依赖 | 调用 | [domain.dever:6:11](domain.dever#L6,11) |
|
||||
|
||||
### content.article.summarize
|
||||
|
||||
定义:[app.dever:11:1](app.dever#L11,1)
|
||||
|
||||
<a id="flow-61067b9f346a3099-1"></a>
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
n0(["summarize"])
|
||||
click n0 href "app.dever#L11,1" "打开源码"
|
||||
n1(["返回"])
|
||||
n3{"还有元素?"}
|
||||
click n3 href "app.dever#L12,42" "打开源码"
|
||||
n4["集合操作结果"]
|
||||
click n4 href "app.dever#L12,15" "打开源码"
|
||||
n5["取下一元素"]
|
||||
click n5 href "app.dever#L12,15" "打开源码"
|
||||
n6[["content.article.domain.isPublished"]]
|
||||
click n6 href "app.dever#L12,15" "打开源码"
|
||||
n7["赋值 published"]
|
||||
click n7 href "app.dever#L12,15" "打开源码"
|
||||
n8{"还有元素?"}
|
||||
click n8 href "app.dever#L13,40" "打开源码"
|
||||
n9["集合操作结果"]
|
||||
click n9 href "app.dever#L13,12" "打开源码"
|
||||
n10["取下一元素"]
|
||||
click n10 href "app.dever#L13,12" "打开源码"
|
||||
n11[["content.article.domain.publishedTitle"]]
|
||||
click n11 href "app.dever#L13,12" "打开源码"
|
||||
n12["赋值 titles"]
|
||||
click n12 href "app.dever#L13,12" "打开源码"
|
||||
n13{"还有元素?"}
|
||||
click n13 href "app.dever#L16,50" "打开源码"
|
||||
n14["集合操作结果"]
|
||||
click n14 href "app.dever#L16,20" "打开源码"
|
||||
n15["取下一元素"]
|
||||
click n15 href "app.dever#L16,20" "打开源码"
|
||||
n16[["content.article.domain.addTitleLength"]]
|
||||
click n16 href "app.dever#L16,20" "打开源码"
|
||||
n17["赋值 summary"]
|
||||
click n17 href "app.dever#L14,13" "打开源码"
|
||||
n0 -->|"开始遍历"| n3
|
||||
n3 -->|"否(包括空集合)"| n4
|
||||
n3 -->|"是"| n5
|
||||
n5 --> n6
|
||||
n6 -->|"下一元素"| n3
|
||||
n4 --> n7
|
||||
n7 -->|"开始遍历"| n8
|
||||
n8 -->|"否(包括空集合)"| n9
|
||||
n8 -->|"是"| n10
|
||||
n10 --> n11
|
||||
n11 -->|"下一元素"| n8
|
||||
n9 --> n12
|
||||
n12 -->|"开始遍历"| n13
|
||||
n13 -->|"否(包括空集合)"| n14
|
||||
n13 -->|"是"| n15
|
||||
n15 --> n16
|
||||
n16 -->|"下一元素"| n13
|
||||
n14 --> n17
|
||||
n17 --> n1
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>源码与子流程</summary>
|
||||
|
||||
| 节点 | 源码 | 子流程 |
|
||||
| --- | --- | --- |
|
||||
| content.article.domain.isPublished | [app.dever:12:15](app.dever#L12,15) | [content.article.domain.isPublished](link.md#flow-424569accb37593c-1) |
|
||||
| content.article.domain.publishedTitle | [app.dever:13:12](app.dever#L13,12) | [content.article.domain.publishedTitle](link.md#flow-e1432830e4785e97-1) |
|
||||
| content.article.domain.addTitleLength | [app.dever:16:20](app.dever#L16,20) | [content.article.domain.addTitleLength](link.md#flow-ae94676d0264c9fd-1) |
|
||||
|
||||
</details>
|
||||
|
||||
| 目标 | 归属 | 方式 | 调用位置 |
|
||||
| --- | --- | --- | --- |
|
||||
| [content.article.domain.isPublished](domain.dever#L1) | 领域内 | 集合回调 | [app.dever:12:22](app.dever#L12,22) |
|
||||
| [content.article.domain.publishedTitle](domain.dever#L5) | 领域内 | 集合回调 | [app.dever:13:17](app.dever#L13,17) |
|
||||
| [content.article.domain.addTitleLength](domain.dever#L9) | 领域内 | 集合回调 | [app.dever:16:27](app.dever#L16,27) |
|
||||
@@ -0,0 +1,43 @@
|
||||
type State {
|
||||
Draft
|
||||
Published
|
||||
Rejected(reason: Text)
|
||||
}
|
||||
|
||||
clauses() () {
|
||||
assertEq(label(State.Draft), "draft")
|
||||
assertEq(label(State.Published), "published")
|
||||
assertEq(label(State.Rejected("needs revision")), "needs revision")
|
||||
assertEq(display(null), "missing")
|
||||
assertEq(display("present"), "present")
|
||||
assertEq(grade(59), "fail")
|
||||
assertEq(grade(60), "pass")
|
||||
}
|
||||
|
||||
label(state: State.Published) (text: Text) {
|
||||
text = "published"
|
||||
}
|
||||
|
||||
label(state: State.Rejected(reason)) (text: Text) {
|
||||
text = reason
|
||||
}
|
||||
|
||||
label(state: other) (text: Text) {
|
||||
text = "draft"
|
||||
}
|
||||
|
||||
display(value: Text) (text: Text) {
|
||||
text = value
|
||||
}
|
||||
|
||||
display(value: null) (text: Text) {
|
||||
text = "missing"
|
||||
}
|
||||
|
||||
grade(score: Int<60) (text: Text) {
|
||||
text = "fail"
|
||||
}
|
||||
|
||||
grade(score: Int >= 60) (text: Text) {
|
||||
text = "pass"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
summary() () {
|
||||
articles = [
|
||||
app.Article {
|
||||
title = " First "
|
||||
published = true
|
||||
},
|
||||
app.Article {
|
||||
title = "Hidden"
|
||||
published = false
|
||||
},
|
||||
app.Article {
|
||||
title = " "
|
||||
published = true
|
||||
},
|
||||
app.Article {
|
||||
title = "Second"
|
||||
published = true
|
||||
}
|
||||
]
|
||||
actual = app.summarize(articles)
|
||||
assertEq(actual.titles, ["First", "Second"])
|
||||
assertEq(actual.title_length, 11)
|
||||
each(assertCleanTitle, actual.titles)
|
||||
empty = app.summarize([])
|
||||
assertEq(empty.titles, [])
|
||||
assertEq(empty.title_length, 0)
|
||||
}
|
||||
|
||||
assertCleanTitle(title: Text) () {
|
||||
assert(title != "")
|
||||
assertEq(title, text.trim(title))
|
||||
}
|
||||
Reference in new issue
Block a user