From e4f8d1b3b075323968bb6dc334226dff33c0a2b0 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 3 Feb 2026 22:42:37 +0800 Subject: Updated doc. --- doc/docs/.vitepress/public/image/yuescript.svg | 2 +- .../.vitepress/theme/components/YueCompiler.vue | 46 ++++++++++++---------- doc/docs/.vitepress/theme/custom.css | 42 +++++++++++++++----- doc/docs/.vitepress/theme/index.ts | 3 ++ doc/docs/doc/index.md | 10 ++--- doc/docs/index.md | 4 +- doc/docs/zh/doc/index.md | 18 ++++----- doc/docs/zh/index.md | 4 +- spec/inputs/compile_doc.yue | 4 +- spec/outputs/codes_from_doc.lua | 34 +++++++++++++++- spec/outputs/codes_from_doc_zh.lua | 34 +++++++++++++++- spec/outputs/compile_doc.lua | 10 ++--- 12 files changed, 151 insertions(+), 60 deletions(-) diff --git a/doc/docs/.vitepress/public/image/yuescript.svg b/doc/docs/.vitepress/public/image/yuescript.svg index 71214fe..f81e533 100644 --- a/doc/docs/.vitepress/public/image/yuescript.svg +++ b/doc/docs/.vitepress/public/image/yuescript.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/doc/docs/.vitepress/theme/components/YueCompiler.vue b/doc/docs/.vitepress/theme/components/YueCompiler.vue index 28a6a9f..dcea692 100755 --- a/doc/docs/.vitepress/theme/components/YueCompiler.vue +++ b/doc/docs/.vitepress/theme/components/YueCompiler.vue @@ -39,24 +39,25 @@ import { history, indentWithTab } from '@codemirror/commands' import { defaultKeymap, historyKeymap } from '@codemirror/commands' import { simpleMode } from '@codemirror/legacy-modes/mode/simple-mode' -const vscodeLightTheme = EditorView.theme( +/* shikijs/themes/light-plus: editor.background #FFFFFF, editor.foreground #000000 */ +const lightPlusTheme = EditorView.theme( { '&': { height: '100%', - backgroundColor: '#ffffff', + backgroundColor: '#FFFFFF', color: '#000000', - fontSize: '15px' + fontSize: '0.8em' }, '&.cm-focused': { outline: 'none' }, '.cm-content': { fontFamily: - "Consolas, Menlo, Monaco, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Liberation Mono', 'Nimbus Mono L', 'Courier New', Courier, monospace", + "ui-monospace, 'Menlo', 'Monaco', 'Consolas', 'Liberation Mono', 'Courier New', monospace", lineHeight: '1.375' }, '.cm-gutters': { - backgroundColor: '#ffffff', + backgroundColor: '#FFFFFF', color: '#6e6e6e', borderRight: 'none' }, @@ -82,24 +83,25 @@ const vscodeLightTheme = EditorView.theme( { dark: false } ) -const vscodeDarkTheme = EditorView.theme( +/* shikijs/themes/dark-plus: editor.background #1E1E1E, editor.foreground #D4D4D4 */ +const darkPlusTheme = EditorView.theme( { '&': { height: '100%', - backgroundColor: '#1e1e1e', - color: '#d4d4d4', - fontSize: '15px' + backgroundColor: '#1E1E1E', + color: '#D4D4D4', + fontSize: '0.8em' }, '&.cm-focused': { outline: 'none' }, '.cm-content': { fontFamily: - "Consolas, Menlo, Monaco, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Liberation Mono', 'Nimbus Mono L', 'Courier New', Courier, monospace", + "ui-monospace, 'Menlo', 'Monaco', 'Consolas', 'Liberation Mono', 'Courier New', monospace", lineHeight: '1.375' }, '.cm-gutters': { - backgroundColor: '#1e1e1e', + backgroundColor: '#1E1E1E', color: '#858585', borderRight: 'none' }, @@ -125,16 +127,17 @@ const vscodeDarkTheme = EditorView.theme( { dark: true } ) -const vscodeLightHighlightStyle = HighlightStyle.define([ +/* shikijs/themes/light-plus tokenColors */ +const lightPlusHighlightStyle = HighlightStyle.define([ { tag: tags.comment, color: '#008000' }, - { tag: tags.keyword, color: '#0000ff' }, + { tag: tags.keyword, color: '#AF00DB' }, { tag: [tags.operator, tags.punctuation], color: '#000000' }, { tag: [tags.string, tags.special(tags.string)], color: '#a31515' }, + { tag: tags.regexp, color: '#811f3f' }, { tag: [tags.number, tags.bool, tags.null], color: '#098658' }, { tag: tags.function(tags.variableName), color: '#795e26' }, { tag: tags.typeName, color: '#267f99' }, { tag: tags.className, color: '#267f99' }, - { tag: tags.variableName, color: '#001080' }, { tag: tags.propertyName, color: '#001080' }, { tag: tags.tagName, color: '#800000' }, { tag: tags.attributeName, color: '#e50000' }, @@ -142,16 +145,17 @@ const vscodeLightHighlightStyle = HighlightStyle.define([ { tag: tags.invalid, color: '#cd3131' } ]) -const vscodeDarkHighlightStyle = HighlightStyle.define([ +/* shikijs/themes/dark-plus tokenColors */ +const darkPlusHighlightStyle = HighlightStyle.define([ { tag: tags.comment, color: '#6a9955' }, - { tag: tags.keyword, color: '#569cd6' }, + { tag: tags.keyword, color: '#C586C0' }, { tag: [tags.operator, tags.punctuation], color: '#d4d4d4' }, { tag: [tags.string, tags.special(tags.string)], color: '#ce9178' }, + { tag: tags.regexp, color: '#d16969' }, { tag: [tags.number, tags.bool, tags.null], color: '#b5cea8' }, { tag: tags.function(tags.variableName), color: '#dcdcaa' }, { tag: tags.typeName, color: '#4ec9b0' }, { tag: tags.className, color: '#4ec9b0' }, - { tag: tags.variableName, color: '#9cdcfe' }, { tag: tags.propertyName, color: '#9cdcfe' }, { tag: tags.tagName, color: '#569cd6' }, { tag: tags.attributeName, color: '#9cdcfe' }, @@ -328,12 +332,12 @@ export default { this.readOnlyCompartment.of(EditorState.readOnly.of(this.readonly)), this.highlightCompartment.of( syntaxHighlighting( - isDark ? vscodeDarkHighlightStyle : vscodeLightHighlightStyle, + isDark ? darkPlusHighlightStyle : lightPlusHighlightStyle, { fallback: true } ) ), updateListener, - this.themeCompartment.of(isDark ? vscodeDarkTheme : vscodeLightTheme) + this.themeCompartment.of(isDark ? darkPlusTheme : lightPlusTheme) ] }) @@ -350,11 +354,11 @@ export default { this.editorView.dispatch({ effects: [ this.themeCompartment.reconfigure( - isDark ? vscodeDarkTheme : vscodeLightTheme + isDark ? darkPlusTheme : lightPlusTheme ), this.highlightCompartment.reconfigure( syntaxHighlighting( - isDark ? vscodeDarkHighlightStyle : vscodeLightHighlightStyle, + isDark ? darkPlusHighlightStyle : lightPlusHighlightStyle, { fallback: true } ) ) diff --git a/doc/docs/.vitepress/theme/custom.css b/doc/docs/.vitepress/theme/custom.css index 9085b4b..7b4e593 100644 --- a/doc/docs/.vitepress/theme/custom.css +++ b/doc/docs/.vitepress/theme/custom.css @@ -14,7 +14,7 @@ max-width: 450px !important; } -/* Prism theme for YueCompiler output (VS Code Light/Dark) */ +/* Prism theme for YueCompiler output (shikijs/themes light-plus & dark-plus) */ .code-output, .code-output code { background: #ffffff; @@ -27,12 +27,13 @@ color: #d4d4d4; } +/* light-plus */ .code-output .token.comment { color: #008000; } .code-output .token.keyword { - color: #0000ff; + color: #AF00DB; } .code-output .token.operator, @@ -41,12 +42,19 @@ } .code-output .token.string, -.code-output .token.char, -.code-output .token.regex, -.code-output .token.variable { +.code-output .token.char { color: #a31515; } +.code-output .token.regex { + color: #811f3f; +} + +.code-output .token.variable, +.code-output .token.parameter { + color: #001080; +} + .code-output .token.number, .code-output .token.boolean, .code-output .token.constant { @@ -62,12 +70,17 @@ color: #267f99; } +.code-output .token.invalid { + color: #cd3131; +} + +/* dark-plus */ .dark .code-output .token.comment { color: #6a9955; } .dark .code-output .token.keyword { - color: #569cd6; + color: #C586C0; } .dark .code-output .token.operator, @@ -76,12 +89,19 @@ } .dark .code-output .token.string, -.dark .code-output .token.char, -.dark .code-output .token.regex, -.dark .code-output .token.variable { +.dark .code-output .token.char { color: #ce9178; } +.dark .code-output .token.regex { + color: #d16969; +} + +.dark .code-output .token.variable, +.dark .code-output .token.parameter { + color: #9cdcfe; +} + .dark .code-output .token.number, .dark .code-output .token.boolean, .dark .code-output .token.constant { @@ -96,3 +116,7 @@ .dark .code-output .token.builtin { color: #4ec9b0; } + +.dark .code-output .token.invalid { + color: #f44747; +} diff --git a/doc/docs/.vitepress/theme/index.ts b/doc/docs/.vitepress/theme/index.ts index e2a44c6..398df17 100644 --- a/doc/docs/.vitepress/theme/index.ts +++ b/doc/docs/.vitepress/theme/index.ts @@ -2,8 +2,11 @@ import DefaultTheme from 'vitepress/theme' import type { Theme } from 'vitepress' import './custom.css' +// @ts-ignore import CompilerModal from './components/CompilerModal.vue' +// @ts-ignore import YueCompiler from './components/YueCompiler.vue' +// @ts-ignore import YueDisplay from './components/YueDisplay.vue' const theme: Theme = { diff --git a/doc/docs/doc/index.md b/doc/docs/doc/index.md index 6998747..6de2ce7 100755 --- a/doc/docs/doc/index.md +++ b/doc/docs/doc/index.md @@ -2908,7 +2908,7 @@ thing = { width: 123 } -thing_copy = \{k, v for k, v in pairs thing} +thing_copy = {k, v for k, v in pairs thing} ``` @@ -2919,7 +2919,7 @@ no_color = {k, v for k, v in pairs thing when k != "color"} ```yue -no_color = \{k, v for k, v in pairs thing when k != "color"} +no_color = {k, v for k, v in pairs thing when k != "color"} ``` @@ -2934,7 +2934,7 @@ sqrts = {i, math.sqrt i for i in *numbers} ```yue numbers = [1, 2, 3, 4] -sqrts = \{i, math.sqrt i for i in *numbers} +sqrts = {i, math.sqrt i for i in *numbers} ``` @@ -2951,7 +2951,7 @@ tbl = {unpack tuple for tuple in *tuples} ```yue tuples = [ ["hello", "world"], ["foo", "bar"]] -tbl = \{unpack tuple for tuple in *tuples} +tbl = {unpack tuple for tuple in *tuples} ``` @@ -4751,7 +4751,7 @@ to_lua: function(code: string, config?: Config): | --- | --- | | string \| nil | The compiled Lua code, or nil if the compilation failed. | | string \| nil | The error message, or nil if the compilation succeeded. | -| \{\{string, integer, integer}} \| nil | The global variables appearing in the code (with name, row and column), or nil if the compiler option `lint_global` is false. | +| {{string, integer, integer}} \| nil | The global variables appearing in the code (with name, row and column), or nil if the compiler option `lint_global` is false. | #### file_exist diff --git a/doc/docs/index.md b/doc/docs/index.md index a8c43d2..0ce1284 100644 --- a/doc/docs/index.md +++ b/doc/docs/index.md @@ -15,8 +15,8 @@ features: details: Write concise syntax that compiles to readable Lua, with predictable output. - title: Modern language features details: Pipe, pattern matching, slicing, and destructuring without giving up Lua interop. - - title: Tooling built in - details: Browser-based playground, syntax highlighting, and docs that stay in sync. + - title: Rapid Iteration + details: Any feedback is welcome to help accelerate the language development and evolution! footer: MIT Licensed | Copyright © 2017-2026 Li Jin --- diff --git a/doc/docs/zh/doc/index.md b/doc/docs/zh/doc/index.md index dff51a9..5250325 100755 --- a/doc/docs/zh/doc/index.md +++ b/doc/docs/zh/doc/index.md @@ -2858,7 +2858,7 @@ thing = { width: 123 } -thing_copy = \{k, v for k, v in pairs thing} +thing_copy = {k, v for k, v in pairs thing} ``` @@ -2869,7 +2869,7 @@ no_color = {k, v for k, v in pairs thing when k != "color"} ```yue -no_color = \{k, v for k, v in pairs thing when k != "color"} +no_color = {k, v for k, v in pairs thing when k != "color"} ``` @@ -2884,7 +2884,7 @@ sqrts = {i, math.sqrt i for i in *numbers} ```yue numbers = [1, 2, 3, 4] -sqrts = \{i, math.sqrt i for i in *numbers} +sqrts = {i, math.sqrt i for i in *numbers} ``` @@ -2901,7 +2901,7 @@ tbl = {unpack tuple for tuple in *tuples} ```yue tuples = [ ["hello", "world"], ["foo", "bar"]] -tbl = \{unpack tuple for tuple in *tuples} +tbl = {unpack tuple for tuple in *tuples} ``` @@ -3588,7 +3588,7 @@ switch item ```yue -item = \{} +item = {} {pos: {:x = 50, :y = 200}} = item -- 获取错误:尝试索引nil值(字段'pos') @@ -3748,7 +3748,7 @@ class Inventory ```yue class Inventory new: => - @items = \{} + @items = {} add_item: (name) => if @items[name] @@ -4463,7 +4463,7 @@ tbl = { ```yue -tbl = \{ +tbl = { key: do print "分配键值!" 1234 @@ -4501,7 +4501,7 @@ run_callback my_object\write ```yue -my_object = \{ +my_object = { value: 1000 write: => print "值为:", @value } @@ -4698,7 +4698,7 @@ to_lua: function(code: string, config?: Config): | --- | --- | | string \| nil | 编译后的 Lua 代码,如果编译失败则为 nil。 | | string \| nil | 错误消息,如果编译成功则为 nil。 | -| \{\{string, integer, integer}} \| nil | 代码中出现的全局变量(带有名称、行和列),如果编译器选项 `lint_global` 为 false 则为 nil。 | +| {{string, integer, integer}} \| nil | 代码中出现的全局变量(带有名称、行和列),如果编译器选项 `lint_global` 为 false 则为 nil。 | #### file_exist diff --git a/doc/docs/zh/index.md b/doc/docs/zh/index.md index 6d677e9..9068956 100644 --- a/doc/docs/zh/index.md +++ b/doc/docs/zh/index.md @@ -15,8 +15,8 @@ features: details: 更精简的语法,编译为可读 Lua,输出可预测、易集成。 - title: 现代语言特性 details: 管道、模式匹配、切片与解构,同时保留 Lua 互操作性。 - - title: 内置工具链 - details: 在线 Playground、语法高亮与同步更新的文档。 + - title: 快速迭代 + details: 虚心接受用户反馈,以帮助改进和加速语言的开发和演进! footer: MIT Licensed | Copyright © 2017-2026 Li Jin --- diff --git a/spec/inputs/compile_doc.yue b/spec/inputs/compile_doc.yue index c189c17..db0464b 100644 --- a/spec/inputs/compile_doc.yue +++ b/spec/inputs/compile_doc.yue @@ -7,13 +7,13 @@ for [compiledFile, docFile] in *[ import "yue" as :to_lua text = \read "*a" codes = [] - for code in text\gmatch "```moonscript(.-)```" + for code in text\gmatch "```yuescript[\r\n]+(.-)```[^%w]" if result, err := to_lua code, implicit_return_root: false, reserve_line_number: false codes[] = result elseif not err\match "macro exporting module only accepts macro definition" print err os.exit 1 - for code in text\gmatch "```yue(.-)```" + for code in text\gmatch "```yue[\r\n]+(.-)```[^%w]" if result, err := to_lua code, implicit_return_root: false, reserve_line_number: false codes[] = result else diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index 3b0724a..b8985e7 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua @@ -107,7 +107,7 @@ if cond then end end print("yuescript") -print(3) +print(2) print("Valid enum type:", "Static") do print(123, "hello") @@ -992,6 +992,36 @@ local arg1 = { a = 0 } f2(arg1, arg2) +local findFirstEven +findFirstEven = function(list) + for _index_0 = 1, #list do + local item = list[_index_0] + if type(item) == "table" then + for _index_1 = 1, #item do + local sub = item[_index_1] + if sub % 2 == 0 then + return sub + end + end + end + end + return nil +end +local findFirstEven +findFirstEven = function(list) + for _index_0 = 1, #list do + local item = list[_index_0] + if type(item) == "table" then + for _index_1 = 1, #item do + local sub = item[_index_1] + if sub % 2 == 0 then + return sub + end + end + end + end + return nil +end local f f = function(...) local t = { @@ -2637,7 +2667,7 @@ if cond then end end print("yuescript") -print(3) +print(2) print("Valid enum type:", "Static") do print(123, "hello") diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index 89335c9..2aa354e 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua @@ -107,7 +107,7 @@ if cond then end end print("yuescript") -print(3) +print(2) print("有效的枚举类型:", "Static") do print(123, "hello") @@ -986,6 +986,36 @@ local arg1 = { a = 0 } f2(arg1, arg2) +local findFirstEven +findFirstEven = function(list) + for _index_0 = 1, #list do + local item = list[_index_0] + if type(item) == "table" then + for _index_1 = 1, #item do + local sub = item[_index_1] + if sub % 2 == 0 then + return sub + end + end + end + end + return nil +end +local findFirstEven +findFirstEven = function(list) + for _index_0 = 1, #list do + local item = list[_index_0] + if type(item) == "table" then + for _index_1 = 1, #item do + local sub = item[_index_1] + if sub % 2 == 0 then + return sub + end + end + end + end + return nil +end local f f = function(...) local t = { @@ -2631,7 +2661,7 @@ if cond then end end print("yuescript") -print(3) +print(2) print("有效的枚举类型:", "Static") do print(123, "hello") diff --git a/spec/outputs/compile_doc.lua b/spec/outputs/compile_doc.lua index 3781fb9..e7d307d 100644 --- a/spec/outputs/compile_doc.lua +++ b/spec/outputs/compile_doc.lua @@ -2,11 +2,11 @@ local outputFolder = ... local _list_0 = { { "codes_from_doc.lua", - "doc/docs/doc/README.md" + "doc/docs/doc/index.md" }, { "codes_from_doc_zh.lua", - "doc/docs/zh/doc/README.md" + "doc/docs/zh/doc/index.md" } } for _index_0 = 1, #_list_0 do @@ -18,7 +18,7 @@ for _index_0 = 1, #_list_0 do local to_lua = require("yue").to_lua local text = _with_0:read("*a") local codes = { } - for code in text:gmatch("```moonscript(.-)```") do + for code in text:gmatch("```yuescript[\r\n]+(.-)```[^%w]") do local result, err = to_lua(code, { implicit_return_root = false, reserve_line_number = false @@ -30,8 +30,8 @@ for _index_0 = 1, #_list_0 do os.exit(1) end end - for code in text:gmatch("
(.-)
") do - local result, err = to_lua(code:gsub("<", "<"):gsub(">", ">"), { + for code in text:gmatch("```yue[\r\n]+(.-)```[^%w]") do + local result, err = to_lua(code, { implicit_return_root = false, reserve_line_number = false }) -- cgit v1.2.3-55-g6feb