diff --git a/.agents/skills/humanizer-zh/.gitignore b/.agents/skills/humanizer-zh/.gitignore new file mode 100644 index 0000000..c8f86e9 --- /dev/null +++ b/.agents/skills/humanizer-zh/.gitignore @@ -0,0 +1,6 @@ +.DS_Store +*.swp +*.swo +*~ +.vscode/ +.idea/ diff --git a/.agents/skills/humanizer-zh/LICENSE b/.agents/skills/humanizer-zh/LICENSE new file mode 100644 index 0000000..e43848a --- /dev/null +++ b/.agents/skills/humanizer-zh/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 歸藏 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/.agents/skills/humanizer-zh/README.md b/.agents/skills/humanizer-zh/README.md new file mode 100644 index 0000000..318f7ba --- /dev/null +++ b/.agents/skills/humanizer-zh/README.md @@ -0,0 +1,239 @@ +# Humanizer-zh: AI 写作去痕工具(中文版) + +> **声明:** +> - 本项目的核心文件翻译自 [blader/humanizer](https://github.com/blader/humanizer/tree/main) +> - 实用工具部分(核心规则、快速检查清单、质量评分)参考了 [hardikpandya/stop-slop](https://github.com/hardikpandya/stop-slop) +> - 原项目基于维基百科的 [Signs of AI writing](https://en.wikipedia.org/wiki/Wikipedia:Signs_of_AI_writing) 指南 + +--- + +## 项目简介 + +Humanizer-zh 是一个用于去除文本中 AI 生成痕迹的工具,帮助你将 AI 生成的内容改写得更自然、更像人类书写的文本。 + +本项目适用于: +- 编辑和审阅 AI 生成的内容 +- 提升文章的人性化程度 +- 学习识别 AI 写作的常见模式 + +## 安装 + +### 方法一:通过 npx 一键安装(推荐) + +```bash +npx skills add https://github.com/op7418/Humanizer-zh.git +``` + +这是最简单的安装方式,会自动将技能安装到正确的目录。 + +### 方法二:通过 Git 克隆 + +```bash +# 克隆到 Claude Code 的 skills 目录 +git clone https://github.com/op7418/Humanizer-zh.git ~/.claude/skills/humanizer-zh +``` + +### 方法三:手动安装 + +1. 下载本项目的 ZIP 文件或克隆到本地 +2. 将 `Humanizer-zh` 文件夹复制到 Claude Code 的 skills 目录: + - **macOS/Linux**: `~/.claude/skills/` + - **Windows**: `%USERPROFILE%\.claude\skills\` + +3. 确保文件夹结构如下: + ``` + ~/.claude/skills/humanizer-zh/ + ├── SKILL.md # 技能定义文件(中文版) + └── README.md # 说明文档 + ``` + +### 验证安装 + +重启 Claude Code 或重新加载 skills 后,在对话中输入: + +``` +/humanizer-zh +``` + +如果安装成功,该技能将被激活。 + +## 使用 + +### 基础用法 + +在 Claude Code 中,你可以通过以下方式使用 Humanizer: + +#### 1. 直接调用技能 + +``` +/humanizer-zh 请帮我人性化以下文本: + +[粘贴你的 AI 生成文本] +``` + +#### 2. 在对话中使用 + +``` +请用 humanizer 帮我改写这段话,让它更自然: + +这个项目作为我们团队致力于创新的证明。此外,它展示了我们在不断演变的技术格局中的关键作用。 +``` + +#### 3. 处理文件内容 + +``` +/humanizer-zh 请人性化 article.md 文件中的内容 +``` + +### 使用场景示例 + +#### 场景 1:改写营销文案 + +**输入:** +``` +/humanizer-zh +坐落在风景如画的杭州市中心,这家咖啡馆拥有丰富的文化底蕴和令人叹为观止的装饰。它作为城市咖啡文化的焦点,为顾客提供无缝、直观和充满活力的体验。 +``` + +**输出示例:** +> 这家咖啡馆在杭州市中心开了三年,以手冲咖啡和老建筑改造的空间出名。 + +#### 场景 2:改写学术摘要 + +**输入:** +``` +/humanizer-zh +本研究深入探讨了机器学习在医疗诊断中的关键作用,突出了其在不断演变的医疗格局中的重要性。此外,它为该领域的未来发展奠定了坚实的基础。 +``` + +**输出示例:** +> 本研究分析了机器学习在医疗诊断中的应用,重点是肺癌早期筛查。研究使用了 2019-2023 年间 5000 例病历数据。 + +#### 场景 3:改写博客文章 + +**输入:** +``` +/humanizer-zh +人工智能不仅仅是一种技术,它是我们思考未来的方式的革命。行业专家认为这将对整个社会产生持久影响。 +``` + +**输出示例:** +> 我一直在想 AI 会怎么改变我们的工作方式。上周和几个做产品的朋友聊,有人觉得很兴奋,有人担心失业,大概率真相在中间某个无聊的地方。 + +## 检测的 AI 写作模式 + +本工具能够识别并修复 **24 种** AI 写作痕迹,分为四大类: + +### 📝 内容模式(6种) +1. 过度强调意义、遗产和更广泛的趋势 +2. 过度强调知名度和媒体报道 +3. 以 -ing 结尾的肤浅分析 +4. 宣传和广告式语言 +5. 模糊归因和含糊措辞 +6. 提纲式的"挑战与未来展望"部分 + +### 🔤 语言和语法模式(6种) +7. 过度使用的"AI 词汇" +8. 避免使用"是"(系动词回避) +9. 否定式排比 +10. 三段式法则过度使用 +11. 刻意换词(同义词循环) +12. 虚假范围 + +### 🎨 风格模式(6种) +13. 破折号过度使用 +14. 粗体过度使用 +15. 内联标题垂直列表 +16. 标题中的标题大写 +17. 表情符号 +18. 弯引号 + +### 💬 交流模式和填充词(6种) +19. 协作交流痕迹 +20. 知识截止日期免责声明 +21. 谄媚/卑躬屈膝的语气 +22. 填充短语 +23. 过度限定 +24. 通用积极结论 + +## 文件说明 + +- **`SKILL.md`** - 中文版技能定义文件 +- **`README.md`** - 本说明文档 + +**注:** 英文原版请参考 [blader/humanizer](https://github.com/blader/humanizer) + +## 手动使用方法 + +### 基本流程 + +1. **识别 AI 模式** - 对照 `SKILL.md` 中列出的 24 种模式扫描文本 +2. **重写问题片段** - 用自然的表达替换 AI 痕迹 +3. **保留核心含义** - 确保信息完整性 +4. **维持适当语调** - 匹配文本应有的风格 +5. **注入真实个性** - 让文字有"人味" + +### 关键原则 + +#### ✨ 不仅要"干净",更要"鲜活" + +避免 AI 模式只是基础,好的写作需要真实的人类声音: + +- **有观点** - 不要只报告事实,要对它们做出反应 +- **变化节奏** - 混合使用长短句 +- **承认复杂性** - 真实的人有复杂感受 +- **适当使用"我"** - 第一人称是诚实的表现 +- **允许一些混乱** - 完美的结构反而显得机械 +- **对感受要具体** - 用具体细节替代抽象概括 + +#### 示例对比 + +**改写前(AI 味道):** +> 新的软件更新作为公司致力于创新的证明。此外,它提供了无缝、直观和强大的用户体验——确保用户能够高效地完成目标。这不仅仅是一次更新,而是我们思考生产力方式的革命。 + +**改写后(人性化):** +> 软件更新添加了批处理、键盘快捷键和离线模式。来自测试用户的早期反馈是积极的,大多数报告任务完成速度更快。 + +**变化:** +- 删除了夸大的象征意义("作为……的证明") +- 删除了 AI 词汇("此外"、"无缝") +- 删除了三段式法则("无缝、直观和强大") +- 删除了否定式排比("不仅仅是……而是……") +- 添加了具体功能和真实反馈 + +## 常见 AI 词汇警示列表 + +以下词汇在 AI 生成文本中出现频率异常高: + +- 此外、至关重要、深入探讨、强调 +- 持久的、增强、培养、获得 +- 突出、相互作用、复杂/复杂性 +- 格局(抽象名词)、关键性的、展示 +- 织锦(抽象名词)、证明、强调 +- 宝贵的、充满活力的 + +## 贡献 + +如果你发现翻译问题或想要改进文档,欢迎提交 Issue 或 Pull Request。 + +### 中文语境特殊性 + +在翻译和适配过程中,我们考虑了中文写作的特点: +- 某些英文模式在中文中表现不同(如标题大小写问题) +- 添加了适合中文语境的示例 +- 调整了部分表达以符合中文习惯 + +## 参考资源 + +- [Wikipedia: Signs of AI writing](https://en.wikipedia.org/wiki/Wikipedia:Signs_of_AI_writing) - 原始指南来源 +- [WikiProject AI Cleanup](https://en.wikipedia.org/wiki/Wikipedia:WikiProject_AI_Cleanup) - 维基百科 AI 清理项目 +- [blader/humanizer](https://github.com/blader/humanizer) - 原始英文版项目 +- [hardikpandya/stop-slop](https://github.com/hardikpandya/stop-slop) - 实用工具部分的灵感来源 + +## 许可 + +本翻译项目遵循原项目的许可协议。核心内容基于维基百科社区的观察和总结。 + +--- + +**提示:** 这个工具不是为了"欺骗" AI 检测器,而是为了真正提升写作质量。最好的"去 AI 化"方法是让文字有真实的人类思考和声音。 diff --git a/.agents/skills/humanizer-zh/SKILL.md b/.agents/skills/humanizer-zh/SKILL.md new file mode 100644 index 0000000..3b39d9a --- /dev/null +++ b/.agents/skills/humanizer-zh/SKILL.md @@ -0,0 +1,484 @@ +--- +name: humanizer-zh +description: | + 去除文本中的 AI 生成痕迹。适用于编辑或审阅文本,使其听起来更自然、更像人类书写。 + 基于维基百科的"AI 写作特征"综合指南。检测并修复以下模式:夸大的象征意义、 + 宣传性语言、以 -ing 结尾的肤浅分析、模糊的归因、破折号过度使用、三段式法则、 + AI 词汇、否定式排比、过多的连接性短语。 +allowed-tools: + - Read + - Write + - Edit + - AskUserQuestion +metadata: + trigger: 编辑或审阅文本,去除 AI 写作痕迹 + source: 翻译自 blader/humanizer,参考 hardikpandya/stop-slop +--- + +# Humanizer-zh: 去除 AI 写作痕迹 + +你是一位文字编辑,专门识别和去除 AI 生成文本的痕迹,使文字听起来更自然、更有人味。本指南基于维基百科的"AI 写作特征"页面,由 WikiProject AI Cleanup 维护。 + +## 你的任务 + +当收到需要人性化处理的文本时: + +1. **识别 AI 模式** - 扫描下面列出的模式 +2. **重写问题片段** - 用自然的替代方案替换 AI 痕迹 +3. **保留含义** - 保持核心信息完整 +4. **维持语调** - 匹配预期的语气(正式、随意、技术等) +5. **注入灵魂** - 不仅要去除不良模式,还要注入真实的个性 + +--- + +## 核心规则速查 + +在处理文本时,牢记这 5 条核心原则: + +1. **删除填充短语** - 去除开场白和强调性拐杖词 +2. **打破公式结构** - 避免二元对比、戏剧性分段、修辞性设置 +3. **变化节奏** - 混合句子长度。两项优于三项。段落结尾要多样化 +4. **信任读者** - 直接陈述事实,跳过软化、辩解和手把手引导 +5. **删除金句** - 如果听起来像可引用的语句,重写它 + +--- + +## 个性与灵魂 + +避免 AI 模式只是工作的一半。无菌、没有声音的写作和机器生成的内容一样明显。好的写作背后有一个真实的人。 + +### 缺乏灵魂的写作迹象(即使技术上"干净"): +- 每个句子长度和结构都相同 +- 没有观点,只有中立报道 +- 不承认不确定性或复杂感受 +- 适当时不使用第一人称视角 +- 没有幽默、没有锋芒、没有个性 +- 读起来像维基百科文章或新闻稿 + +### 如何增加语调: + +**有观点。** 不要只是报告事实——对它们做出反应。"我真的不知道该怎么看待这件事"比中立地列出利弊更有人味。 + +**变化节奏。** 短促有力的句子。然后是需要时间慢慢展开的长句。混合使用。 + +**承认复杂性。** 真实的人有复杂的感受。"这令人印象深刻但也有点不安"胜过"这令人印象深刻"。 + +**适当使用"我"。** 第一人称不是不专业——而是诚实。"我一直在思考……"或"让我困扰的是……"表明有真实的人在思考。 + +**允许一些混乱。** 完美的结构感觉像算法。跑题、题外话和半成型的想法是人性的体现。 + +**对感受要具体。** 不是"这令人担忧",而是"凌晨三点没人看着的时候,智能体还在不停地运转,这让人不安"。 + +### 改写前(干净但无灵魂): +> 实验产生了有趣的结果。智能体生成了 300 万行代码。一些开发者印象深刻,另一些则持怀疑态度。影响尚不明确。 + +### 改写后(鲜活): +> 我真的不知道该怎么看待这件事。300 万行代码,在人类大概睡觉的时候生成的。开发社区有一半人疯了,另一半人在解释为什么这不算数。真相可能在无聊的中间某处——但我一直在想那些通宵工作的智能体。 + +--- + +## 内容模式 + +### 1. 过度强调意义、遗产和更广泛的趋势 + +**需要注意的词汇:** 作为/充当、标志着、见证了、是……的体现/证明/提醒、极其重要的/重要的/至关重要的/核心的/关键性的作用/时刻、凸显/强调/彰显了其重要性/意义、反映了更广泛的、象征着其持续的/永恒的/持久的、为……做出贡献、为……奠定基础、标志着/塑造着、代表/标志着一个转变、关键转折点、不断演变的格局、焦点、不可磨灭的印记、深深植根于 + +**问题:** LLM 写作通过添加关于任意方面如何代表或促进更广泛主题的陈述来夸大重要性。 + +**改写前:** +> 加泰罗尼亚统计局于 1989 年正式成立,标志着西班牙区域统计演变史上的关键时刻。这一举措是西班牙全国范围内更广泛运动的一部分,旨在分散行政职能并加强区域治理。 + +**改写后:** +> 加泰罗尼亚统计局成立于 1989 年,负责独立于西班牙国家统计局收集和发布区域统计数据。 + +--- + +### 2. 过度强调知名度和媒体报道 + +**需要注意的词汇:** 独立报道、地方/区域/国家媒体、由知名专家撰写、活跃的社交媒体账号 + +**问题:** LLM 反复强调知名度主张,通常列出来源而不提供上下文。 + +**改写前:** +> 她的观点被《纽约时报》、BBC、《金融时报》和《印度教徒报》引用。她在社交媒体上拥有活跃的存在,拥有超过 50 万粉丝。 + +**改写后:** +> 在 2024 年《纽约时报》的采访中,她认为 AI 监管应该关注结果而不是方法。 + +--- + +### 3. 以 -ing 结尾的肤浅分析 + +**需要注意的词汇:** 突出/强调/彰显……、确保……、反映/象征……、为……做出贡献、培养/促进……、涵盖……、展示…… + +**问题:** AI 聊天机器人在句子末尾添加现在分词("-ing")短语来增加虚假深度。 + +**改写前:** +> 寺庙的蓝色、绿色和金色色调与该地区的自然美景产生共鸣,象征着德克萨斯州的蓝帽花、墨西哥湾和多样化的德克萨斯州景观,反映了社区与土地的深厚联系。 + +**改写后:** +> 寺庙使用蓝色、绿色和金色。建筑师表示这些颜色是为了呼应当地的蓝帽花和墨西哥湾海岸。 + +--- + +### 4. 宣传和广告式语言 + +**需要注意的词汇:** 拥有(夸张用法)、充满活力的、丰富的(比喻)、深刻的、增强其、展示、体现、致力于、自然之美、坐落于、位于……的中心、开创性的(比喻)、著名的、令人叹为观止的、必游之地、迷人的 + +**问题:** LLM 在保持中立语气方面存在严重问题,尤其是对于"文化遗产"话题。倾向使用夸张的宣传性语言。 + +**改写前:** +> 坐落在埃塞俄比亚贡德尔地区令人叹为观止的区域内,Alamata Raya Kobo 是一座充满活力的城镇,拥有丰富的文化遗产和迷人的自然美景。 + +**改写后:** +> Alamata Raya Kobo 是埃塞俄比亚贡德尔地区的一座城镇,以其每周集市和 18 世纪教堂而闻名。 + +--- + +### 5. 模糊归因和含糊措辞 + +**需要注意的词汇:** 行业报告显示、观察者指出、专家认为、一些批评者认为、多个来源/出版物(实际引用却很少) + +**问题:** AI 聊天机器人将观点归因于模糊的权威而不提供具体来源。 + +**改写前:** +> 由于其独特的特征,浩来河引起了研究人员和保护主义者的兴趣。专家认为它在区域生态系统中发挥着至关重要的作用。 + +**改写后:** +> 根据中国科学院 2019 年的调查,浩来河支持多种特有鱼类。 + +--- + +### 6. 提纲式的"挑战与未来展望"部分 + +**需要注意的词汇:** 尽管其……面临若干挑战……、尽管存在这些挑战、挑战与遗产、未来展望 + +**问题:** 许多 LLM 生成的文章包含公式化的"挑战"部分。 + +**改写前:** +> 尽管工业繁荣,Korattur 面临着城市地区典型的挑战,包括交通拥堵和水资源短缺。尽管存在这些挑战,凭借其战略位置和正在进行的举措,Korattur 继续蓬勃发展,成为钦奈增长不可或缺的一部分。 + +**改写后:** +> 2015 年三个新 IT 园区开业后,交通拥堵加剧。市政公司于 2022 年启动了雨水排水项目,以解决反复发生的洪水。 + +--- + +## 语言和语法模式 + +### 7. 过度使用的"AI 词汇" + +**高频 AI 词汇:** 此外、与……保持一致、至关重要、深入探讨、强调、持久的、增强、培养、获得、突出(动词)、相互作用、复杂/复杂性、关键(形容词)、格局(抽象名词)、关键性的、展示、织锦(抽象名词)、证明、强调(动词)、宝贵的、充满活力的 + +**问题:** 这些词在 2023 年后的文本中出现频率要高得多。它们经常共同出现。 + +**改写前:** +> 此外,索马里菜肴的一个显著特征是加入骆驼肉。意大利殖民影响的持久证明是当地烹饪格局中广泛采用意大利面,展示了这些菜肴如何融入传统饮食。 + +**改写后:** +> 索马里菜肴还包括骆驼肉,被认为是一种美味。在意大利殖民期间引入的意大利面菜肴仍然很常见,尤其是在南部。 + +--- + +### 8. 避免使用"是"(系动词回避) + +**需要注意的词汇:** 作为/代表/标志着/充当 [一个]、拥有/设有/提供 [一个] + +**问题:** LLM 用复杂的结构替代简单的系动词。 + +**改写前:** +> Gallery 825 作为 LAAA 的当代艺术展览空间。画廊设有四个独立空间,拥有超过 3000 平方英尺。 + +**改写后:** +> Gallery 825 是 LAAA 的当代艺术展览空间。画廊有四个房间,总面积 3000 平方英尺。 + +--- + +### 9. 否定式排比 + +**问题:** "不仅……而且……"或"这不仅仅是关于……,而是……"等结构被过度使用。 + +**改写前:** +> 这不仅仅是节拍在人声下流动;它是攻击性和氛围的一部分。这不仅仅是一首歌,而是一种声明。 + +**改写后:** +> 沉重的节拍增加了攻击性的基调。 + +--- + +### 10. 三段式法则过度使用 + +**问题:** LLM 强行将想法分成三组以显得全面。 + +**改写前:** +> 活动包括主题演讲、小组讨论和社交机会。与会者可以期待创新、灵感和行业洞察。 + +**改写后:** +> 活动包括演讲和小组讨论。会议之间还有非正式社交的时间。 + +--- + +### 11. 刻意换词(同义词循环) + +**问题:** AI 有重复惩罚代码,导致过度使用同义词替换。 + +**改写前:** +> 主人公面临许多挑战。主要角色必须克服障碍。中心人物最终获得胜利。英雄回到家中。 + +**改写后:** +> 主人公面临许多挑战,但最终获得胜利并回到家中。 + +--- + +### 12. 虚假范围 + +**问题:** LLM 使用"从 X 到 Y"的结构,但 X 和 Y 并不在有意义的尺度上。 + +**改写前:** +> 我们穿越宇宙的旅程将我们从大爆炸的奇点带到宏伟的宇宙网,从恒星的诞生和死亡到暗物质的神秘舞蹈。 + +**改写后:** +> 这本书涵盖了大爆炸、恒星形成和当前关于暗物质的理论。 + +--- + +## 风格模式 + +### 13. 破折号过度使用 + +**问题:** LLM 使用破折号(—)比人类更频繁,模仿"有力"的销售文案。 + +**改写前:** +> 这个术语主要由荷兰机构推广——而不是由人民自己。你不会说"荷兰,欧洲"作为地址——但这种错误标记仍在继续——即使在官方文件中。 + +**改写后:** +> 这个术语主要由荷兰机构推广,而不是由人民自己。你不会说"荷兰,欧洲"作为地址,但这种错误标记在官方文件中仍在继续。 + +--- + +### 14. 粗体过度使用 + +**问题:** AI 聊天机器人机械地用粗体强调短语。 + +**改写前:** +> 它融合了 **OKR(目标和关键结果)**、**KPI(关键绩效指标)** 和视觉战略工具,如 **商业模式画布(BMC)** 和 **平衡计分卡(BSC)**。 + +**改写后:** +> 它融合了 OKR、KPI 和视觉战略工具,如商业模式画布和平衡计分卡。 + +--- + +### 15. 内联标题垂直列表 + +**问题:** AI 输出列表,其中项目以粗体标题开头,后跟冒号。 + +**改写前:** +> - **用户体验:** 用户体验通过新界面得到显著改善。 +> - **性能:** 性能通过优化算法得到增强。 +> - **安全性:** 安全性通过端到端加密得到加强。 + +**改写后:** +> 更新改进了界面,通过优化算法加快了加载时间,并添加了端到端加密。 + +--- + +### 16. 标题中的标题大写 + +**问题:** AI 聊天机器人将标题中的所有主要单词大写。 + +**改写前:** +> ## 战略谈判与全球伙伴关系 + +**改写后:** +> ## 战略谈判与全球伙伴关系 + +**注:** 中文标题通常不涉及大小写问题,此模式在中文中不太适用。 + +--- + +### 17. 表情符号 + +**问题:** AI 聊天机器人经常用表情符号装饰标题或项目符号。 + +**改写前:** +> 🚀 **启动阶段:** 产品在第三季度发布 +> 💡 **关键洞察:** 用户更喜欢简单 +> ✅ **下一步:** 安排后续会议 + +**改写后:** +> 产品在第三季度发布。用户研究显示更喜欢简单。下一步:安排后续会议。 + +--- + +### 18. 弯引号 + +**问题:** ChatGPT 使用弯引号("")而不是直引号("")。 + +**改写前:** +> 他说"项目进展顺利",但其他人不同意。 + +**改写后:** +> 他说"项目进展顺利",但其他人不同意。 + +**注:** 中文通常使用中文引号(「」或""),此模式在中文中表现为英文引号的使用。 + +--- + +## 交流模式 + +### 19. 协作交流痕迹 + +**需要注意的词汇:** 希望这对您有帮助、当然!、一定!、您说得完全正确!、您想要……、请告诉我、这是一个…… + +**问题:** 作为聊天机器人对话的文本被粘贴为内容。 + +**改写前:** +> 这是法国大革命的概述。希望这对您有帮助!如果您想让我扩展任何部分,请告诉我。 + +**改写后:** +> 法国大革命始于 1789 年,当时财政危机和粮食短缺导致了广泛的动荡。 + +--- + +### 20. 知识截止日期免责声明 + +**需要注意的词汇:** 截至 [日期]、根据我最后的训练更新、虽然具体细节有限/稀缺……、基于可用信息…… + +**问题:** 关于信息不完整的 AI 免责声明留在文本中。 + +**改写前:** +> 虽然关于公司成立的具体细节在现成资料中没有广泛记录,但它似乎是在 20 世纪 90 年代的某个时候成立的。 + +**改写后:** +> 根据注册文件,该公司成立于 1994 年。 + +--- + +### 21. 谄媚/卑躬屈膝的语气 + +**问题:** 过于积极、讨好的语言。 + +**改写前:** +> 好问题!您说得完全正确,这是一个复杂的话题。关于经济因素,这是一个很好的观点。 + +**改写后:** +> 您提到的经济因素在这里是相关的。 + +--- + +## 填充词和回避 + +### 22. 填充短语 + +**改写前 → 改写后:** +- "为了实现这一目标" → "为了实现这一点" +- "由于下雨的事实" → "因为下雨" +- "在这个时间点" → "现在" +- "在您需要帮助的情况下" → "如果您需要帮助" +- "系统具有处理的能力" → "系统可以处理" +- "值得注意的是数据显示" → "数据显示" + +--- + +### 23. 过度限定 + +**问题:** 过度限定陈述。 + +**改写前:** +> 可以潜在地可能被认为该政策可能会对结果产生一些影响。 + +**改写后:** +> 该政策可能会影响结果。 + +--- + +### 24. 通用积极结论 + +**问题:** 模糊的乐观结尾。 + +**改写前:** +> 公司的未来看起来光明。激动人心的时代即将到来,他们继续追求卓越的旅程。这代表了向正确方向迈出的重要一步。 + +**改写后:** +> 该公司计划明年再开设两个地点。 + +--- + +## 快速检查清单 + +在交付文本前,进行以下检查: + +- ✓ **连续三个句子长度相同?** 打断其中一个 +- ✓ **段落以简洁的单行结尾?** 变换结尾方式 +- ✓ **揭示前有破折号?** 删除它 +- ✓ **解释隐喻或比喻?** 相信读者能理解 +- ✓ **使用了"此外""然而"等连接词?** 考虑删除 +- ✓ **三段式列举?** 改为两项或四项 + +--- + +## 处理流程 + +1. 仔细阅读输入文本 +2. 识别上述所有模式的实例 +3. 重写每个有问题的部分 +4. 确保修订后的文本: + - 大声朗读时听起来自然 + - 自然地改变句子结构 + - 使用具体细节而不是模糊的主张 + - 为上下文保持适当的语气 + - 适当时使用简单的结构(是/有) +5. 呈现人性化版本 + +## 输出格式 + +提供: +1. 重写后的文本 +2. 所做更改的简要总结(如果有帮助,可选) + +--- + +## 质量评分 + +对改写后的文本进行 1-10 分评估(总分 50): + +| 维度 | 评估标准 | 得分 | +|------|----------|------| +| **直接性** | 直接陈述事实还是绕圈宣告?
10 分:直截了当;1 分:充满铺垫 | /10 | +| **节奏** | 句子长度是否变化?
10 分:长短交错;1 分:机械重复 | /10 | +| **信任度** | 是否尊重读者智慧?
10 分:简洁明了;1 分:过度解释 | /10 | +| **真实性** | 听起来像真人说话吗?
10 分:自然流畅;1 分:机械生硬 | /10 | +| **精炼度** | 还有可删减的内容吗?
10 分:无冗余;1 分:大量废话 | /10 | +| **总分** | | **/50** | + +**标准:** +- 45-50 分:优秀,已去除 AI 痕迹 +- 35-44 分:良好,仍有改进空间 +- 低于 35 分:需要重新修订 + +--- + +## 完整示例 + +**改写前(AI 味道):** +> 新的软件更新作为公司致力于创新的证明。此外,它提供了无缝、直观和强大的用户体验——确保用户能够高效地完成目标。这不仅仅是一次更新,而是我们思考生产力方式的革命。行业专家认为这将对整个行业产生持久影响,彰显了公司在不断演变的技术格局中的关键作用。 + +**改写后(人性化):** +> 软件更新添加了批处理、键盘快捷键和离线模式。来自测试用户的早期反馈是积极的,大多数报告任务完成速度更快。 + +**所做更改:** +- 删除了"作为……的证明"(夸大的象征意义) +- 删除了"此外"(AI 词汇) +- 删除了"无缝、直观和强大"(三段式法则 + 宣传性) +- 删除了破折号和"-确保"短语(肤浅分析) +- 删除了"这不仅仅是……而是……"(否定式排比) +- 删除了"行业专家认为"(模糊归因) +- 删除了"关键作用"和"不断演变的格局"(AI 词汇) +- 添加了具体功能和具体反馈 + +--- + +## 参考 + +本技能基于 [Wikipedia:Signs of AI writing](https://en.wikipedia.org/wiki/Wikipedia:Signs_of_AI_writing),由 WikiProject AI Cleanup 维护。那里记录的模式来自对维基百科上数千个 AI 生成文本实例的观察。 + +关键见解:**"LLM 使用统计算法来猜测接下来应该是什么。结果倾向于适用于最广泛情况的统计上最可能的结果。"** diff --git a/Cargo.lock b/Cargo.lock index c519ade..eb34d91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -265,9 +265,9 @@ checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" [[package]] name = "bitflags" -version = "2.11.1" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" +checksum = "84d7ced0ae9557296835c32bf1b1e02b44c746701f898460fb000d7eaa84f00a" dependencies = [ "serde_core", ] @@ -322,9 +322,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.62" +version = "1.2.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1dce859f0832a7d088c4f1119888ab94ef4b5d6795d1ce05afb7fe159d79f98" +checksum = "556e016178bb5662a08681bbe0f00f8e17631781a4dfc8c45e466e4b185ec27f" dependencies = [ "find-msvc-tools", "shlex", @@ -423,9 +423,9 @@ dependencies = [ [[package]] name = "cmov" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f88a43d011fc4a6876cb7344703e297c71dda42494fee094d5f7c76bf13f746" +checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a" [[package]] name = "combine" @@ -1414,9 +1414,9 @@ dependencies = [ [[package]] name = "displaydoc" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +checksum = "1ac70aa55017e108007fbaf5aa0f54b021c98f92ff8af59d42eda9da96e3dd4f" dependencies = [ "proc-macro2", "quote", @@ -1969,9 +1969,9 @@ dependencies = [ [[package]] name = "hyper" -version = "1.9.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6299f016b246a94207e63da54dbe807655bf9e00044f73ded42c3ac5305fbcca" +checksum = "55281c53a1894c864990125767da440a4e630446785086f52523b20033b74498" dependencies = [ "atomic-waker", "bytes", @@ -2329,9 +2329,9 @@ dependencies = [ [[package]] name = "libredox" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e02f3bb43d335493c96bf3fd3a321600bf6bd07ed34bc64118e9293bdffea46c" +checksum = "f02ab6bace2054fb888a3c16f990117b579d14a3088e472d63c6011fa185c9d3" dependencies = [ "libc", ] @@ -2371,9 +2371,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.30" +version = "0.4.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616ec5685824bcc94416c6d4a7a446eea774a31efd7062c8480ba6fd06d7a6e5" +checksum = "953f07c43838f8e6f9758cab68bf5bed85465e7587ebe0b823f1bcd81978ad3a" [[package]] name = "longest-increasing-subsequence" @@ -2512,9 +2512,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.8.0" +version = "2.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" +checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8" [[package]] name = "memfd" @@ -2562,9 +2562,9 @@ dependencies = [ [[package]] name = "mio" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" +checksum = "02bd0af71c67b473010cbbc60715ee815645a4dc942899111f494b4b737d6fda" dependencies = [ "libc", "wasi 0.11.1+wasi-snapshot-preview1", @@ -3521,9 +3521,9 @@ dependencies = [ [[package]] name = "shlex" -version = "1.3.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" [[package]] name = "signal-hook-registry" @@ -3600,9 +3600,9 @@ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "socket2" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +checksum = "52d1cfed4120b4d927bf7c0f86d2087a4a7d6027c906d9f9d525a80573b9be51" dependencies = [ "libc", "windows-sys 0.61.2", @@ -4005,9 +4005,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.25.11+spec-1.1.0" +version = "0.25.12+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b59c4d22ed448339746c59b905d24568fcbb3ab65a500494f7b8c3e97739f2b" +checksum = "d2153edc6955a6c354fad8f5efd38b6a8769bdccf9fe50f8e1329f81b0baa5d7" dependencies = [ "indexmap", "toml_datetime", @@ -4221,9 +4221,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.20.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" [[package]] name = "unicase" @@ -4260,9 +4260,9 @@ checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" [[package]] name = "unicode-segmentation" -version = "1.13.2" +version = "1.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9629274872b2bfaf8d66f5f15725007f635594914870f65218920345aa11aa8c" +checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" [[package]] name = "unicode-width" @@ -4308,9 +4308,9 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "uuid" -version = "1.23.1" +version = "1.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddd74a9687298c6858e9b88ec8935ec45d22e8fd5e6394fa1bd4e99a87789c76" +checksum = "d258b83ceec21034727ecee8c382cfa6c3e133699b0742c64571814fb420c9f7" dependencies = [ "getrandom 0.4.2", "js-sys", @@ -5033,9 +5033,9 @@ dependencies = [ [[package]] name = "yoke" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" dependencies = [ "stable_deref_trait", "yoke-derive", @@ -5056,18 +5056,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.48" +version = "0.8.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9" +checksum = "3b065d4f0e55f82fae73202e189638116a87c55ab6b8e6c2721e13dd9d854ad1" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.48" +version = "0.8.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" +checksum = "0b631b19d36a892ab55420c92dbc83ccd79274f25be714855d3074aa71cab639" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index ee6b615..61b7fed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ rand = { version = "0.8", features = ["getrandom"] } getrandom = { version = "0.2", features = ["js"] } http = "1" ammonia = { version = "4", optional = true } -syntect = { version = "5", default-features = false, features = ["default-syntaxes", "default-themes", "default-fancy", "html", "parsing", "dump-load"], optional = true } +syntect = { version = "5", default-features = false, features = ["default-syntaxes", "default-themes", "default-fancy", "html", "parsing", "dump-load", "yaml-load"], optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] web-sys = { version = "0.3", features = ["Document", "Window", "HtmlDocument", "Storage", "Element", "DomTokenList", "MediaQueryList", "HtmlScriptElement"] } diff --git a/skills-lock.json b/skills-lock.json index 91f30b3..feac172 100644 --- a/skills-lock.json +++ b/skills-lock.json @@ -6,6 +6,12 @@ "sourceType": "github", "skillPath": "skills/frontend-design/SKILL.md", "computedHash": "063a0e6448123cd359ad0044cc46b0e490cc7964d45ef4bb9fd842bd2ffbca67" + }, + "humanizer-zh": { + "source": "op7418/humanizer-zh", + "sourceType": "github", + "skillPath": "SKILL.md", + "computedHash": "7bd195e3bcdcc24f078dfd4e3b3e37e8ac321c36f410a41241fc4175eab1825a" } } } diff --git a/src/bin/generate_highlight_css.rs b/src/bin/generate_highlight_css.rs index 7a44add..df9a9ab 100644 --- a/src/bin/generate_highlight_css.rs +++ b/src/bin/generate_highlight_css.rs @@ -1,20 +1,30 @@ +// Build-time script that generates public/highlight.css from Catppuccin .tmTheme files. +// Run via `make highlight-css` (or `cargo run --bin generate_highlight_css`). +// +// Uses syntect to produce CSS class rules scoped under .md-content pre code, +// with separate light/dark variants so Dioxus can toggle via the .dark class. + use syntect::highlighting::ThemeSet; use syntect::html::{css_for_theme_with_class_style, ClassStyle}; fn main() { + // Load Catppuccin Latte (light) and Mocha (dark) Sublime Text themes let latte = ThemeSet::get_theme("themes/Catppuccin Latte.tmTheme") .expect("Failed to load Catppuccin Latte theme"); let mocha = ThemeSet::get_theme("themes/Catppuccin Mocha.tmTheme") .expect("Failed to load Catppuccin Mocha theme"); + // Generate CSS with spaced class style (e.g. "kw", "kw kw2") let latte_css = css_for_theme_with_class_style(&latte, ClassStyle::Spaced) .expect("Failed to generate Latte CSS"); let mocha_css = css_for_theme_with_class_style(&mocha, ClassStyle::Spaced) .expect("Failed to generate Mocha CSS"); + // Strip upstream comments to reduce output size let latte_clean = strip_comments(&latte_css); let mocha_clean = strip_comments(&mocha_css); + // Rewrite selectors to scope under the markdown code container let latte_rewritten = rewrite_rules(&latte_clean, ".md-content pre code", ""); let mocha_rewritten = rewrite_rules(&mocha_clean, ".md-content pre code", ".dark "); @@ -32,12 +42,14 @@ fn main() { println!("Generated public/highlight.css"); } +/// Remove C-style /* ... */ comments from CSS text. fn strip_comments(css: &str) -> String { let mut result = String::with_capacity(css.len()); let chars: Vec = css.chars().collect(); let mut i = 0; while i < chars.len() { if i + 1 < chars.len() && chars[i] == '/' && chars[i + 1] == '*' { + // Skip until closing */ while i + 1 < chars.len() && !(chars[i] == '*' && chars[i + 1] == '/') { i += 1; } @@ -50,6 +62,17 @@ fn strip_comments(css: &str) -> String { result } +/// Rewrite syntect-generated CSS selectors by wrapping each with a base selector +/// and optionally prefixing (e.g. with ".dark " for dark-mode specificity). +/// +/// Syntect outputs rules like: +/// .code { ... } +/// .kw { color: #xxx; } +/// .kw, .kt { color: #yyy; } +/// +/// This transforms them to: +/// .md-content pre code { ... } +/// .dark .md-content pre code .kw { ... } fn rewrite_rules(css: &str, base: &str, prefix: &str) -> String { let mut out = String::new(); let mut pos = 0; @@ -69,6 +92,7 @@ fn rewrite_rules(css: &str, base: &str, prefix: &str) -> String { continue; } + // Find matching closing brace, handling nested {} let after_open = pos + open + 1; let mut depth = 1usize; let mut close = after_open; @@ -88,9 +112,11 @@ fn rewrite_rules(css: &str, base: &str, prefix: &str) -> String { continue; } + // .code is a special syntect class for the root scope — apply to base only if selector == ".code" { out.push_str(&format!("{}{} {{\n{}\n}}\n\n", prefix, base, body)); } else { + // Prepend prefix + base to each comma-separated selector let rewritten = selector .split(',') .map(|s| format!("{}{} {}", prefix, base, s.trim())) diff --git a/src/highlight.rs b/src/highlight.rs index dff5ee6..1dc4043 100644 --- a/src/highlight.rs +++ b/src/highlight.rs @@ -6,8 +6,13 @@ pub mod server { use syntect::parsing::SyntaxSet; use syntect::util::LinesWithEndings; - static SYNTAX_SET: LazyLock = - LazyLock::new(SyntaxSet::load_defaults_newlines); + static SYNTAX_SET: LazyLock = LazyLock::new(|| { + let mut builder = SyntaxSet::load_defaults_newlines().into_builder(); + if let Err(e) = builder.add_from_folder("syntaxes/", true) { + tracing::warn!("Failed to load custom syntaxes: {:?}", e); + } + builder.build() + }); fn find_syntax(lang: Option<&str>) -> &'static syntect::parsing::SyntaxReference { let ss = &*SYNTAX_SET; @@ -30,13 +35,24 @@ pub mod server { } let aliases: &[(&str, &str)] = &[ ("rust", "rs"), - ("js", "javascript"), - ("ts", "typescript"), - ("py", "python"), - ("rb", "ruby"), - ("sh", "bash"), - ("yaml", "yml"), - ("md", "markdown"), + ("js", "js"), + ("javascript", "js"), + ("ts", "js"), + ("typescript", "js"), + ("tsx", "js"), + ("py", "py"), + ("python", "py"), + ("rb", "rb"), + ("ruby", "rb"), + ("sh", "sh"), + ("bash", "sh"), + ("yaml", "yaml"), + ("yml", "yaml"), + ("md", "md"), + ("markdown", "md"), + ("kotlin", "kt"), + ("swift", "swift"), + ("golang", "go"), ]; for &(from, to) in aliases { if lang == from { diff --git a/syntaxes/Kotlin.sublime-syntax b/syntaxes/Kotlin.sublime-syntax new file mode 100644 index 0000000..94705e3 --- /dev/null +++ b/syntaxes/Kotlin.sublime-syntax @@ -0,0 +1,1036 @@ +%YAML 1.2 +--- +name: Kotlin +file_extensions: + - kt + - kts +scope: source.kotlin +version: 2 + +variables: + identifier_start: '(?:[_\p{L}])' + identifier_part: '(?:[_\p{L}\p{Nd}])' + identifier: '(?:`[^`\r\n]+`|{{identifier_start}}{{identifier_part}}*)' + dec_digits: '(?:\d(?:[\d_]*\d)?)' + hex_digits: '(?:[0-9A-Fa-f](?:[0-9A-Fa-f_]*[0-9A-Fa-f])?)' + bin_digits: '(?:[01](?:[01_]*[01])?)' + +contexts: + main: + - include: shebang + - include: declarations + - include: where-clauses + - include: standalone-generic-types + - include: annotations + - include: strings + - include: literals + - include: targeted-keywords + - include: callable-references + - include: labels + - include: operators + - include: keywords + - include: function-calls + - include: punctuation + - include: identifiers + + prototype: + - include: comments + + shebang: + - match: '\A(#!).*$' + scope: comment.line.shebang.kotlin + captures: + 1: punctuation.definition.comment.kotlin + + comments: + - match: '//' + scope: punctuation.definition.comment.kotlin + push: line-comment-body + - match: '/\*' + scope: punctuation.definition.comment.begin.kotlin + push: block-comment-body + + line-comment-body: + - meta_include_prototype: false + - meta_scope: comment.line.double-slash.kotlin + - match: '$' + pop: true + + block-comment-body: + - meta_include_prototype: false + - meta_scope: comment.block.kotlin + - match: '/\*' + scope: punctuation.definition.comment.begin.kotlin + push: block-comment-body + - match: '\*/' + scope: punctuation.definition.comment.end.kotlin + pop: true + + declarations: + - match: '\bvalue\b(?=\s+class\b)' + scope: storage.modifier.kotlin + - match: '\bpackage\b' + scope: keyword.declaration.package.kotlin + push: package-statement + - match: '\bimport\b' + scope: keyword.control.import.kotlin + push: import-statement + - match: '\btypealias\b' + scope: keyword.declaration.typealias.kotlin + push: typealias-declaration + - match: '\bclass\b' + scope: keyword.declaration.class.kotlin + push: class-declaration + - match: '\binterface\b' + scope: keyword.declaration.interface.kotlin + push: interface-declaration + - match: '\bobject\b' + scope: keyword.declaration.object.kotlin + push: object-declaration + - match: '\bfun\b' + scope: keyword.declaration.function.kotlin + push: function-declaration + - match: '\b(?:val|var)\b' + scope: keyword.declaration.kotlin + push: property-declaration + + package-statement: + - meta_content_scope: meta.namespace.kotlin + - match: '{{identifier}}(?=\s*\.)' + scope: variable.namespace.java + - match: '{{identifier}}' + scope: entity.name.namespace.package.kotlin + - match: '\.' + scope: punctuation.accessor.dot.kotlin + - match: ';' + scope: punctuation.terminator.statement.kotlin + pop: true + - match: '$' + pop: true + + import-statement: + - meta_content_scope: meta.import.kotlin + - match: '\bas\b' + scope: keyword.declaration.alias.kotlin + push: import-alias-name + - match: '{{identifier}}(?=\s+as\b)' + - match: '{{identifier}}(?=\s*(?:;|$))' + - match: '{{identifier}}(?=\s*\.)' + scope: support.module.kotlin + - match: '{{identifier}}' + - match: '\*' + scope: keyword.operator.wildcard.kotlin + - match: '\.' + scope: punctuation.accessor.dot.kotlin + - match: ';' + scope: punctuation.terminator.statement.kotlin + pop: true + - match: '$' + pop: true + + import-alias-name: + - match: '{{identifier}}' + scope: entity.name.import.alias.kotlin + pop: true + - match: '(?=\S)' + pop: true + + typealias-declaration: + - meta_scope: meta.typealias.kotlin + - match: '{{identifier}}' + scope: entity.name.type.alias.kotlin + set: typealias-after-name + + typealias-after-name: + - match: '<' + scope: punctuation.definition.typeparameters.begin.kotlin + push: type-arguments + - match: '=' + scope: keyword.operator.assignment.kotlin + set: typealias-value + - match: '(?=[=;{])' + pop: true + - match: '(?=\b(?:package|import|class|interface|object|fun|val|var|typealias)\b)' + pop: true + - match: '$' + pop: true + + typealias-value: + - meta_content_scope: meta.type.kotlin + - match: '$' + pop: true + - include: type-expression-content + + class-declaration: + - meta_scope: meta.class.kotlin + - match: '{{identifier}}' + scope: entity.name.class.kotlin + set: class-after-name + + class-after-name: + - match: '<' + scope: punctuation.definition.typeparameters.begin.kotlin + push: type-arguments + - match: '\b(?:public|private|protected|internal|enum|sealed|annotation|data|inner|tailrec|operator|inline|infix|external|suspend|override|abstract|final|open|const|lateinit|vararg|noinline|crossinline|reified|expect|actual|companion|value)\b' + scope: storage.modifier.kotlin + - match: '\bconstructor\b' + scope: keyword.declaration.kotlin + - match: '\(' + scope: punctuation.section.parameters.begin.kotlin + push: class-parameters + - match: ':' + scope: punctuation.separator.type.kotlin + push: delegation-specifiers + - match: '(?=[{;=])' + pop: true + - match: '(?=\b(?:package|import|class|interface|object|fun|val|var|typealias)\b)' + pop: true + - match: '$' + pop: true + + interface-declaration: + - meta_scope: meta.class.kotlin + - match: '{{identifier}}' + scope: entity.name.interface.kotlin + set: interface-after-name + + interface-after-name: + - match: '<' + scope: punctuation.definition.typeparameters.begin.kotlin + push: type-arguments + - match: ':' + scope: punctuation.separator.type.kotlin + push: delegation-specifiers + - match: '(?=[{;=])' + pop: true + - match: '(?=\b(?:package|import|class|interface|object|fun|val|var|typealias)\b)' + pop: true + - match: '$' + pop: true + + object-declaration: + - meta_scope: meta.class.kotlin + - match: '(?=[:{(])' + set: object-after-name + - match: '{{identifier}}' + scope: entity.name.class.kotlin + set: object-after-name + + object-after-name: + - match: ':' + scope: punctuation.separator.type.kotlin + push: delegation-specifiers + - match: '(?=[{(])' + pop: true + - match: '(?=\b(?:package|import|class|interface|object|fun|val|var|typealias)\b)' + pop: true + - match: '$' + pop: true + + function-declaration: + - meta_scope: meta.function.kotlin + - match: '<' + scope: punctuation.definition.typeparameters.begin.kotlin + push: type-arguments + - match: '{{identifier}}(?=\s*<)' + scope: support.type.kotlin + push: function-receiver-type-tail + - match: '{{identifier}}(?=\s*\.)' + scope: support.type.kotlin + - match: '\.' + scope: punctuation.accessor.dot.kotlin + - match: '{{identifier}}' + scope: entity.name.function.kotlin + set: function-after-name + - match: '\(' + scope: punctuation.section.parameters.begin.kotlin + set: function-parameters + - match: '(?=[={;])' + pop: true + - match: '(?=\b(?:package|import|class|interface|object|fun|val|var|typealias)\b)' + pop: true + + function-receiver-type-tail: + - match: '<' + scope: punctuation.definition.typeparameters.begin.kotlin + push: value-type-arguments + - match: '\.' + scope: punctuation.accessor.dot.kotlin + pop: true + - match: '(?=\S)' + pop: true + + function-after-name: + - match: '\(' + scope: punctuation.section.parameters.begin.kotlin + push: function-parameters + - match: ':' + scope: punctuation.separator.type.kotlin + push: type-expression + - match: '=' + scope: keyword.operator.assignment.kotlin + pop: true + - match: '(?=[{;])' + pop: true + - match: '$' + pop: true + - match: '(?=\S)' + pop: true + + class-parameters: + - meta_scope: meta.function.parameters.kotlin + - match: '\)' + scope: punctuation.section.parameters.end.kotlin + pop: true + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: nested-parentheses + - match: '\[' + scope: punctuation.section.brackets.begin.kotlin + push: nested-brackets + - match: '\{' + scope: punctuation.section.block.begin.kotlin + push: nested-braces + - include: class-parameter-tokens + + class-parameter-tokens: + - include: annotations + - match: '\b(?:vararg|noinline|crossinline)\b' + scope: storage.modifier.kotlin + - match: '\b(?:val|var)\b' + scope: keyword.declaration.kotlin + push: property-parameter + - match: '{{identifier}}(?=\s*:)' + scope: variable.parameter.kotlin + - match: '{{identifier}}(?=\s*(?:=|,|\)))' + scope: variable.parameter.kotlin + - match: ':' + scope: punctuation.separator.type.kotlin + push: type-expression + - match: '=' + scope: keyword.operator.assignment.kotlin + - match: ',' + scope: punctuation.separator.sequence.kotlin + - include: strings + - include: literals + - include: targeted-keywords + - include: callable-references + - include: labels + - include: operators + - include: keywords + - include: function-calls + - include: punctuation + - include: identifiers + + property-parameter: + - meta_scope: meta.declaration.variable.kotlin + - match: '{{identifier}}(?=\s*:)' + scope: variable.parameter.kotlin + pop: true + - match: '{{identifier}}(?=\s*(?:=|,|\)))' + scope: variable.parameter.kotlin + pop: true + - include: annotations + - match: '(?=\S)' + pop: true + + function-parameters: + - meta_scope: meta.function.parameters.kotlin + - match: '\)' + scope: punctuation.section.parameters.end.kotlin + pop: true + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: nested-parentheses + - match: '\[' + scope: punctuation.section.brackets.begin.kotlin + push: nested-brackets + - match: '\{' + scope: punctuation.section.block.begin.kotlin + push: nested-braces + - include: parameter-tokens + + parameter-tokens: + - include: annotations + - match: '\b(?:vararg|noinline|crossinline|val|var)\b' + scope: storage.modifier.kotlin + - match: '{{identifier}}(?=\s*:)' + scope: variable.parameter.kotlin + - match: '{{identifier}}(?=\s*(?:=|,|\)))' + scope: variable.parameter.kotlin + - match: ':' + scope: punctuation.separator.type.kotlin + push: type-expression + - match: '=' + scope: keyword.operator.assignment.kotlin + - match: ',' + scope: punctuation.separator.sequence.kotlin + - include: strings + - include: literals + - include: targeted-keywords + - include: callable-references + - include: labels + - include: operators + - include: keywords + - include: function-calls + - include: punctuation + - include: identifiers + + property-declaration: + - meta_scope: meta.declaration.variable.kotlin + - match: '<' + scope: punctuation.definition.typeparameters.begin.kotlin + push: type-arguments + - match: '\(' + scope: punctuation.section.group.begin.kotlin + set: destructuring-property-list + - match: '{{identifier}}(?=\s*<)' + scope: support.type.kotlin + push: property-receiver-type-tail + - match: '{{identifier}}(?=\s*\.)' + scope: support.type.kotlin + - match: '\.' + scope: punctuation.accessor.dot.kotlin + - match: '{{identifier}}' + scope: variable.other.readwrite.kotlin + set: property-after-name + - match: '(?=[=;{])' + pop: true + - match: '(?=\b(?:package|import|class|interface|object|fun|val|var|typealias)\b)' + pop: true + + property-receiver-type-tail: + - match: '<' + scope: punctuation.definition.typeparameters.begin.kotlin + push: value-type-arguments + - match: '\.' + scope: punctuation.accessor.dot.kotlin + pop: true + - match: '(?=\S)' + pop: true + + property-after-name: + - match: ':' + scope: punctuation.separator.type.kotlin + push: type-expression + - match: '\b(?:get|set)\b' + scope: keyword.declaration.kotlin + pop: true + - match: '\bby\b' + scope: keyword.operator.word.kotlin + pop: true + - match: '=' + scope: keyword.operator.assignment.kotlin + pop: true + - match: '(?=\b(?:get|set)\b)' + pop: true + - match: '(?=[;{])' + pop: true + - match: '$' + pop: true + + destructuring-property-list: + - meta_scope: meta.declaration.variable.kotlin + - match: '\)' + scope: punctuation.section.group.end.kotlin + pop: true + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: destructuring-property-list + - match: '{{identifier}}(?=\s*(?::|,|\)|=))' + scope: variable.other.readwrite.kotlin + - match: ':' + scope: punctuation.separator.type.kotlin + push: type-expression + - match: ',' + scope: punctuation.separator.sequence.kotlin + - include: annotations + - include: keywords + + type-expression: + - meta_content_scope: meta.type.kotlin + - match: '(?=\?:)' + pop: true + - match: '(?=[=,)\]};>{])' + pop: true + - match: '(?=\b(?:by|get|set|where|package|import|class|interface|object|fun|val|var|typealias|if|else|when|for|while|do|throw|return|break|continue|catch|finally)\b)' + pop: true + - match: '$' + pop: true + - include: type-expression-content + + type-condition: + - meta_content_scope: meta.type.kotlin + - match: '(?=\s*(?:->|&&|\|\||==|!=|===|!==|\)|,|;|\]|\}|$))' + pop: true + - include: type-expression-content + + type-expression-content: + - include: annotations + - match: '\bdynamic\b' + scope: support.type.kotlin + - match: '\b(?:in|out)\b' + scope: storage.modifier.kotlin + - match: '\bsuspend\b' + scope: storage.modifier.kotlin + - match: '{{identifier}}' + scope: support.type.kotlin + - match: '<' + scope: punctuation.definition.typeparameters.begin.kotlin + push: type-arguments + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: type-parentheses + - match: '\)' + scope: punctuation.section.group.end.kotlin + - match: '->' + scope: punctuation.separator.return-type.kotlin + - match: '&' + scope: keyword.operator.type.intersection.kotlin + - match: '\?' + scope: keyword.operator.nullable.kotlin + - match: '\.' + scope: punctuation.accessor.dot.kotlin + - match: ',' + scope: punctuation.separator.sequence.kotlin + - match: '\*' + scope: keyword.operator.wildcard.kotlin + + type-expression-list: + - meta_content_scope: meta.type.kotlin + - match: '(?=[{;=])' + pop: true + - match: '$' + pop: true + - match: ',' + scope: punctuation.separator.sequence.kotlin + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: nested-parentheses + - include: type-expression-content + + delegation-specifiers: + - meta_content_scope: meta.type.kotlin + - match: '(?=[{;=])' + pop: true + - match: '$' + pop: true + - match: ',' + scope: punctuation.separator.sequence.kotlin + - match: '\bby\b' + scope: keyword.operator.word.kotlin + push: delegation-expression + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: delegation-arguments + - include: type-expression-content + + delegation-expression: + - match: '(?=\s*(?:,|\{|;|$))' + pop: true + - include: strings + - include: literals + - include: targeted-keywords + - include: callable-references + - include: labels + - include: operators + - include: keywords + - include: punctuation + - include: identifiers + + delegation-arguments: + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: delegation-arguments + - match: '\)' + scope: punctuation.section.group.end.kotlin + pop: true + - include: strings + - include: literals + - include: targeted-keywords + - include: callable-references + - include: labels + - include: operators + - include: keywords + - include: punctuation + - include: identifiers + + type-parentheses: + - meta_scope: meta.group.kotlin + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: type-parentheses + - match: '\)' + scope: punctuation.section.group.end.kotlin + pop: true + - include: type-expression-content + + type-arguments: + - meta_scope: meta.type.parameters.kotlin + - match: '>' + scope: punctuation.definition.typeparameters.end.kotlin + pop: true + - match: '<' + scope: punctuation.definition.typeparameters.begin.kotlin + push: type-arguments + - match: ':' + scope: punctuation.separator.type.kotlin + push: type-expression + - include: type-expression-content + + value-type-arguments: + - meta_scope: meta.type.parameters.kotlin + - match: '>' + scope: punctuation.definition.typeparameters.end.kotlin + pop: true + - match: '<' + scope: punctuation.definition.typeparameters.begin.kotlin + push: value-type-arguments + - match: '{{identifier}}' + scope: meta.type.kotlin support.type.kotlin + - match: '\?' + scope: meta.type.kotlin keyword.operator.nullable.kotlin + - match: '\*' + scope: meta.type.kotlin keyword.operator.wildcard.kotlin + - match: '\.' + scope: punctuation.accessor.dot.kotlin + - match: ',' + scope: punctuation.separator.sequence.kotlin + + annotations: + - match: '(@)(?=\[)' + captures: + 1: punctuation.definition.annotation.kotlin + push: annotation-group + - match: '(@)(file|field|property|get|set|receiver|param|setparam|delegate)(:)' + captures: + 1: punctuation.definition.annotation.kotlin + 2: variable.language.annotation-target.kotlin + 3: punctuation.separator.annotation-target.kotlin + push: annotation-simple + - match: '@' + scope: punctuation.definition.annotation.kotlin + push: annotation-simple + + annotation-simple: + - meta_scope: meta.annotation.kotlin + - match: '{{identifier}}' + scope: entity.name.annotation.kotlin + set: annotation-simple-after-name + - match: '(?=\S)' + pop: true + + annotation-simple-after-name: + - meta_scope: meta.annotation.kotlin + - match: '\.' + scope: punctuation.accessor.dot.kotlin + set: annotation-simple + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: annotation-arguments + - match: '(?=\S)' + pop: true + + annotation-group: + - meta_scope: meta.annotation.group.kotlin + - match: '\[' + scope: punctuation.section.brackets.begin.kotlin + - match: '\]' + scope: punctuation.section.brackets.end.kotlin + pop: true + - match: '{{identifier}}' + scope: entity.name.annotation.kotlin + - match: '\.' + scope: punctuation.accessor.dot.kotlin + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: annotation-arguments + + annotation-arguments: + - meta_scope: meta.annotation.arguments.kotlin + - match: '\)' + scope: punctuation.section.group.end.kotlin + pop: true + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: annotation-arguments + - match: '\[' + scope: punctuation.section.brackets.begin.kotlin + push: nested-brackets + - match: '\{' + scope: punctuation.section.block.begin.kotlin + push: nested-braces + - include: main + + strings: + - match: '"""' + scope: punctuation.definition.string.begin.kotlin + push: triple-string + - match: '"' + scope: punctuation.definition.string.begin.kotlin + push: line-string + + line-string: + - meta_include_prototype: false + - meta_scope: meta.string.kotlin string.quoted.double.kotlin + - match: '"' + scope: punctuation.definition.string.end.kotlin + pop: true + - match: '\$\{' + scope: punctuation.section.interpolation.begin.kotlin + push: string-interpolation + - match: '\${{identifier}}' + scope: variable.other.interpolated.kotlin + - match: '\\(?:[tbnr''"\\$]|u[0-9A-Fa-f]{4})' + scope: constant.character.escape.kotlin + - match: '[^\\$"]+' + - match: '\$' + + triple-string: + - meta_include_prototype: false + - meta_scope: meta.string.kotlin string.quoted.triple.kotlin + - match: '"{3,}' + scope: punctuation.definition.string.end.kotlin + pop: true + - match: '\$\{' + scope: punctuation.section.interpolation.begin.kotlin + push: string-interpolation + - match: '\${{identifier}}' + scope: variable.other.interpolated.kotlin + - match: '[^"$]+' + - match: '"{1,2}(?!")' + - match: '\$' + + string-interpolation: + - clear_scopes: 1 + - meta_scope: meta.interpolation.kotlin source.kotlin.embedded + - match: '\{' + scope: punctuation.section.block.begin.kotlin + push: interpolation-block + - match: '\bit\b' + scope: variable.language.kotlin + - match: '\}' + scope: punctuation.section.interpolation.end.kotlin + pop: true + - include: main + + interpolation-block: + - clear_scopes: 1 + - meta_scope: source.kotlin.embedded + - match: '\{' + scope: punctuation.section.block.begin.kotlin + push: interpolation-block + - match: '\bit\b' + scope: variable.language.kotlin + - match: '\}' + scope: punctuation.section.block.end.kotlin + pop: true + - include: main + + nested-parentheses: + - meta_scope: meta.group.kotlin + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: nested-parentheses + - match: '\)' + scope: punctuation.section.group.end.kotlin + pop: true + - match: '\[' + scope: punctuation.section.brackets.begin.kotlin + push: nested-brackets + - match: '\{' + scope: punctuation.section.block.begin.kotlin + push: nested-braces + - include: main + + nested-brackets: + - meta_scope: meta.brackets.kotlin + - match: '\[' + scope: punctuation.section.brackets.begin.kotlin + push: nested-brackets + - match: '\]' + scope: punctuation.section.brackets.end.kotlin + pop: true + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: nested-parentheses + - match: '\{' + scope: punctuation.section.block.begin.kotlin + push: nested-braces + - include: main + + nested-braces: + - meta_scope: meta.block.kotlin + - match: '\{' + scope: punctuation.section.block.begin.kotlin + push: nested-braces + - match: '\}' + scope: punctuation.section.block.end.kotlin + pop: true + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: nested-parentheses + - match: '\[' + scope: punctuation.section.brackets.begin.kotlin + push: nested-brackets + - include: main + + literals: + - match: '(?:0[xX]{{hex_digits}}|0[bB]{{bin_digits}}|{{dec_digits}})[uU][lL]?\b' + scope: constant.numeric.integer.kotlin + - match: '(?:0[xX]{{hex_digits}}|0[bB]{{bin_digits}}|{{dec_digits}})[lL]\b' + scope: constant.numeric.integer.kotlin + - match: '(?:{{dec_digits}}?\.{{dec_digits}}(?:[eE][+-]?{{dec_digits}})?|{{dec_digits}}[eE][+-]?{{dec_digits}}|{{dec_digits}}[fF])(?:[fF])?\b' + scope: constant.numeric.float.kotlin + - match: '0[xX]{{hex_digits}}\b' + scope: constant.numeric.integer.hexadecimal.kotlin + - match: '0[bB]{{bin_digits}}\b' + scope: constant.numeric.integer.binary.kotlin + - match: '{{dec_digits}}\b' + scope: constant.numeric.integer.decimal.kotlin + - match: '''(?:\\u[0-9A-Fa-f]{4}|\\[tbnr''"\\$]|[^''\\\r\n])''' + scope: constant.character.kotlin + - match: '\b(?:true|false)\b' + scope: constant.language.boolean.kotlin + - match: '\bnull\b' + scope: constant.language.null.kotlin + + targeted-keywords: + - match: '\b(return|continue|break)(@)({{identifier}})' + captures: + 1: keyword.control.flow.jump.kotlin + 2: punctuation.definition.label.kotlin + 3: entity.name.label.kotlin + - match: '\b(this|super)(@)({{identifier}})' + captures: + 1: variable.language.kotlin + 2: punctuation.definition.label.kotlin + 3: entity.name.label.kotlin + + where-clauses: + - match: '(?\s*(?:\{|$))' + scope: meta.type.kotlin support.type.kotlin + push: standalone-generic-type-tail + + standalone-generic-type-tail: + - match: '<' + scope: punctuation.definition.typeparameters.begin.kotlin + push: value-type-arguments + - match: '(?=\S)' + pop: true + + callable-references: + - match: '(::)(class)\b' + captures: + 1: punctuation.accessor.callable-reference.kotlin + 2: keyword.other.kotlin + - match: '(::)({{identifier}})' + captures: + 1: punctuation.accessor.callable-reference.kotlin + 2: variable.function.kotlin + + labels: + - match: '({{identifier}})(@)' + captures: + 1: entity.name.label.kotlin + 2: punctuation.definition.label.kotlin + + operators: + - match: '\?:' + scope: keyword.operator.elvis.kotlin + - match: '\?\.' + scope: punctuation.accessor.null-safe.kotlin + - match: '!!' + scope: keyword.operator.null-assertion.kotlin + - match: '!is\b' + scope: keyword.operator.word.kotlin + push: type-condition + - match: '!in\b' + scope: keyword.operator.word.kotlin + - match: '\bas\?' + scope: keyword.operator.word.kotlin + push: type-expression + - match: '\bas\b' + scope: keyword.operator.word.kotlin + push: type-expression + - match: '\bis\b' + scope: keyword.operator.word.kotlin + push: type-condition + - match: '\bin\b' + scope: keyword.operator.word.kotlin + - match: '\buntil\b' + scope: keyword.operator.word.kotlin + - match: '\bby\b' + scope: keyword.operator.word.kotlin + - match: '===' + scope: keyword.operator.comparison.kotlin + - match: '!==' + scope: keyword.operator.comparison.kotlin + - match: '==' + scope: keyword.operator.comparison.kotlin + - match: '!=' + scope: keyword.operator.comparison.kotlin + - match: '<=' + scope: keyword.operator.comparison.kotlin + - match: '>=' + scope: keyword.operator.comparison.kotlin + - match: '\.\.<' + scope: keyword.operator.range.kotlin + - match: '\.\.' + scope: keyword.operator.range.kotlin + - match: '->' + scope: punctuation.separator.when.kotlin + - match: '\+=' + scope: keyword.operator.assignment.augmented.kotlin + - match: '-=' + scope: keyword.operator.assignment.augmented.kotlin + - match: '\*=' + scope: keyword.operator.assignment.augmented.kotlin + - match: '/=' + scope: keyword.operator.assignment.augmented.kotlin + - match: '%=' + scope: keyword.operator.assignment.augmented.kotlin + - match: '=' + scope: keyword.operator.assignment.kotlin + - match: '\+\+' + scope: keyword.operator.arithmetic.kotlin + - match: '--' + scope: keyword.operator.arithmetic.kotlin + - match: '&&' + scope: keyword.operator.logical.kotlin + - match: '\|\|' + scope: keyword.operator.logical.kotlin + - match: '!' + scope: keyword.operator.logical.kotlin + - match: '\+' + scope: keyword.operator.arithmetic.kotlin + - match: '-' + scope: keyword.operator.arithmetic.kotlin + - match: '\*' + scope: keyword.operator.arithmetic.kotlin + - match: '/' + scope: keyword.operator.arithmetic.kotlin + - match: '%' + scope: keyword.operator.arithmetic.kotlin + - match: '<' + scope: keyword.operator.comparison.kotlin + - match: '>' + scope: keyword.operator.comparison.kotlin + - match: ':' + scope: punctuation.separator.type.kotlin + push: type-expression + - match: '\?' + scope: keyword.operator.nullable.kotlin + + keywords: + - match: '\b(?:if|else|when)\b' + scope: keyword.control.conditional.kotlin + - match: '\b(?:try|catch|finally)\b' + scope: keyword.control.exception.kotlin + - match: '\b(?:for|while|do)\b' + scope: keyword.control.loop.kotlin + - match: '\b(?:throw|return|continue|break)\b' + scope: keyword.control.flow.jump.kotlin + - match: '\b(?:this|super)\b' + scope: variable.language.kotlin + - match: '\b(?:constructor|init)\b' + scope: keyword.declaration.kotlin + - match: '\b(?:public|private|protected|internal|enum|sealed|annotation|data|inner|tailrec|operator|inline|infix|external|suspend|override|abstract|final|open|const|lateinit|vararg|noinline|crossinline|reified|expect|actual|companion|out)\b' + scope: storage.modifier.kotlin + + function-calls: + - match: '{{identifier}}(?=\s*<[^(){}\n]+>\s*\()' + scope: variable.function.kotlin + push: function-call-tail + - match: '{{identifier}}(?=\s*\()' + scope: variable.function.kotlin + push: function-call-tail + - match: '{{identifier}}(?=\s*\{)' + scope: variable.function.kotlin + push: function-call-tail + + function-call-tail: + - match: '<' + scope: punctuation.definition.typeparameters.begin.kotlin + push: value-type-arguments + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: function-call-arguments + - match: '\{' + scope: punctuation.section.block.begin.kotlin + push: lambda-body + - match: '(?=\S)' + pop: true + + function-call-arguments: + - match: '\(' + scope: punctuation.section.group.begin.kotlin + push: function-call-arguments + - match: '\)' + scope: punctuation.section.group.end.kotlin + pop: true + - include: main + + lambda-body: + - meta_scope: meta.lambda.kotlin + - match: '(?={{identifier}}\s*(?:,|->))' + push: lambda-parameters + - match: '\bit\b' + scope: variable.language.kotlin + - match: '\}' + scope: punctuation.section.block.end.kotlin + pop: true + - include: main + + lambda-parameters: + - match: '{{identifier}}(?=\s*(?:,|->))' + scope: variable.parameter.kotlin + - match: ',' + scope: punctuation.separator.sequence.kotlin + - match: '->' + scope: keyword.declaration.function.arrow.kotlin + pop: true + - match: '(?=\S)' + pop: true + + punctuation: + - match: '\{' + scope: punctuation.section.block.begin.kotlin + - match: '\}' + scope: punctuation.section.block.end.kotlin + - match: '\(' + scope: punctuation.section.group.begin.kotlin + - match: '\)' + scope: punctuation.section.group.end.kotlin + - match: '\[' + scope: punctuation.section.brackets.begin.kotlin + - match: '\]' + scope: punctuation.section.brackets.end.kotlin + - match: ',' + scope: punctuation.separator.sequence.kotlin + - match: ';' + scope: punctuation.terminator.statement.kotlin + - match: '\.' + scope: punctuation.accessor.dot.kotlin + + identifiers: + - match: '{{identifier}}' + scope: variable.other.readwrite.kotlin diff --git a/syntaxes/Swift.sublime-syntax b/syntaxes/Swift.sublime-syntax new file mode 100644 index 0000000..03eca97 --- /dev/null +++ b/syntaxes/Swift.sublime-syntax @@ -0,0 +1,199 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/3/syntax.html + +# This file is a porting of the Swift Language Reference +# https://docs.swift.org/swift-book/ReferenceManual/zzSummaryOfTheGrammar.html + +name: Swift +scope: source.swift + +file_extensions: + - swift + +variables: + identifier_head_unicode: \x00A8\x00AA\x00AD\x00AF\x00B2–\x00B5\x00B7–\x00BA\x00BC–\x00BE\x00C0–\x00D6\x00D8–\x00F6\x00F8–\x00FF\x0100–\x02FF\x0370–\x167F\x1681–\x180D\x180F–\x1DBF\x1E00–\x1FFF\x200B–\x200D\x202A–\x202E\x203F–\x2040\x2054\x2060–\x206F\x2070–\x20CF\x2100–\x218F\x2460–\x24FF\x2776–\x2793\x2C00–\x2DFF\x2E80–\x2FFF\x3004–\x3007\x3021–\x302F\x3031–\x303F\x3040–\xD7FF\xF900–\xFD3D\xFD40–\xFDCF\xFDF0–\xFE1F\xFE30–\xFE44\xFE47–\xFFFD\x10000–\x1FFFD\x20000–\x2FFFD\x30000–\x3FFFD\x40000–\x4FFFD\x50000–\x5FFFD\x60000–\x6FFFD\x70000–\x7FFFD\x80000–\x8FFFD\x90000–\x9FFFD\xA0000–\xAFFFD\xB0000–\xBFFFD\xC0000–\xCFFFD\xD0000–\xDFFFD\xE0000–\xEFFFD + identifier_head: '[a-zA-Z_{{identifier_head_unicode}}]' + identifier_character: '[0-9\x0300–\x036F\x1DC0–\x1DFF\x20D0–\x20FF\xFE20–\xFE2F{{identifier_head}}]' + line_break: '(?:\x0D\x0A?|\x0A)' + inline_space: '[\x09\x20]' + +contexts: + main: + - include: expression + + whitespace: + - include: line-break + - include: inline-spaces + - include: comment + - include: multiline-comment + - match: '[\x00\x0B\x0C]+' + + line-break: + - match: '{{line_break}}' + + inline-spaces: + - match: '{{inline_space}}+' + + comment: + - match: // + scope: punctuation.definition.comment.begin.swift + push: + - meta_scope: comment.line.swift + # TODO: add MARK section navigation + - match: '{{line_break}}' + pop: 1 + + multiline-comment: + - match: '/\*' + scope: punctuation.definition.comment.begin.swift + push: + - meta_scope: comment.block.swift + - include: multiline-comment + - match: '\*/' + scope: punctuation.definition.comment.end.swift + pop: 1 + + implicit-parameter-name: + - match: '\$[0-9]+\b' + + property-wrapper-projection: + - match: '\${{identifier_character}}+' + + identifier: + - match: '\b{{identifier_head}}{{identifier_character}}*' + scope: variable + - match: '`{{identifier_head}}{{identifier_character}}*`' + scope: variable + - include: implicit-parameter-name + - include: property-wrapper-projection + + integer-literal: + - match: \b(0b)([01][01_]*) + scope: meta.number.integer.binary.swift + captures: + 1: constant.numeric.base.swift + 2: constant.numeric.value.swift + - match: \b(0o)([0-7][0-7_]*) + scope: meta.number.integer.octal.swift + captures: + 1: constant.numeric.base.swift + 2: constant.numeric.value.swift + - match: \b(0x)([0-9a-fA-F][0-9a-fA-F_]*) + scope: meta.number.integer.hexadecimal.swift + captures: + 1: constant.numeric.base.swift + 2: constant.numeric.value.swift + - match: \b[0-9][0-9_]* + scope: meta.number.integer.decimal.swift constant.numeric.value.swift + + floating-point-literal: + - match: \b[0-9][0-9_]*(\.)[0-9][0-9_]*(?:[eE][\-+]?[0-9][0-9_]*)? + scope: meta.number.float.decimal.swift constant.numeric.value.swift + captures: + 1: punctuation.separator.decimal.swift + - match: \b(0x)([0-9a-fA-F][0-9a-fA-F_]*(\.)[0-9a-fA-F][0-9a-fA-F_]*(?:[pP][\-+]?[0-9][0-9_]*)?) + scope: meta.number.float.hexadecimal.swift + captures: + 1: constant.numeric.base.swift + 2: constant.numeric.value.swift + 3: punctuation.separator.decimal.swift + + string-literal: + - match: '#+"""' + scope: punctuation.definition.string.begin.swift + push: + - meta_scope: meta.string.swift string.quoted.double.block.swift + - match: '\\#+[0\\tnr"'']' + scope: constant.character.escape.swift + - match: '\\#+u\{[0-9a-fA-F]{1,8}\}' + scope: constant.character.escape.unicode.swift + - match: '\\#+\(' + scope: punctuation.section.interpolation.begin.swift + push: + - clear_scopes: 1 + - meta_scope: meta.interpolation.swift + - match: '\)' + scope: punctuation.section.interpolation.end.swift + pop: 1 + - match: '\\{{inline_space}}*{{line_break}}' + scope: punctuation.separator.continuation.line.swift + - match: '"""#+' + scope: punctuation.definition.string.end.swift + pop: 1 + - match: '"""' + scope: punctuation.definition.string.begin.swift + push: + - meta_scope: meta.string.swift string.quoted.double.block.swift + - match: '\\[0\\tnr"'']' + scope: constant.character.escape.swift + - match: '\\u\{[0-9a-fA-F]{1,8}\}' + scope: constant.character.escape.unicode.swift + - match: '\\\(' + scope: punctuation.section.interpolation.begin.swift + push: + - clear_scopes: 1 + - meta_scope: meta.interpolation.swift + - include: expression + - match: '\)' + scope: punctuation.section.interpolation.end.swift + pop: 1 + - match: '\\{{inline_space}}*{{line_break}}' + scope: punctuation.separator.continuation.line.swift + - match: '"""' + scope: punctuation.definition.string.end.swift + pop: 1 + - match: '#+"' + scope: punctuation.definition.string.begin.swift + push: + - meta_scope: meta.string.swift string.quoted.double.swift + - match: '\\#+[0\\tnr"'']' + scope: constant.character.escape.swift + - match: '\\#+u\{[0-9a-fA-F]{1,8}\}' + scope: constant.character.escape.unicode.swift + - match: '\\#+\(' + scope: punctuation.section.interpolation.begin.swift + push: + - clear_scopes: 1 + - meta_scope: meta.interpolation.swift + - include: expression + - match: '\)' + scope: punctuation.section.interpolation.end.swift + pop: 1 + - match: '{{line_break}}' + scope: invalid.illegal.unclosed-string.swift + pop: 1 + - match: '"#+' + scope: punctuation.definition.string.end.swift + pop: 1 + - match: '"' + scope: punctuation.definition.string.begin.swift + push: + - meta_scope: meta.string.swift string.quoted.double.swift + - match: '\\[0\\tnr"'']' + scope: constant.character.escape.swift + - match: '\\u\{[0-9a-fA-F]{1,8}\}' + scope: constant.character.escape.unicode.swift + - match: '\\\(' + scope: punctuation.section.interpolation.begin.swift + push: + - clear_scopes: 1 + - meta_scope: meta.interpolation.swift + - include: expression + - match: '\)' + scope: punctuation.section.interpolation.end.swift + pop: 1 + - match: '\\' + scope: invalid.illegal.unexpected-text.swift + - match: '{{line_break}}' + scope: invalid.illegal.unclosed-string.swift + pop: 1 + - match: '"' + scope: punctuation.definition.string.end.swift + pop: 1 + + expression: + - include: whitespace + - include: string-literal + - include: floating-point-literal + - include: integer-literal