Skip to content

Commit 654ad4b

Browse files
authored
Merge branch 'master' into chore/test-improve
2 parents 60750c9 + 26ef342 commit 654ad4b

22 files changed

+1412
-798
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ build/wenyan-win.exe
66
temp
77
dist
88
/tools/calendar.html
9+
藏書樓

CHANGELOG.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
# v0.2.3
2+
3+
## 序.wy
4+
5+
Think `序.wy` the Wenyan version of `index.js`.
6+
7+
For example, the reader now will search for a module `四庫全書` for a given path `/tmp/examples`
8+
9+
- `/tmp/examples/四庫全書.wy`
10+
- `/tmp/examples/四庫全書/序.wy`
11+
12+
The first match will be imported. Refer to #512 for more details.
13+
14+
## 藏書樓
15+
16+
Think `藏書樓` the Wenyan version of `node_modules`.
17+
18+
`藏書樓` will be included as `importPaths` by CLI automatically. It will do an up searching for `藏書樓` from the cwd (just as node did)
19+
20+
21+
# v0.2.2
22+
23+
## New Website Domain http://wy-lang.org!
24+
25+
We are now using Netlify to build our website & IDE. The legacy links will redirect to http://wy-lang.org automatically.
26+
27+
- New spec page, [check it out](https://wy-lang.org/spec)
28+
29+
## Features
30+
- New option `importPaths` for specifying the import searching directories, (PR #499, by @antfu)
31+
- New option `allowHttp` for allowing import scripts from the web (default to `false`). refer to #499 for more details.
32+
33+
## Fixes
34+
- Fix for mismatched scope begin/end in typecheck (PR #496, thanks @statementreply)
35+
- Stdlib: Fix for some 曆法 functions (PR #503, thanks @statementreply)
36+
- Stdlib: Improve asin, acos and atan (PR #511, thanks @statementreply)
37+
38+
## Examples
39+
- New example Pascal Triangle (PR #498, thanks @MerakDipper)
40+
141
# v0.2.1
242

343
## Static Type Inference

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
<img src="screenshots/logo.png" align="right" width="100" height="100"/>
1+
<img src="screenshots/logo.png" align="right" width="128" height="128"/>
22

33
# 文言 wenyan-lang
44

55
[![npm](https://img.shields.io/npm/v/@wenyanlang/core)](https://www.npmjs.com/package/@wenyanlang/core)
66
[![build](https://img.shields.io/github/workflow/status/LingDong-/wenyan-lang/Build%20%26%20Test)](https://github.com/LingDong-/wenyan-lang/actions)
7+
[![Netlify Status](https://api.netlify.com/api/v1/badges/c36d4838-1c8f-4cfe-986e-43e0de6f71a3/deploy-status)](https://app.netlify.com/sites/wenyan-lang/deploys)
78

8-
[http://wenyan-lang.lingdong.works](http://wenyan-lang.lingdong.works)
9+
### [https://wy-lang.org](https://wy-lang.org)
910

1011
English | [简体中文](./README.zh-Hans.md) | [繁体中文](./README.zh-Hant.md)
1112

12-
文言文編程語言。A programming language for the ancient Chinese. [Try it online.](http://wenyan-lang.lingdong.works/ide.html)
13+
文言文編程語言。A programming language for the ancient Chinese. [Try it online.](https://wy-lang.org/ide)
1314

1415
![](screenshots/screenshot01.png)
1516

@@ -59,7 +60,7 @@ More sophisticated examples, such as the Sieve of Eratosthenes, Quicksort, Mande
5960
- [Natural Language Programming](https://en.wikipedia.org/wiki/Natural-language_programming) sharing the grammar of [Classical Chinese](https://en.wikipedia.org/wiki/Classical_Chinese)
6061
- Compiles to [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript), [Python](https://python.org), or [Ruby](http://ruby-lang.org)
6162
- [Turing complete](https://github.com/LingDong-/wenyan-lang/blob/master/examples/turing.wy)
62-
- An [online IDE](http://wenyan-lang.lingdong.works/ide.html)
63+
- An [online IDE](https://wy-lang.org/ide)
6364
- [Examples](https://github.com/LingDong-/wenyan-lang/tree/master/examples) to get started
6465

6566

@@ -83,7 +84,7 @@ wenyan examples/helloworld.wy
8384
> From v0.1.0, the `wenyan` command will direct execute the script by default. If you are migrating from previous versions, please use `wenyan -h` to output the help and check [this PR](https://github.com/LingDong-/wenyan-lang/pull/356) for the detailed changes.
8485
8586

86-
### [The Online IDE](http://wenyan-lang.lingdong.works/ide.html)
87+
### [The Online IDE](https://wy-lang.org/ide)
8788

8889
![](screenshots/screenshot02.png)
8990

@@ -114,7 +115,7 @@ Please refer to [Browser Runtime](./documentation/Runtime.md)
114115

115116
## Syntax Cheatsheet
116117

117-
A context-free grammar description is under construction. Meanwhile, please check the cheatsheet below, or look into `src/parser.js` to learn about the syntax. Be sure to check out the examples from the online IDE too!
118+
You can find the Language Specification [here](https://wy-lang.org/spec) (WIP). To get started, you can also check the cheatsheet below, or look into `src/parser.js` to learn more. Be sure to check out the examples from the online IDE too!
118119

119120
### Variables
120121

documentation/wenyan.g4

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
grammar wenyan;
2+
program : statement* ;
3+
statement : declare_statement
4+
| define_statement
5+
| print_statement
6+
| for_statement
7+
| function_statement
8+
| if_statement
9+
| return_statement
10+
| math_statement
11+
| assign_statement
12+
| import_statement
13+
| object_statement
14+
| reference_statement
15+
| array_statement
16+
| flush_statement
17+
| BREAK
18+
| comment;
19+
20+
reference_statement : '' data ('' (STRING_LITERAL|INT_NUM|'其餘'|IDENTIFIER|''))? name_single_statement? ;
21+
22+
23+
array_statement : array_cat_statement|array_push_statement ;
24+
array_cat_statement : '' (IDENTIFIER|'') (PREPOSITION_RIGHT IDENTIFIER)+ name_single_statement?;
25+
array_push_statement : '' (IDENTIFIER|'') (PREPOSITION_RIGHT data)+ name_single_statement?;
26+
27+
28+
function_statement : function_define_statement|(function_call_statement (name_single_statement)?) ;
29+
function_call_statement : function_pre_call|function_post_call ;
30+
function_pre_call : ('' IDENTIFIER (preposition data)*)|('施其' (preposition data)*) ;
31+
function_post_call : ('' INT_NUM '以施' IDENTIFIER)+ ;
32+
function_define_statement : '吾有' INT_NUM '' name_single_statement ('欲行是術' '必先得' (INT_NUM TYPE ('' IDENTIFIER)+)+)? ('是術曰'|'乃行是術曰') statement* '是謂' IDENTIFIER '之術也' ;
33+
34+
35+
if_statement : IF if_expression '' statement+ (ELSE statement+)? FOR_IF_END ;
36+
if_expression : unary_if_expression|binary_if_expression ;
37+
unary_if_expression : data|(IDENTIFIER ''(''|STRING_LITERAL|IDENTIFIER))|'' ;
38+
binary_if_expression : unary_if_expression IF_LOGIC_OP unary_if_expression ;
39+
40+
41+
declare_statement : ('吾有'|'今有') INT_NUM TYPE ('' data)*;
42+
define_statement : (declare_statement name_multi_statement)|init_define_statement ;
43+
44+
45+
name_multi_statement : '名之' ('' IDENTIFIER)+ ;
46+
name_single_statement : '名之' ('' IDENTIFIER) ;
47+
init_define_statement : '' TYPE data (name_single_statement)? ;
48+
49+
50+
for_statement : for_arr_statement
51+
| for_enum_statement
52+
| for_while_statement ;
53+
for_arr_statement : FOR_START_ARR IDENTIFIER FOR_MID_ARR IDENTIFIER statement* FOR_IF_END ;
54+
for_enum_statement : FOR_START_ENUM (INT_NUM|IDENTIFIER) FOR_MID_ENUM statement* FOR_IF_END ;
55+
for_while_statement : FOR_START_WHILE statement* FOR_IF_END ;
56+
57+
58+
math_statement : (arith_math_statement|boolean_algebra_statement|mod_math_statement) (name_multi_statement)? ;
59+
arith_math_statement : arith_binary_math|arith_unary_math ;
60+
arith_binary_math : ARITH_BINARY_OP (data|'') preposition (data|'') ;
61+
arith_unary_math : UNARY_OP (IDENTIFIER|'') ;
62+
mod_math_statement : '' (INT_NUM|FLOAT_NUM|IDENTIFIER|'') preposition (INT_NUM|FLOAT_NUM|IDENTIFIER) POST_MOD_MATH_OP? ;
63+
boolean_algebra_statement : '' IDENTIFIER IDENTIFIER LOGIC_BINARY_OP ;
64+
65+
66+
assign_statement : '昔之' IDENTIFIER ('' (INT_NUM|STRING_LITERAL|IDENTIFIER))? '' (('' ((data ('' INT_NUM)?)|'') '是矣')|'今不復存矣') ;
67+
68+
69+
return_statement : '乃得' (data|'')|'乃歸空無'|'乃得矣' ;
70+
71+
72+
import_statement : '吾嘗觀' STRING_LITERAL '之書' ('方悟' IDENTIFIER+ '之義')? ;
73+
74+
75+
object_statement : '吾有' INT_NUM '' name_multi_statement (object_define_statement)? ;
76+
object_define_statement : '其物如是' ('物之' STRING_LITERAL '' TYPE '' data)+ '是謂' IDENTIFIER '之物也' ;
77+
78+
79+
data : STRING_LITERAL|BOOL_VALUE|IDENTIFIER|INT_NUM|FLOAT_NUM ;
80+
81+
STRING_LITERAL : '「「' ( ~('') )* '」」' ;
82+
IDENTIFIER : '' ( ~('') )+ '' ;
83+
84+
ARITH_BINARY_OP : ''|''|'' ;
85+
LOGIC_BINARY_OP : '中有陽乎'|'中無陰乎' ;
86+
POST_MOD_MATH_OP : '所餘幾何' ;
87+
UNARY_OP : '' ;
88+
89+
preposition : PREPOSITION_LEFT|PREPOSITION_RIGHT ;
90+
PREPOSITION_LEFT : '' ;
91+
PREPOSITION_RIGHT : '' ;
92+
93+
IF : '' ;
94+
ELSE : '若非' ;
95+
IF_LOGIC_OP : '等於'|'不等於'|'不大於'|'不小於'|'大於'|'小於' ;
96+
97+
FOR_START_ARR : '' ;
98+
FOR_START_ENUM : '為是' ;
99+
FOR_START_WHILE : '恆為是' ;
100+
FOR_MID_ARR : '中之' ;
101+
FOR_MID_ENUM : '' ;
102+
FOR_IF_END : '云云'|'' ;
103+
104+
FLOAT_NUM : INT_NUM '' (INT_NUM FLOAT_NUM_KEYWORDS)+ ;
105+
FLOAT_NUM_KEYWORDS : ''|''|''|''|''|''|''|''|''|'' ;
106+
INT_NUM : INT_NUM_KEYWORDS+ ;
107+
108+
INT_NUM_KEYWORDS : ''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|'' ;
109+
TYPE : ''|''|''|'' ;
110+
BOOL_VALUE : ''|'' ;
111+
print_statement : '書之' ;
112+
113+
WS : ([ \t\r\n]|''|'')+ -> skip ;
114+
comment : ('注曰'|'疏曰'|'批曰') STRING_LITERAL ;
115+
flush_statement : '' ;
116+
117+
BREAK : '乃止' ;

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
| [tree2.wy](tree2.wy) | 畫樹二 |
4040
| [try.wy](try.wy) | 異常處理示例 |
4141
| [turing.wy](turing.wy) | 圖靈機 |
42+
| [pascal_triangle.wy](pascal_triangle.wy) | 賈憲三角 |
4243

4344
[1]: https://en.wikipedia.org/wiki/Fizz_buzz
4445
[2]: https://zh.wikipedia.org/wiki/自產生程式

examples/pascal_triangle.wy

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
吾有一術。名之曰「賈憲三角」。欲行是術。必先得一數。曰「層數」。乃行是術曰。
2+
吾有一列。名之曰「前層之得」。
3+
充「前層之得」以一。夫「前層之得」。書之。
4+
若「層數」等於一者乃歸空無也。
5+
6+
充「前層之得」以一。夫「前層之得」。書之。
7+
若「層數」等於二者乃歸空無也。
8+
9+
有數三。名之曰「計甲」。
10+
恆為是。若「計甲」大於「層數」者乃止也。
11+
吾有一列。名之曰「此層之得」。
12+
充「此層之得」以一。
13+
有數一。名之曰「計乙」。
14+
夫「前層之得」之長。名之曰「層長」。
15+
恆為是。若「計乙」不小於「層長」者乃止也
16+
加一以「計乙」。名之曰「計乙又一」
17+
夫「前層之得」之「計乙」。名之曰「數甲」。
18+
夫「前層之得」之「計乙又一」。名之曰「數乙」。
19+
加「數甲」以「數乙」。名之曰「新數」。
20+
充「此層之得」以「新數」。
21+
加「計乙」以一。昔之「計乙」者。今其是矣。
22+
云云。
23+
充「此層之得」以一。夫「此層之得」。書之。
24+
昔之「前層之得」者。今「此層之得」是矣。
25+
加「計甲」以一。昔之「計甲」者。今其是矣。
26+
云云
27+
是謂「賈憲三角」之術也。
28+
29+
施「賈憲三角」於九。

0 commit comments

Comments
 (0)