Skip to content

Commit ffa0658

Browse files
committed
Splited docs.
1 parent 8d2a049 commit ffa0658

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+16345
-15958
lines changed

doc/docs/.vitepress/config.mts

Lines changed: 138 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,140 @@ const moonscriptLanguage = {
1515
aliases: ['yue', 'yuescript', 'moon'],
1616
}
1717

18+
// Generate sidebar configuration function
19+
function createSidebar(basePath: string, zh: boolean) {
20+
return [
21+
{
22+
text: zh ? '介绍' : 'Introduction',
23+
link: `${basePath}/introduction`,
24+
},
25+
{
26+
text: zh ? '安装' : 'Installation',
27+
link: `${basePath}/installation`,
28+
},
29+
{
30+
text: zh ? '使用方法' : 'Usage',
31+
link: `${basePath}/usage`,
32+
},
33+
{
34+
text: zh ? '宏' : 'Macro',
35+
link: `${basePath}/macro`,
36+
},
37+
{
38+
text: zh ? '操作符' : 'Operator',
39+
link: `${basePath}/operator`,
40+
},
41+
{
42+
text: zh ? '模块' : 'Module',
43+
link: `${basePath}/module`,
44+
},
45+
{
46+
text: zh ? '赋值' : 'Assignment',
47+
link: `${basePath}/assignment`,
48+
},
49+
{
50+
text: zh ? '解构赋值' : 'Destructuring Assignment',
51+
link: `${basePath}/destructuring-assignment`,
52+
},
53+
{
54+
text: zh ? 'If 赋值' : 'If Assignment',
55+
link: `${basePath}/if-assignment`,
56+
},
57+
{
58+
text: zh ? '可变参数赋值' : 'Varargs Assignment',
59+
link: `${basePath}/varargs-assignment`,
60+
},
61+
{
62+
text: zh ? '空白' : 'Whitespace',
63+
link: `${basePath}/whitespace`,
64+
},
65+
{
66+
text: zh ? '注释' : 'Comment',
67+
link: `${basePath}/comment`,
68+
},
69+
{
70+
text: zh ? '错误处理' : 'Try',
71+
link: `${basePath}/try`,
72+
},
73+
{
74+
text: zh ? '属性' : 'Attributes',
75+
link: `${basePath}/attributes`,
76+
},
77+
{
78+
text: zh ? '字面量' : 'Literals',
79+
link: `${basePath}/literals`,
80+
},
81+
{
82+
text: zh ? '函数字面量' : 'Function Literals',
83+
link: `${basePath}/function-literals`,
84+
},
85+
{
86+
text: zh ? '反向回调' : 'Backcalls',
87+
link: `${basePath}/backcalls`,
88+
},
89+
{
90+
text: zh ? '表格字面量' : 'Table Literals',
91+
link: `${basePath}/table-literals`,
92+
},
93+
{
94+
text: zh ? '推导式' : 'Comprehensions',
95+
link: `${basePath}/comprehensions`,
96+
},
97+
{
98+
text: zh ? 'for 循环' : 'For Loop',
99+
link: `${basePath}/for-loop`,
100+
},
101+
{
102+
text: zh ? 'while 循环' : 'While Loop',
103+
link: `${basePath}/while-loop`,
104+
},
105+
{
106+
text: zh ? 'continue 语句' : 'Continue Statement',
107+
link: `${basePath}/continue`,
108+
},
109+
{
110+
text: zh ? '条件语句' : 'Conditionals',
111+
link: `${basePath}/conditionals`,
112+
},
113+
{
114+
text: zh ? '代码行修饰符' : 'Line Decorators',
115+
link: `${basePath}/line-decorators`,
116+
},
117+
{
118+
text: zh ? 'switch 语句' : 'Switch',
119+
link: `${basePath}/switch`,
120+
},
121+
{
122+
text: zh ? '面向对象编程' : 'Object Oriented Programming',
123+
link: `${basePath}/object-oriented-programming`,
124+
},
125+
{
126+
text: zh ? 'with 语句' : 'With Statement',
127+
link: `${basePath}/with-statement`,
128+
},
129+
{
130+
text: zh ? 'do 语句' : 'Do',
131+
link: `${basePath}/do`,
132+
},
133+
{
134+
text: zh ? '函数存根' : 'Function Stubs',
135+
link: `${basePath}/function-stubs`,
136+
},
137+
{
138+
text: zh ? '使用 using 语句:防止破坏性赋值' : 'The Using Clause; Controlling Destructive Assignment',
139+
link: `${basePath}/the-using-clause-controlling-destructive-assignment`,
140+
},
141+
{
142+
text: zh ? '月之脚本语言库' : 'The YueScript Library',
143+
link: `${basePath}/the-yuescript-library`,
144+
},
145+
{
146+
text: zh ? 'MIT 许可证' : 'Licence: MIT',
147+
link: `${basePath}/licence-mit`,
148+
},
149+
]
150+
}
151+
18152
export default defineConfig({
19153
title: 'YueScript',
20154
description: 'A language that compiles to Lua',
@@ -84,7 +218,8 @@ export default defineConfig({
84218
{ text: 'Document', link: '/doc/' },
85219
{ text: 'Try yue!', link: '/try/' },
86220
{ text: 'Github', link: 'https://github.com/IppClub/Yuescript' }
87-
]
221+
],
222+
sidebar: createSidebar('/doc', false),
88223
}
89224
},
90225
zh: {
@@ -96,7 +231,8 @@ export default defineConfig({
96231
{ text: '文档', link: '/zh/doc/' },
97232
{ text: '试一试!', link: '/zh/try/' },
98233
{ text: 'Github', link: 'https://github.com/IppClub/Yuescript' }
99-
]
234+
],
235+
sidebar: createSidebar('/zh/doc', true),
100236
}
101237
}
102238
}

