Skip to content

Commit

Permalink
Merge branch 'release' of https://github.com/LingDong-/wenyan-lang in…
Browse files Browse the repository at this point in the history
…to release
  • Loading branch information
antfu committed Jan 2, 2020
2 parents e3463e5 + 43a1e56 commit e3f7a86
Show file tree
Hide file tree
Showing 30 changed files with 1,955 additions and 966 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Lingdong Huang
Copyright (c) 2019-present Lingdong Huang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

# 文言 wenyan-lang

[![npm](https://img.shields.io/npm/v/@wenyanlang/core)](https://www.npmjs.com/package/@wenyanlang/core)
[![build](https://img.shields.io/github/workflow/status/LingDong-/wenyan-lang/Build%20%26%20Test)](https://github.com/LingDong-/wenyan-lang/actions)

[http://wenyan-lang.lingdong.works](http://wenyan-lang.lingdong.works)

English | [简体中文](./README.zh-Hans.md) | [繁体中文](./README.zh-Hant.md)
Expand Down
35 changes: 30 additions & 5 deletions documentation/Compiler-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { compile } from '@wenyanlang/core'

### Browsers

You can add following lind to the head of your html body.
You can add the following line to the head of your html body.

```html
<script src='https://unpkg.com/@wenyanlang/core/index.min.js'></script>
Expand All @@ -44,28 +44,53 @@ const compiled = Wenyan.compile('吾有一言。曰「「問天地好在。」

- core
- [compile](#compile)
- [execute](#execute)

### Execute

[Source](../src/parser.js)

```ts
function execute(source: string, options?: ExecuteOptions)
```

**Parameters**

| Name | Type | Note |
| --- | --- | --- |
| source | string | The Wenyan source code |
| options | object | [Execute Options](#Execute-Options) |

### Compile

[Source](../src/parser.js)

```ts
function compile(targetLang: string, source: string, options?: CompilerOptions)
function compile(source: string, options?: CompilerOptions)
```

**Parameters**

| Name | Type | Note |
| --- | --- | --- |
| targetLang | string | Can be `js`, `py` or `rb` |
| source | string | The Wenyan source code |
| options | object | [Compiler Options](#Compiler-Options) |

### Compiler Options
#### Compiler Options

| Fields | Default Value | Note |
| --- | --- | --- |
| lang | `js` | Target language, can be `js`, `py` or `rb` |
| romanizeIdentifiers | none | Romanize variable identifiers (e.g. `` to `JIA2`) |
| resetVarCnt | false | Reset temporary variable counter |
| logCallback | console.log | Get verbose debug log |
| errorLog | process.exit | Error log |
| errorLog | process.exit | Error log |

#### Execute Options

Execute Options extends all field in [Compiler Options](#Compiler-Options)

| Fields | Default Value | Note |
| --- | --- | --- |
| outputHanzi | true | Convert numbers and bools to Hanzi |
| output | `console.log` | You can redirect the output if you don't want to use `console.log` |
12 changes: 11 additions & 1 deletion documentation/Runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

You can now run Wenyan as normal Javscript script right in your html.

[**Check out the demo**](https://jsfiddle.net/antfu/u532ny49/2/)
[**Check out the demo**](https://jsfiddle.net/antfu/u532ny49/)

## Installation

Expand Down Expand Up @@ -47,6 +47,16 @@ You can import remote scripts as you will do for Javascript.
<script type="application/wenyan" src="https://raw.githubusercontent.com/LingDong-/wenyan-lang/master/examples/fizzbuzz.wy"></script>
```

### Outputing Hanzi

By default, it will convert numbers and bools to hanzi. If you want to output raw numbers, you can specify `ouputHanzi="false"` in attr of script tag.

```html
<script type="application/wenyan" ouputHanzi="false">
吾有一數。曰三。書之。
</script>
```

### DOM Hacks

There are some hacks you can do to access the DOM and browser APIs. This allows wenyan to do some realworld applications.
Expand Down
8 changes: 1 addition & 7 deletions documentation/Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@

This project uses [Mocha](https://mochajs.org/) and [Chai](https://www.chaijs.com/) for unit testing and snapshot testing.

You will need to build first

```bash
npm run build
```

Then you can run all the tests by
You can run all the tests by

```bash
npm test
Expand Down
110 changes: 41 additions & 69 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,44 @@

<!-- Auto generated. DO NOT edit this file manually. -->
# Examples(範例)

| File(文檔) | Remark(說明) |
| -------------------------- | ----------------------- |
| [beer.wy][3] | while |
| [collatz.wy][4] | 角谷猜想 |
| [collatz2.wy][5] | 考拉兹猜想(角谷猜想) |
| [divination.wy][6] | 春秋古筮法 |
| [eightqueens.wy][7] | 八皇后問題 |
| [euclidean.wy][8] | 歐幾里得法 |
| [factorial.wy][9] | 階乘 |
| [fibonacci.wy][10] | 斐波那契 |
| [fibonacci2.wy][11] | 斐氏列 |
| [fizzbuzz.wy][12] | [Fizz buzz][1] |
| [hanoi.wy][13] | 漢諾塔 |
| [helloworld.wy][14] | 問天地好在 |
| [helloworld+.wy][15] | 問天地好在+ |
| [import.wy][16] | 導入 |
| [mandelbrot.wy][17] | 曼德博集 |
| [mergesort.wy][18] | 歸併排序 |
| [misc.wy][19] | 雜項 |
| [modinv.wy][20] | 大衍求一術 |
| [multiplication_table.wy][21] | 乘算口訣 |
| [nested_fun.wy][22] | 函数 |
| [obj.wy][23] | 对象 |
| [pi_leibniz.wy][24] | 萊布尼茲圓周率估算 |
| [pi_liuhui.wy][25] | 劉徽割圓術求圓周率 |
| [quicksort.wy][26] | 快速排序 |
| [quicksort_inplace.wy][27] | 快速排序2 |
| [quine.wy][28] | [自產生程式][2] |
| [quine2.wy][29] | 自產生程式2 |
| [selectionsort.wy][30] | 選擇排序 |
| [sieve.wy][31] | 埃氏篩 |
| [sqrt_newton.wy][32] | 牛頓求根法 |
| [turing.wy][33] | 圖靈機 |
| [draw_heart.wy][34] | 畫心 |
| File(文檔) | Remark(說明) |
| -------------------------------------- | ------------------------- |
| [beer.wy](beer.wy) | 九十九瓶啤酒 |
| [collatz.wy](collatz.wy) | 考拉兹猜想 |
| [collatz2.wy](collatz2.wy) | 考拉兹猜想二 |
| [divination.wy](divination.wy) | 春秋古筮法 |
| [draw_heart.wy](draw_heart.wy) | 畫心 |
| [eightqueens.wy](eightqueens.wy) | 八皇后問題 |
| [euclidean.wy](euclidean.wy) | 歐幾里得法 |
| [factorial.wy](factorial.wy) | 階乘 |
| [fibonacci.wy](fibonacci.wy) | 斐氏列 |
| [fibonacci2.wy](fibonacci2.wy) | 斐氏列二 |
| [fizzbuzz.wy](fizzbuzz.wy) | [嘶嘶嗡嗡][1] |
| [hanoi.wy](hanoi.wy) | 漢諾塔 |
| [helloworld.wy](helloworld.wy) | 問天地好在 |
| [helloworld+.wy](helloworld+.wy) | 問天地好在+ |
| [import.wy](import.wy) | 導入示例 |
| [macro.wy](macro.wy) | 宏示例 |
| [mandelbrot.wy](mandelbrot.wy) | 曼德博集 |
| [mergesort.wy](mergesort.wy) | 歸併排序 |
| [misc.wy](misc.wy) | 雜項 |
| [modinv.wy](modinv.wy) | 大衍求一術 |
| [multiplication_table.wy](multiplication_table.wy) | 乘算口訣 |
| [nested_fun.wy](nested_fun.wy) | 嵌套調用示例 |
| [obj.wy](obj.wy) | 对象示例 |
| [pi_leibniz.wy](pi_leibniz.wy) | 萊布尼茲圓周率估算 |
| [pi_liuhui.wy](pi_liuhui.wy) | 劉徽割圓術求圓周率 |
| [quicksort.wy](quicksort.wy) | 快速排序 |
| [quicksort_inplace.wy](quicksort_inplace.wy) | 快速排序二 |
| [quine.wy](quine.wy) | [自產生程式][2] |
| [quine2.wy](quine2.wy) | 自產生程式二 |
| [selectionsort.wy](selectionsort.wy) | 選擇排序 |
| [sieve.wy](sieve.wy) | 埃氏篩 |
| [sqrt_newton.wy](sqrt_newton.wy) | 牛頓求根法 |
| [tree.wy](tree.wy) | 畫樹 |
| [tree2.wy](tree2.wy) | 畫樹二 |
| [try.wy](try.wy) | 異常處理示例 |
| [turing.wy](turing.wy) | 圖靈機 |

[1]: https://en.wikipedia.org/wiki/Fizz_buzz "Fizz buzz"
[2]: https://zh.wikipedia.org/wiki/自產生程式 "自產生程式"
[3]: beer.wy
[4]: collatz.wy
[5]: collatz2.wy
[6]: divination.wy
[7]: eightqueens.wy
[8]: euclidean.wy
[9]: factorial.wy
[10]: fibonacci.wy
[11]: fibonacci2.wy
[12]: fizzbuzz.wy
[13]: hanoi.wy
[14]: helloworld.wy
[15]: helloworld+.wy
[16]: import.wy
[17]: mandelbrot.wy
[18]: mergesort.wy
[19]: misc.wy
[20]: modinv.wy
[21]: multiplication_table.wy
[22]: nested_fun.wy
[23]: obj.wy
[24]: pi_leobniz.wy
[25]: pi_liuhui.wy
[26]: quicksort.wy
[27]: quicksort_inplace.wy
[28]: quine.wy
[29]: quine2.wy
[30]: selectionsort.wy
[31]: sieve.wy
[32]: sqrt_newton.wy
[33]: turing.wy
[34]: draw_heart.wy
[1]: https://en.wikipedia.org/wiki/Fizz_buzz
[2]: https://zh.wikipedia.org/wiki/自產生程式
12 changes: 6 additions & 6 deletions examples/draw_heart.wy
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
欲行是術。必先得一言。曰「心語」。
乃行是術曰。
夫「心語」之長。名之曰「長度」。
吾有一言。曰「「``」」。名之曰「填充符」。
吾有一言。曰「「」」。名之曰「填充符」。
吾有一言。曰「「\n」」。名之曰「换行符」。
除十三以十。名之曰「乙」。
除負十一以十。名之曰「乙止」。
Expand All @@ -25,18 +25,18 @@
乘「甲」以「甲」。加其以「加數」。減其以一。名之曰「函數值」。
若「函數值」不大於零者。
夫「心語」之「輸出位置」。名之曰「字」。
「本行」以「字」。昔之「本行」者今其是矣。
「本行」以「字」。昔之「本行」者今其是矣。
除「輸出位置」以「長度」。所餘幾何。加其以一。昔之「輸出位置」者今其是矣。
若非。
「本行」以「填充符」。昔之「本行」者今其是矣。
「本行」以「填充符」。昔之「本行」者今其是矣。
终也。
加「甲」以「甲步長」。昔之「甲」者今其是矣。
云云。
減「乙」以「乙步長」。昔之「乙」者今其是矣。
「本行」以「换行符」。昔之「本行」者今其是矣。
「果」以「本行」。昔之「果」者今其是矣。
「本行」以「换行符」。昔之「本行」者今其是矣。
「果」以「本行」。昔之「果」者今其是矣。
云云。
吾有一言。曰「果」。書之。
是謂「畫心」之術也。

施「畫心」於「「琉璃梳子撫青絲,畫心牽腸癡不癡。」」。
施「畫心」於「「琉璃梳子撫青絲畫心牽腸癡不癡。」」。
2 changes: 1 addition & 1 deletion examples/obj.wy
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
物之「「丁」」者。數曰四。
是謂「乙」之物也。
乃得「乙」。
是謂「造物之術」之物也
是謂「造物之術」之術也

施「造物之術」於「「某甲」」。名之曰「戊」。
昔之「戊」之「「丁」」者。今五是矣。
Expand Down
2 changes: 1 addition & 1 deletion examples/quine.wy
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
注曰Reference: 注曰https://qiita.com/amoO_O/items/5d0c4edfc99f64bea6fb
吾有一術。名之曰「自己複製」。欲行是術。必先得零數。是術曰。吾有一術。名之曰「置換」。欲行是術。必先得三數。曰「文字列」。曰「置換対象」。曰「置換先」是術曰。吾有一言。曰「「」」。名之曰「返品」。吾有一數。曰二。名之曰「未来」。吾有一爻。曰陽。名之曰「実行条件」。凡「文字列」中之「文字」。若「実行条件」者。若「文字」等於「「星」」中無陰乎「文字列」之「未来」等於「置換対象」者。昔之「文字」者。今「置換先」是。昔之「実行条件」者。今陰是。也。加「返品」以「文字」。昔之「返品」者。今其是矣。若非。昔之「実行条件」者。今陽是。也。加「未来」以一。昔之「未来」者。今其是矣。云云。乃得「返品」。是謂「置換」之術也。吾有一言。曰String.fromCharCode名之曰「函数」。施「函数」於一萬二千三百。昔之「始」者。今其是矣。施「函数」於一萬二千三百零一。昔之「終」者。今其是矣。吾有二言。曰「「吾有一術。名之曰星甲自己複製星乙。欲行是術。必先得零數。是術曰。吾有一術。名之曰星甲置換星乙。欲行是術。必先得三數。曰星甲文字列星乙。曰星甲置換対象星乙。曰星甲置換先星乙是術曰。吾有一言。曰星甲星甲星乙星乙。名之曰星甲返品星乙。吾有一數。曰二。名之曰星甲未来星乙。吾有一爻。曰陽。名之曰星甲実行条件星乙。凡星甲文字列星乙中之星甲文字星乙。若星甲実行条件星乙者。若星甲文字星乙等於星甲星甲星星乙星乙中無陰乎星甲文字列星乙之星甲未来星乙等於星甲置換対象星乙者。昔之星甲文字星乙者。今星甲置換先星乙是。昔之星甲実行条件星乙者。今陰是。也。加星甲返品星乙以星甲文字星乙。昔之星甲返品星乙者。今其是矣。若非。昔之星甲実行条件星乙者。今陽是。也。加星甲未来星乙以一。昔之星甲未来星乙者。今其是矣。云云。乃得星甲返品星乙。是謂星甲置換星乙之術也。吾有一言。曰String.fromCharCode名之曰星甲函数星乙。施星甲函数星乙於一萬二千三百。昔之星甲始星乙者。今其是矣。施星甲函数星乙於一萬二千三百零一。昔之星甲終星乙者。今其是矣。吾有二言。曰星甲星甲星丙星乙星乙。曰星甲星甲星乙星乙。名之曰星甲原文星乙曰星甲結果星乙。施星甲置換星乙於星甲原文星乙。於星甲星甲甲星乙星乙。於星甲始星乙。昔之星甲結果星乙者。今其是矣。施星甲置換星乙於星甲結果星乙。於星甲星甲乙星乙星乙。於星甲終星乙。昔之星甲結果星乙者。今其是矣。施星甲置換星乙於星甲結果星乙。於星甲星甲丙星乙星乙。於星甲原文星乙。昔之星甲結果星乙者。今其是矣。吾有一言。曰星甲結果星乙。書之。是謂星甲自己複製星乙之術也。施星甲自己複製星乙。」」。曰「「」」。名之曰「原文」曰「結果」。施「置換」於「原文」。於「「甲」」。於「始」。昔之「結果」者。今其是矣。施「置換」於「結果」。於「「乙」」。於「終」。昔之「結果」者。今其是矣。施「置換」於「結果」。於「「丙」」。於「原文」。昔之「結果」者。今其是矣。吾有一言。曰「結果」。書之。是謂「自己複製」之術也。施「自己複製」。
吾有一術。名之曰「自己複製」。欲行是術。是術曰。吾有一術。名之曰「置換」。欲行是術。必先得三數。曰「文字列」。曰「置換対象」。曰「置換先」是術曰。吾有一言。曰「「」」。名之曰「返品」。吾有一數。曰二。名之曰「未来」。吾有一爻。曰陽。名之曰「実行条件」。凡「文字列」中之「文字」。若「実行条件」者。若「文字」等於「「星」」中無陰乎「文字列」之「未来」等於「置換対象」者。昔之「文字」者。今「置換先」是。昔之「実行条件」者。今陰是。也。加「返品」以「文字」。昔之「返品」者。今其是矣。若非。昔之「実行条件」者。今陽是。也。加「未来」以一。昔之「未来」者。今其是矣。云云。乃得「返品」。是謂「置換」之術也。吾有一言。曰String.fromCharCode名之曰「函数」。施「函数」於一萬二千三百。昔之「始」者。今其是矣。施「函数」於一萬二千三百零一。昔之「終」者。今其是矣。吾有二言。曰「「吾有一術。名之曰星甲自己複製星乙。欲行是術。是術曰。吾有一術。名之曰星甲置換星乙。欲行是術。必先得三數。曰星甲文字列星乙。曰星甲置換対象星乙。曰星甲置換先星乙是術曰。吾有一言。曰星甲星甲星乙星乙。名之曰星甲返品星乙。吾有一數。曰二。名之曰星甲未来星乙。吾有一爻。曰陽。名之曰星甲実行条件星乙。凡星甲文字列星乙中之星甲文字星乙。若星甲実行条件星乙者。若星甲文字星乙等於星甲星甲星星乙星乙中無陰乎星甲文字列星乙之星甲未来星乙等於星甲置換対象星乙者。昔之星甲文字星乙者。今星甲置換先星乙是。昔之星甲実行条件星乙者。今陰是。也。加星甲返品星乙以星甲文字星乙。昔之星甲返品星乙者。今其是矣。若非。昔之星甲実行条件星乙者。今陽是。也。加星甲未来星乙以一。昔之星甲未来星乙者。今其是矣。云云。乃得星甲返品星乙。是謂星甲置換星乙之術也。吾有一言。曰String.fromCharCode名之曰星甲函数星乙。施星甲函数星乙於一萬二千三百。昔之星甲始星乙者。今其是矣。施星甲函数星乙於一萬二千三百零一。昔之星甲終星乙者。今其是矣。吾有二言。曰星甲星甲星丙星乙星乙。曰星甲星甲星乙星乙。名之曰星甲原文星乙曰星甲結果星乙。施星甲置換星乙於星甲原文星乙。於星甲星甲甲星乙星乙。於星甲始星乙。昔之星甲結果星乙者。今其是矣。施星甲置換星乙於星甲結果星乙。於星甲星甲乙星乙星乙。於星甲終星乙。昔之星甲結果星乙者。今其是矣。施星甲置換星乙於星甲結果星乙。於星甲星甲丙星乙星乙。於星甲原文星乙。昔之星甲結果星乙者。今其是矣。吾有一言。曰星甲結果星乙。書之。是謂星甲自己複製星乙之術也。施星甲自己複製星乙。」」。曰「「」」。名之曰「原文」曰「結果」。施「置換」於「原文」。於「「甲」」。於「始」。昔之「結果」者。今其是矣。施「置換」於「結果」。於「「乙」」。於「終」。昔之「結果」者。今其是矣。施「置換」於「結果」。於「「丙」」。於「原文」。昔之「結果」者。今其是矣。吾有一言。曰「結果」。書之。是謂「自己複製」之術也。施「自己複製」。

0 comments on commit e3f7a86

Please sign in to comment.