doc/docs/.vitepress/theme/components/YueCompiler.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const lightPlusTheme = EditorView.theme(
4646
height: '100%',
4747
backgroundColor: '#FFFFFF',
4848
color: '#000000',
49-
fontSize: '0.8em'
49+
fontSize: '14px'
5050
},
5151
'&.cm-focused': {
5252
outline: 'none'
@@ -90,7 +90,7 @@ const darkPlusTheme = EditorView.theme(
9090
height: '100%',
9191
backgroundColor: '#1E1E1E',
9292
color: '#D4D4D4',
93-
fontSize: '0.8em'
93+
fontSize: '14px'
9494
},
9595
'&.cm-focused': {
9696
outline: 'none'

doc/docs/.vitepress/theme/custom.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
.code-output code {
2020
background: #ffffff;
2121
color: #000000;
22+
font-size: 14px;
2223
}
2324

2425
.dark .code-output,

doc/docs/.vitepress/theme/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import DefaultTheme from 'vitepress/theme'
22
import type { Theme } from 'vitepress'
3+
import { h } from 'vue'
34
import './custom.css'
45

56
// @ts-ignore
@@ -11,6 +12,10 @@ import YueDisplay from './components/YueDisplay.vue'
1112

1213
const theme: Theme = {
1314
extends: DefaultTheme,
15+
Layout: () =>
16+
h(DefaultTheme.Layout, null, {
17+
'layout-bottom': () => h(CompilerModal)
18+
}),
1419
enhanceApp({ app }) {
1520
app.component('CompilerModal', CompilerModal)
1621
app.component('YueCompiler', YueCompiler)

doc/docs/doc/assignment.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Assignment
2+
3+
The variable is dynamic typed and is defined as local by default. But you can change the scope of declaration by **local** and **global** statement.
4+
5+
```yuescript
6+
hello = "world"
7+
a, b, c = 1, 2, 3
8+
hello = 123 -- uses the existing variable
9+
```
10+
<YueDisplay>
11+
12+
```yue
13+
hello = "world"
14+
a, b, c = 1, 2, 3
15+
hello = 123 -- uses the existing variable
16+
```
17+
18+
</YueDisplay>
19+
20+
## Perform Update
21+
22+
You can perform update assignment with many binary operators.
23+
```yuescript
24+
x = 1
25+
x += 1
26+
x -= 1
27+
x *= 10
28+
x /= 10
29+
x %= 10
30+
s ..= "world" -- will add a new local if local variable is not exist
31+
arg or= "default value"
32+
```
33+
<YueDisplay>
34+
35+
```yue
36+
x = 1
37+
x += 1
38+
x -= 1
39+
x *= 10
40+
x /= 10
41+
x %= 10
42+
s ..= "world" -- will add a new local if local variable is not exist
43+
arg or= "default value"
44+
```
45+
46+
</YueDisplay>
47+
48+
## Chaining Assignment
49+
50+
You can do chaining assignment to assign multiple items to hold the same value.
51+
```yuescript
52+
a = b = c = d = e = 0
53+
x = y = z = f!
54+
```
55+
<YueDisplay>
56+
57+
```yue
58+
a = b = c = d = e = 0
59+
x = y = z = f!
60+
```
61+
62+
</YueDisplay>
63+
64+
## Explicit Locals
65+
```yuescript
66+
do
67+
local a = 1
68+
local *
69+
print "forward declare all variables as locals"
70+
x = -> 1 + y + z
71+
y, z = 2, 3
72+
global instance = Item\new!
73+
74+
do
75+
local X = 1
76+
local ^
77+
print "only forward declare upper case variables"
78+
a = 1
79+
B = 2
80+
```
81+
<YueDisplay>
82+
83+
```yue
84+
do
85+
local a = 1
86+
local *
87+
print "forward declare all variables as locals"
88+
x = -> 1 + y + z
89+
y, z = 2, 3
90+
global instance = Item\new!
91+
92+
do
93+
local X = 1
94+
local ^
95+
print "only forward declare upper case variables"
96+
a = 1
97+
B = 2
98+
```
99+
100+
</YueDisplay>
101+
102+
## Explicit Globals
103+
```yuescript
104+
do
105+
global a = 1
106+
global *
107+
print "declare all variables as globals"
108+
x = -> 1 + y + z
109+
y, z = 2, 3
110+
111+
do
112+
global X = 1
113+
global ^
114+
print "only declare upper case variables as globals"
115+
a = 1
116+
B = 2
117+
local Temp = "a local value"
118+
```
119+
<YueDisplay>
120+
121+
```yue
122+
do
123+
global a = 1
124+
global *
125+
print "declare all variables as globals"
126+
x = -> 1 + y + z
127+
y, z = 2, 3
128+
129+
do
130+
global X = 1
131+
global ^
132+
print "only declare upper case variables as globals"
133+
a = 1
134+
B = 2
135+
local Temp = "a local value"
136+
```
137+
138+
</YueDisplay>

doc/docs/doc/attributes.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Attributes
2+
3+
Syntax support for Lua 5.4 attributes. And you can still use both the `const` and `close` declaration and get constant check and scoped callback working when targeting Lua versions below 5.4.
4+
5+
```yuescript
6+
const a = 123
7+
close _ = <close>: -> print "Out of scope."
8+
```
9+
<YueDisplay>
10+
11+
```yue
12+
const a = 123
13+
close _ = <close>: -> print "Out of scope."
14+
```
15+
16+
</YueDisplay>
17+
18+
You can do desctructuring with variables attributed as constant.
19+
20+
```yuescript
21+
const {:a, :b, c, d} = tb
22+
-- a = 1
23+
```
24+
<YueDisplay>
25+
26+
```yue
27+
const {:a, :b, c, d} = tb
28+
-- a = 1
29+
```
30+
31+
</YueDisplay>
32+
33+
You can also declare a global variable to be `const`.
34+
35+
```yuescript
36+
global const Constant = 123
37+
-- Constant = 1
38+
```
39+
<YueDisplay>
40+
41+
```yue
42+
global const Constant = 123
43+
-- Constant = 1
44+
```
45+
46+
</YueDisplay>

0 commit comments

Comments
 (0)