From 5d3b07801456d16dcc2c75dcccd48d508a6b60cc Mon Sep 17 00:00:00 2001 From: Li Jin Date: Mon, 19 Apr 2021 23:41:33 +0800 Subject: first commit for Yuescript document site. --- doc/.gitignore | 13 + doc/README.md | 13 + doc/docs/.vuepress/components/CompilerModal.vue | 32 ++ doc/docs/.vuepress/components/YueCompiler.vue | 383 +++++++++++++ doc/docs/.vuepress/components/YueDisplay.vue | 49 ++ doc/docs/.vuepress/config.js | 77 +++ doc/docs/.vuepress/enhanceApp.js | 14 + doc/docs/.vuepress/public/image/yuescript.svg | 53 ++ doc/docs/.vuepress/styles/index.styl | 9 + doc/docs/.vuepress/styles/palette.styl | 12 + doc/docs/.vuepress/theme/LICENSE | 21 + doc/docs/.vuepress/theme/README.md | 11 + .../theme/components/AlgoliaSearchBox.vue | 172 ++++++ .../.vuepress/theme/components/DropdownLink.vue | 252 +++++++++ .../theme/components/DropdownTransition.vue | 33 ++ doc/docs/.vuepress/theme/components/Home.vue | 175 ++++++ doc/docs/.vuepress/theme/components/NavLink.vue | 90 ++++ doc/docs/.vuepress/theme/components/NavLinks.vue | 156 ++++++ doc/docs/.vuepress/theme/components/Navbar.vue | 140 +++++ doc/docs/.vuepress/theme/components/Page.vue | 31 ++ doc/docs/.vuepress/theme/components/PageEdit.vue | 155 ++++++ doc/docs/.vuepress/theme/components/PageNav.vue | 163 ++++++ doc/docs/.vuepress/theme/components/Sidebar.vue | 64 +++ .../.vuepress/theme/components/SidebarButton.vue | 40 ++ .../.vuepress/theme/components/SidebarGroup.vue | 141 +++++ .../.vuepress/theme/components/SidebarLink.vue | 133 +++++ .../.vuepress/theme/components/SidebarLinks.vue | 106 ++++ .../.vuepress/theme/global-components/Badge.vue | 44 ++ .../theme/global-components/CodeBlock.vue | 41 ++ .../theme/global-components/CodeGroup.vue | 120 +++++ doc/docs/.vuepress/theme/index.js | 59 ++ doc/docs/.vuepress/theme/layouts/404.vue | 30 ++ doc/docs/.vuepress/theme/layouts/Layout.vue | 151 ++++++ doc/docs/.vuepress/theme/noopModule.js | 1 + doc/docs/.vuepress/theme/package.json | 44 ++ doc/docs/.vuepress/theme/styles/arrow.styl | 22 + doc/docs/.vuepress/theme/styles/code.styl | 176 ++++++ doc/docs/.vuepress/theme/styles/config.styl | 1 + doc/docs/.vuepress/theme/styles/custom-blocks.styl | 44 ++ doc/docs/.vuepress/theme/styles/index.styl | 202 +++++++ doc/docs/.vuepress/theme/styles/mobile.styl | 37 ++ doc/docs/.vuepress/theme/styles/toc.styl | 3 + doc/docs/.vuepress/theme/styles/wrapper.styl | 9 + doc/docs/.vuepress/theme/util/index.js | 244 +++++++++ doc/docs/README.md | 8 + doc/docs/doc/README.md | 594 +++++++++++++++++++++ doc/docs/try/README.md | 6 + doc/package.json | 25 + 48 files changed, 4399 insertions(+) create mode 100755 doc/.gitignore create mode 100755 doc/README.md create mode 100755 doc/docs/.vuepress/components/CompilerModal.vue create mode 100755 doc/docs/.vuepress/components/YueCompiler.vue create mode 100755 doc/docs/.vuepress/components/YueDisplay.vue create mode 100755 doc/docs/.vuepress/config.js create mode 100755 doc/docs/.vuepress/enhanceApp.js create mode 100644 doc/docs/.vuepress/public/image/yuescript.svg create mode 100755 doc/docs/.vuepress/styles/index.styl create mode 100755 doc/docs/.vuepress/styles/palette.styl create mode 100644 doc/docs/.vuepress/theme/LICENSE create mode 100644 doc/docs/.vuepress/theme/README.md create mode 100644 doc/docs/.vuepress/theme/components/AlgoliaSearchBox.vue create mode 100644 doc/docs/.vuepress/theme/components/DropdownLink.vue create mode 100644 doc/docs/.vuepress/theme/components/DropdownTransition.vue create mode 100644 doc/docs/.vuepress/theme/components/Home.vue create mode 100644 doc/docs/.vuepress/theme/components/NavLink.vue create mode 100644 doc/docs/.vuepress/theme/components/NavLinks.vue create mode 100644 doc/docs/.vuepress/theme/components/Navbar.vue create mode 100644 doc/docs/.vuepress/theme/components/Page.vue create mode 100644 doc/docs/.vuepress/theme/components/PageEdit.vue create mode 100644 doc/docs/.vuepress/theme/components/PageNav.vue create mode 100644 doc/docs/.vuepress/theme/components/Sidebar.vue create mode 100644 doc/docs/.vuepress/theme/components/SidebarButton.vue create mode 100644 doc/docs/.vuepress/theme/components/SidebarGroup.vue create mode 100644 doc/docs/.vuepress/theme/components/SidebarLink.vue create mode 100644 doc/docs/.vuepress/theme/components/SidebarLinks.vue create mode 100644 doc/docs/.vuepress/theme/global-components/Badge.vue create mode 100644 doc/docs/.vuepress/theme/global-components/CodeBlock.vue create mode 100644 doc/docs/.vuepress/theme/global-components/CodeGroup.vue create mode 100644 doc/docs/.vuepress/theme/index.js create mode 100644 doc/docs/.vuepress/theme/layouts/404.vue create mode 100644 doc/docs/.vuepress/theme/layouts/Layout.vue create mode 100644 doc/docs/.vuepress/theme/noopModule.js create mode 100644 doc/docs/.vuepress/theme/package.json create mode 100644 doc/docs/.vuepress/theme/styles/arrow.styl create mode 100644 doc/docs/.vuepress/theme/styles/code.styl create mode 100644 doc/docs/.vuepress/theme/styles/config.styl create mode 100644 doc/docs/.vuepress/theme/styles/custom-blocks.styl create mode 100644 doc/docs/.vuepress/theme/styles/index.styl create mode 100644 doc/docs/.vuepress/theme/styles/mobile.styl create mode 100644 doc/docs/.vuepress/theme/styles/toc.styl create mode 100644 doc/docs/.vuepress/theme/styles/wrapper.styl create mode 100644 doc/docs/.vuepress/theme/util/index.js create mode 100755 doc/docs/README.md create mode 100755 doc/docs/doc/README.md create mode 100755 doc/docs/try/README.md create mode 100755 doc/package.json diff --git a/doc/.gitignore b/doc/.gitignore new file mode 100755 index 0000000..ac4a32c --- /dev/null +++ b/doc/.gitignore @@ -0,0 +1,13 @@ +pids +logs +node_modules +npm-debug.log +coverage/ +run +dist +.DS_Store +.nyc_output +.basement +config.local.js +basement_dist +yarn.lock diff --git a/doc/README.md b/doc/README.md new file mode 100755 index 0000000..8300661 --- /dev/null +++ b/doc/README.md @@ -0,0 +1,13 @@ +# Yuescript + +> Yuescript Documentation + +## Development + +```bash +yarn dev +yarn build +``` + +For more details, please head VuePress's [documentation](https://v1.vuepress.vuejs.org/). + diff --git a/doc/docs/.vuepress/components/CompilerModal.vue b/doc/docs/.vuepress/components/CompilerModal.vue new file mode 100755 index 0000000..65ae9b0 --- /dev/null +++ b/doc/docs/.vuepress/components/CompilerModal.vue @@ -0,0 +1,32 @@ + + + + diff --git a/doc/docs/.vuepress/components/YueCompiler.vue b/doc/docs/.vuepress/components/YueCompiler.vue new file mode 100755 index 0000000..4d72b92 --- /dev/null +++ b/doc/docs/.vuepress/components/YueCompiler.vue @@ -0,0 +1,383 @@ + + + + + + diff --git a/doc/docs/.vuepress/components/YueDisplay.vue b/doc/docs/.vuepress/components/YueDisplay.vue new file mode 100755 index 0000000..b89805b --- /dev/null +++ b/doc/docs/.vuepress/components/YueDisplay.vue @@ -0,0 +1,49 @@ + + + + + + diff --git a/doc/docs/.vuepress/config.js b/doc/docs/.vuepress/config.js new file mode 100755 index 0000000..fe34c46 --- /dev/null +++ b/doc/docs/.vuepress/config.js @@ -0,0 +1,77 @@ +const { description } = require('../../package') + +module.exports = { + /** + * Ref:https://v1.vuepress.vuejs.org/config/#title + */ + title: 'Yuescript', + /** + * Ref:https://v1.vuepress.vuejs.org/config/#description + */ + description: description, + + /** + * Extra tags to be injected to the page HTML `` + * + * ref:https://v1.vuepress.vuejs.org/config/#head + */ + head: [ + ['meta', { name: 'theme-color', content: '#3eaf7c' }], + ['meta', { name: 'apple-mobile-web-app-capable', content: 'yes' }], + ['meta', { name: 'apple-mobile-web-app-status-bar-style', content: 'black' }], + ['script', {}, `window.global = window;`], + ['script', {}, ` + var Module = { + onRuntimeInitialized: function() { + window.yue = Module; + window.Vue.$data.readonly = false; + window.Vue.$data.info = Module.version(); + } + }; + `], + ['script', {}, ` + var Module = { + onRuntimeInitialized: function() { + window.yue = Module; + } + }; + `], + ['script', { src: '/js/yuescript.js' }], + ], + + /** + * Theme configuration, here is the default theme configuration for VuePress. + * + * ref:https://v1.vuepress.vuejs.org/theme/default-theme-config.html + */ + themeConfig: { + repo: '', + editLinks: false, + docsDir: '', + editLinkText: '', + lastUpdated: false, + nav: [ + { + text: 'Document', + link: '/doc/' + }, + { + text: 'Try yue!', + link: '/try/', + }, + { + text: 'Github', + link: 'https://github.com/pigpigyyy/Yuescript' + } + ], + }, + + /** + * Apply plugins,ref:https://v1.vuepress.vuejs.org/zh/plugin/ + */ + plugins: [ + '@vuepress/plugin-back-to-top', + '@vuepress/plugin-medium-zoom', + '~plugins/vue-js-modal.js', + ] +} diff --git a/doc/docs/.vuepress/enhanceApp.js b/doc/docs/.vuepress/enhanceApp.js new file mode 100755 index 0000000..8452a86 --- /dev/null +++ b/doc/docs/.vuepress/enhanceApp.js @@ -0,0 +1,14 @@ +/** + * Client app enhancement file. + * + * https://v1.vuepress.vuejs.org/guide/basic-config.html#app-level-enhancements + */ + +export default ({ + Vue, // the version of Vue being used in the VuePress app + options, // the options for the root Vue instance + router, // the router instance for the app + siteData // site metadata +}) => { + // ...apply enhancements for the site. +} diff --git a/doc/docs/.vuepress/public/image/yuescript.svg b/doc/docs/.vuepress/public/image/yuescript.svg new file mode 100644 index 0000000..b7e5884 --- /dev/null +++ b/doc/docs/.vuepress/public/image/yuescript.svg @@ -0,0 +1,53 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + diff --git a/doc/docs/.vuepress/styles/index.styl b/doc/docs/.vuepress/styles/index.styl new file mode 100755 index 0000000..69327fd --- /dev/null +++ b/doc/docs/.vuepress/styles/index.styl @@ -0,0 +1,9 @@ +/** + * Custom Styles here. + * + * ref:https://v1.vuepress.vuejs.org/config/#index-styl + */ + +.home .hero img + max-width 450px!important + diff --git a/doc/docs/.vuepress/styles/palette.styl b/doc/docs/.vuepress/styles/palette.styl new file mode 100755 index 0000000..389aa76 --- /dev/null +++ b/doc/docs/.vuepress/styles/palette.styl @@ -0,0 +1,12 @@ +/** + * Custom palette here. + * + * ref:https://v1.vuepress.vuejs.org/zh/config/#palette-styl + */ + +$accentColor = #b7ae8f +$textColor = #2c3e50 +$borderColor = #eaecef +$codeBgColor = #f5f7ff + +$contentWidth = 900px diff --git a/doc/docs/.vuepress/theme/LICENSE b/doc/docs/.vuepress/theme/LICENSE new file mode 100644 index 0000000..15f1f7e --- /dev/null +++ b/doc/docs/.vuepress/theme/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2018-present, Yuxi (Evan) You + +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/doc/docs/.vuepress/theme/README.md b/doc/docs/.vuepress/theme/README.md new file mode 100644 index 0000000..fc49626 --- /dev/null +++ b/doc/docs/.vuepress/theme/README.md @@ -0,0 +1,11 @@ +# @vuepress/theme-default + +> theme-default for VuePress + +## Plugins + +The default theme has the following plugin built in: + +- [@vuepress/plugin-active-header-links](https://github.com/vuejs/vuepress/tree/master/packages/@vuepress/plugin-active-header-links) +- [@vuepress/plugin-google-analytics](https://github.com/vuejs/vuepress/tree/master/packages/%40vuepress/plugin-google-analytics) +- [@vuepress/plugin-search](https://github.com/vuejs/vuepress/tree/master/packages/%40vuepress/plugin-search) diff --git a/doc/docs/.vuepress/theme/components/AlgoliaSearchBox.vue b/doc/docs/.vuepress/theme/components/AlgoliaSearchBox.vue new file mode 100644 index 0000000..7071fb8 --- /dev/null +++ b/doc/docs/.vuepress/theme/components/AlgoliaSearchBox.vue @@ -0,0 +1,172 @@ + + + + + diff --git a/doc/docs/.vuepress/theme/components/DropdownLink.vue b/doc/docs/.vuepress/theme/components/DropdownLink.vue new file mode 100644 index 0000000..be6563f --- /dev/null +++ b/doc/docs/.vuepress/theme/components/DropdownLink.vue @@ -0,0 +1,252 @@ + + + + + diff --git a/doc/docs/.vuepress/theme/components/DropdownTransition.vue b/doc/docs/.vuepress/theme/components/DropdownTransition.vue new file mode 100644 index 0000000..eeaf12b --- /dev/null +++ b/doc/docs/.vuepress/theme/components/DropdownTransition.vue @@ -0,0 +1,33 @@ + + + + + diff --git a/doc/docs/.vuepress/theme/components/Home.vue b/doc/docs/.vuepress/theme/components/Home.vue new file mode 100644 index 0000000..acd8744 --- /dev/null +++ b/doc/docs/.vuepress/theme/components/Home.vue @@ -0,0 +1,175 @@ + + + + + diff --git a/doc/docs/.vuepress/theme/components/NavLink.vue b/doc/docs/.vuepress/theme/components/NavLink.vue new file mode 100644 index 0000000..f7e65a4 --- /dev/null +++ b/doc/docs/.vuepress/theme/components/NavLink.vue @@ -0,0 +1,90 @@ + + + diff --git a/doc/docs/.vuepress/theme/components/NavLinks.vue b/doc/docs/.vuepress/theme/components/NavLinks.vue new file mode 100644 index 0000000..2656ae2 --- /dev/null +++ b/doc/docs/.vuepress/theme/components/NavLinks.vue @@ -0,0 +1,156 @@ + + + + + diff --git a/doc/docs/.vuepress/theme/components/Navbar.vue b/doc/docs/.vuepress/theme/components/Navbar.vue new file mode 100644 index 0000000..f8dd49c --- /dev/null +++ b/doc/docs/.vuepress/theme/components/Navbar.vue @@ -0,0 +1,140 @@ + + + + + diff --git a/doc/docs/.vuepress/theme/components/Page.vue b/doc/docs/.vuepress/theme/components/Page.vue new file mode 100644 index 0000000..04ec7cb --- /dev/null +++ b/doc/docs/.vuepress/theme/components/Page.vue @@ -0,0 +1,31 @@ + + + + + diff --git a/doc/docs/.vuepress/theme/components/PageEdit.vue b/doc/docs/.vuepress/theme/components/PageEdit.vue new file mode 100644 index 0000000..cf9b2d2 --- /dev/null +++ b/doc/docs/.vuepress/theme/components/PageEdit.vue @@ -0,0 +1,155 @@ + + + + + diff --git a/doc/docs/.vuepress/theme/components/PageNav.vue b/doc/docs/.vuepress/theme/components/PageNav.vue new file mode 100644 index 0000000..4c19aae --- /dev/null +++ b/doc/docs/.vuepress/theme/components/PageNav.vue @@ -0,0 +1,163 @@ + + + + + diff --git a/doc/docs/.vuepress/theme/components/Sidebar.vue b/doc/docs/.vuepress/theme/components/Sidebar.vue new file mode 100644 index 0000000..e70e333 --- /dev/null +++ b/doc/docs/.vuepress/theme/components/Sidebar.vue @@ -0,0 +1,64 @@ + + + + + diff --git a/doc/docs/.vuepress/theme/components/SidebarButton.vue b/doc/docs/.vuepress/theme/components/SidebarButton.vue new file mode 100644 index 0000000..3f54afd --- /dev/null +++ b/doc/docs/.vuepress/theme/components/SidebarButton.vue @@ -0,0 +1,40 @@ + + + diff --git a/doc/docs/.vuepress/theme/components/SidebarGroup.vue b/doc/docs/.vuepress/theme/components/SidebarGroup.vue new file mode 100644 index 0000000..d7f1929 --- /dev/null +++ b/doc/docs/.vuepress/theme/components/SidebarGroup.vue @@ -0,0 +1,141 @@ + + + + + diff --git a/doc/docs/.vuepress/theme/components/SidebarLink.vue b/doc/docs/.vuepress/theme/components/SidebarLink.vue new file mode 100644 index 0000000..4cd7665 --- /dev/null +++ b/doc/docs/.vuepress/theme/components/SidebarLink.vue @@ -0,0 +1,133 @@ + + + diff --git a/doc/docs/.vuepress/theme/components/SidebarLinks.vue b/doc/docs/.vuepress/theme/components/SidebarLinks.vue new file mode 100644 index 0000000..55e6288 --- /dev/null +++ b/doc/docs/.vuepress/theme/components/SidebarLinks.vue @@ -0,0 +1,106 @@ + + + diff --git a/doc/docs/.vuepress/theme/global-components/Badge.vue b/doc/docs/.vuepress/theme/global-components/Badge.vue new file mode 100644 index 0000000..53951f9 --- /dev/null +++ b/doc/docs/.vuepress/theme/global-components/Badge.vue @@ -0,0 +1,44 @@ + + + diff --git a/doc/docs/.vuepress/theme/global-components/CodeBlock.vue b/doc/docs/.vuepress/theme/global-components/CodeBlock.vue new file mode 100644 index 0000000..d59d85b --- /dev/null +++ b/doc/docs/.vuepress/theme/global-components/CodeBlock.vue @@ -0,0 +1,41 @@ + + + + + diff --git a/doc/docs/.vuepress/theme/global-components/CodeGroup.vue b/doc/docs/.vuepress/theme/global-components/CodeGroup.vue new file mode 100644 index 0000000..ac6ec55 --- /dev/null +++ b/doc/docs/.vuepress/theme/global-components/CodeGroup.vue @@ -0,0 +1,120 @@ + + + + + diff --git a/doc/docs/.vuepress/theme/index.js b/doc/docs/.vuepress/theme/index.js new file mode 100644 index 0000000..baaf102 --- /dev/null +++ b/doc/docs/.vuepress/theme/index.js @@ -0,0 +1,59 @@ +const path = require('path') + +// Theme API. +module.exports = (options, ctx) => { + const { themeConfig, siteConfig } = ctx + + // resolve algolia + const isAlgoliaSearch = ( + themeConfig.algolia + || Object + .keys(siteConfig.locales && themeConfig.locales || {}) + .some(base => themeConfig.locales[base].algolia) + ) + + const enableSmoothScroll = themeConfig.smoothScroll === true + + return { + alias () { + return { + '@AlgoliaSearchBox': isAlgoliaSearch + ? path.resolve(__dirname, 'components/AlgoliaSearchBox.vue') + : path.resolve(__dirname, 'noopModule.js') + } + }, + + plugins: [ + ['@vuepress/active-header-links', options.activeHeaderLinks], + '@vuepress/search', + '@vuepress/plugin-nprogress', + ['container', { + type: 'tip', + defaultTitle: { + '/': 'TIP', + '/zh/': '提示' + } + }], + ['container', { + type: 'warning', + defaultTitle: { + '/': 'WARNING', + '/zh/': '注意' + } + }], + ['container', { + type: 'danger', + defaultTitle: { + '/': 'WARNING', + '/zh/': '警告' + } + }], + ['container', { + type: 'details', + before: info => `
${info ? `${info}` : ''}\n`, + after: () => '
\n' + }], + ['smooth-scroll', enableSmoothScroll] + ] + } +} diff --git a/doc/docs/.vuepress/theme/layouts/404.vue b/doc/docs/.vuepress/theme/layouts/404.vue new file mode 100644 index 0000000..2cbfa0f --- /dev/null +++ b/doc/docs/.vuepress/theme/layouts/404.vue @@ -0,0 +1,30 @@ + + + diff --git a/doc/docs/.vuepress/theme/layouts/Layout.vue b/doc/docs/.vuepress/theme/layouts/Layout.vue new file mode 100644 index 0000000..3298070 --- /dev/null +++ b/doc/docs/.vuepress/theme/layouts/Layout.vue @@ -0,0 +1,151 @@ + + + diff --git a/doc/docs/.vuepress/theme/noopModule.js b/doc/docs/.vuepress/theme/noopModule.js new file mode 100644 index 0000000..b1c6ea4 --- /dev/null +++ b/doc/docs/.vuepress/theme/noopModule.js @@ -0,0 +1 @@ +export default {} diff --git a/doc/docs/.vuepress/theme/package.json b/doc/docs/.vuepress/theme/package.json new file mode 100644 index 0000000..d5dfc26 --- /dev/null +++ b/doc/docs/.vuepress/theme/package.json @@ -0,0 +1,44 @@ +{ + "name": "@vuepress/theme-default", + "version": "1.8.2", + "description": "Default theme for VuePress", + "keywords": [ + "documentation", + "generator", + "vue", + "vuepress" + ], + "homepage": "https://github.com/vuejs/vuepress/blob/master/packages/@vuepress/theme-default#readme", + "bugs": { + "url": "https://github.com/vuejs/vuepress/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/vuejs/vuepress.git", + "directory": "packages/@vuepress/theme-default" + }, + "license": "MIT", + "author": "Evan You", + "main": "index.js", + "dependencies": { + "@vuepress/plugin-active-header-links": "1.8.2", + "@vuepress/plugin-nprogress": "1.8.2", + "@vuepress/plugin-search": "1.8.2", + "docsearch.js": "^2.5.2", + "lodash": "^4.17.15", + "stylus": "^0.54.8", + "stylus-loader": "^3.0.2", + "vuepress-plugin-container": "^2.0.2", + "vuepress-plugin-smooth-scroll": "^0.0.3" + }, + "publishConfig": { + "access": "public" + }, + "maintainers": [ + { + "name": "ULIVZ", + "email": "chl814@foxmail.com" + } + ], + "gitHead": "11eed0f0f105b97a7324cfa8e59d7d27bb966842" +} diff --git a/doc/docs/.vuepress/theme/styles/arrow.styl b/doc/docs/.vuepress/theme/styles/arrow.styl new file mode 100644 index 0000000..20bffc0 --- /dev/null +++ b/doc/docs/.vuepress/theme/styles/arrow.styl @@ -0,0 +1,22 @@ +@require './config' + +.arrow + display inline-block + width 0 + height 0 + &.up + border-left 4px solid transparent + border-right 4px solid transparent + border-bottom 6px solid $arrowBgColor + &.down + border-left 4px solid transparent + border-right 4px solid transparent + border-top 6px solid $arrowBgColor + &.right + border-top 4px solid transparent + border-bottom 4px solid transparent + border-left 6px solid $arrowBgColor + &.left + border-top 4px solid transparent + border-bottom 4px solid transparent + border-right 6px solid $arrowBgColor diff --git a/doc/docs/.vuepress/theme/styles/code.styl b/doc/docs/.vuepress/theme/styles/code.styl new file mode 100644 index 0000000..0cb4081 --- /dev/null +++ b/doc/docs/.vuepress/theme/styles/code.styl @@ -0,0 +1,176 @@ +/* + +Name: Base16 Atelier Sulphurpool Light +Author: Bram de Haan (http://atelierbram.github.io/syntax-highlighting/atelier-schemes/sulphurpool) + +Prism template by Bram de Haan (http://atelierbram.github.io/syntax-highlighting/prism/) +Original Base16 color scheme by Chris Kempson (https://github.com/chriskempson/base16) + +*/ +code[class*="language-"], +pre[class*="language-"] { + font-family: 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; + font-size: 1em; + line-height: 1.375; + direction: ltr; + text-align: left; + white-space: pre; + word-spacing: normal; + word-break: normal; + -moz-tab-size: 4; + -o-tab-size: 4; + tab-size: 4; + -webkit-hyphens: none; + -moz-hyphens: none; + -ms-hyphens: none; + hyphens: none; + background: #f5f7ff; + color: #5e6687; +} + +pre > code[class*="language-"] { + font-size: 1em; +} + +pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection, +code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection { + text-shadow: none; + background: #dfe2f1; +} + +pre[class*="language-"]::selection, pre[class*="language-"] ::selection, +code[class*="language-"]::selection, code[class*="language-"] ::selection { + text-shadow: none; + background: #dfe2f1; +} + +/* Code blocks */ +pre[class*="language-"] { + padding: 1em; + margin: .5em 0; + overflow: auto; +} + +/* Inline code */ +:not(pre) > code[class*="language-"] { + padding: .1em; + border-radius: .3em; +} + +.token.comment, +.token.prolog, +.token.doctype, +.token.cdata { + color: #898ea4; +} + +.token.punctuation { + color: #5e6687; +} + +.token.namespace { + opacity: .7; +} + +.token.operator, +.token.boolean, +.token.number { + color: #c76b29; +} + +.token.property { + color: #c08b30; +} + +.token.tag { + color: #3d8fd1; +} + +.token.string { + color: #22a2c9; +} + +.token.selector { + color: #6679cc; +} + +.token.attr-name { + color: #c76b29; +} + +.token.entity, +.token.url, +.language-css .token.string, +.style .token.string { + color: #22a2c9; +} + +.token.attr-value, +.token.keyword, +.token.control, +.token.directive, +.token.unit { + color: #ac9739; +} + +.token.statement, +.token.regex, +.token.atrule { + color: #22a2c9; +} + +.token.placeholder, +.token.variable { + color: #3d8fd1; +} + +.token.deleted { + text-decoration: line-through; +} + +.token.inserted { + border-bottom: 1px dotted #202746; + text-decoration: none; +} + +.token.italic { + font-style: italic; +} + +.token.important, +.token.bold { + font-weight: bold; +} + +.token.important { + color: #c94922; +} + +.token.entity { + cursor: help; +} + +pre > code.highlight { + outline: 0.4em solid #c94922; + outline-offset: .4em; +} + +/* overrides color-values for the Line Numbers plugin + * http://prismjs.com/plugins/line-numbers/ + */ +.line-numbers .line-numbers-rows { + border-right-color: #dfe2f1; +} + +.line-numbers-rows > span:before { + color: #979db4; +} + +/* overrides color-values for the Line Highlight plugin + * http://prismjs.com/plugins/line-highlight/ + */ +.line-highlight { + background: rgba(107, 115, 148, 0.2); + background: -webkit-linear-gradient(left, rgba(107, 115, 148, 0.2) 70%, rgba(107, 115, 148, 0)); + background: linear-gradient(to right, rgba(107, 115, 148, 0.2) 70%, rgba(107, 115, 148, 0)); +} diff --git a/doc/docs/.vuepress/theme/styles/config.styl b/doc/docs/.vuepress/theme/styles/config.styl new file mode 100644 index 0000000..9e40321 --- /dev/null +++ b/doc/docs/.vuepress/theme/styles/config.styl @@ -0,0 +1 @@ +$contentClass = '.theme-default-content' diff --git a/doc/docs/.vuepress/theme/styles/custom-blocks.styl b/doc/docs/.vuepress/theme/styles/custom-blocks.styl new file mode 100644 index 0000000..5b86816 --- /dev/null +++ b/doc/docs/.vuepress/theme/styles/custom-blocks.styl @@ -0,0 +1,44 @@ +.custom-block + .custom-block-title + font-weight 600 + margin-bottom -0.4rem + &.tip, &.warning, &.danger + padding .1rem 1.5rem + border-left-width .5rem + border-left-style solid + margin 1rem 0 + &.tip + background-color #f3f5f7 + border-color #42b983 + &.warning + background-color rgba(255,229,100,.3) + border-color darken(#ffe564, 35%) + color darken(#ffe564, 70%) + .custom-block-title + color darken(#ffe564, 50%) + a + color $textColor + &.danger + background-color #ffe6e6 + border-color darken(red, 20%) + color darken(red, 70%) + .custom-block-title + color darken(red, 40%) + a + color $textColor + &.details + display block + position relative + border-radius 2px + margin 1.6em 0 + padding 1.6em + background-color #eee + h4 + margin-top 0 + figure, p + &:last-child + margin-bottom 0 + padding-bottom 0 + summary + outline none + cursor pointer diff --git a/doc/docs/.vuepress/theme/styles/index.styl b/doc/docs/.vuepress/theme/styles/index.styl new file mode 100644 index 0000000..ecef658 --- /dev/null +++ b/doc/docs/.vuepress/theme/styles/index.styl @@ -0,0 +1,202 @@ +@require './config' +@require './code' +@require './custom-blocks' +@require './arrow' +@require './wrapper' +@require './toc' + +html, body + padding 0 + margin 0 + background-color #fff + +body + font-family -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif + -webkit-font-smoothing antialiased + -moz-osx-font-smoothing grayscale + font-size 16px + color $textColor + +.page + padding-left $sidebarWidth + +.navbar + position fixed + z-index 20 + top 0 + left 0 + right 0 + height $navbarHeight + background-color #fff + box-sizing border-box + border-bottom 1px solid $borderColor + +.sidebar-mask + position fixed + z-index 9 + top 0 + left 0 + width 100vw + height 100vh + display none + +.sidebar + font-size 16px + background-color #fff + width $sidebarWidth + position fixed + z-index 10 + margin 0 + top $navbarHeight + left 0 + bottom 0 + box-sizing border-box + border-right 1px solid $borderColor + overflow-y auto + +{$contentClass}:not(.custom) + @extend $wrapper + > *:first-child + margin-top $navbarHeight + + a:hover + text-decoration underline + + p.demo + padding 1rem 1.5rem + border 1px solid #ddd + border-radius 4px + + img + max-width 100% + +{$contentClass}.custom + padding 0 + margin 0 + + img + max-width 100% + +a + font-weight 500 + color $accentColor + text-decoration none + +p a code + font-weight 400 + color $accentColor + +kbd + background #eee + border solid 0.15rem #ddd + border-bottom solid 0.25rem #ddd + border-radius 0.15rem + padding 0 0.15em + +blockquote + font-size 1rem + color #999; + border-left .2rem solid #dfe2e5 + margin 1rem 0 + padding .25rem 0 .25rem 1rem + + & > p + margin 0 + +ul, ol + padding-left 1.2em + +strong + font-weight 600 + +h1, h2, h3, h4, h5, h6 + font-weight 600 + line-height 1.25 + + {$contentClass}:not(.custom) > & + margin-top (0.5rem - $navbarHeight) + padding-top ($navbarHeight + 1rem) + margin-bottom 0 + + &:first-child + margin-top -1.5rem + margin-bottom 1rem + + + p, + pre, + .custom-block + margin-top 2rem + + &:focus .header-anchor, + &:hover .header-anchor + opacity: 1 + +h1 + font-size 2.2rem + +h2 + font-size 1.65rem + padding-bottom .3rem + border-bottom 1px solid $borderColor + +h3 + font-size 1.35rem + +a.header-anchor + font-size 0.85em + float left + margin-left -0.87em + padding-right 0.23em + margin-top 0.125em + opacity 0 + + &:focus, + &:hover + text-decoration none + +code, kbd, .line-number + font-family 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 + +p, ul, ol + line-height 1.7 + +hr + border 0 + border-top 1px solid $borderColor + +table + border-collapse collapse + margin 1rem 0 + display: block + overflow-x: auto + +tr + border-top 1px solid #dfe2e5 + + &:nth-child(2n) + background-color #f6f8fa + +th, td + border 1px solid #dfe2e5 + padding .6em 1em + +.theme-container + &.sidebar-open + .sidebar-mask + display: block + + &.no-navbar + {$contentClass}:not(.custom) > h1, h2, h3, h4, h5, h6 + margin-top 1.5rem + padding-top 0 + + .sidebar + top 0 + +@media (min-width: ($MQMobile + 1px)) + .theme-container.no-sidebar + .sidebar + display none + + .page + padding-left 0 + +@require 'mobile.styl' diff --git a/doc/docs/.vuepress/theme/styles/mobile.styl b/doc/docs/.vuepress/theme/styles/mobile.styl new file mode 100644 index 0000000..f5bd327 --- /dev/null +++ b/doc/docs/.vuepress/theme/styles/mobile.styl @@ -0,0 +1,37 @@ +@require './config' + +$mobileSidebarWidth = $sidebarWidth * 0.82 + +// narrow desktop / iPad +@media (max-width: $MQNarrow) + .sidebar + font-size 15px + width $mobileSidebarWidth + .page + padding-left $mobileSidebarWidth + +// wide mobile +@media (max-width: $MQMobile) + .sidebar + top 0 + padding-top $navbarHeight + transform translateX(-100%) + transition transform .2s ease + .page + padding-left 0 + .theme-container + &.sidebar-open + .sidebar + transform translateX(0) + &.no-navbar + .sidebar + padding-top: 0 + +// narrow mobile +@media (max-width: $MQMobileNarrow) + h1 + font-size 1.9rem + {$contentClass} + div[class*="language-"] + margin 0.85rem -1.5rem + border-radius 0 diff --git a/doc/docs/.vuepress/theme/styles/toc.styl b/doc/docs/.vuepress/theme/styles/toc.styl new file mode 100644 index 0000000..d3e7106 --- /dev/null +++ b/doc/docs/.vuepress/theme/styles/toc.styl @@ -0,0 +1,3 @@ +.table-of-contents + .badge + vertical-align middle diff --git a/doc/docs/.vuepress/theme/styles/wrapper.styl b/doc/docs/.vuepress/theme/styles/wrapper.styl new file mode 100644 index 0000000..a99262c --- /dev/null +++ b/doc/docs/.vuepress/theme/styles/wrapper.styl @@ -0,0 +1,9 @@ +$wrapper + max-width $contentWidth + margin 0 auto + padding 2rem 2.5rem + @media (max-width: $MQNarrow) + padding 2rem + @media (max-width: $MQMobileNarrow) + padding 1.5rem + diff --git a/doc/docs/.vuepress/theme/util/index.js b/doc/docs/.vuepress/theme/util/index.js new file mode 100644 index 0000000..92fcd3b --- /dev/null +++ b/doc/docs/.vuepress/theme/util/index.js @@ -0,0 +1,244 @@ +export const hashRE = /#.*$/ +export const extRE = /\.(md|html)$/ +export const endingSlashRE = /\/$/ +export const outboundRE = /^[a-z]+:/i + +export function normalize (path) { + return decodeURI(path) + .replace(hashRE, '') + .replace(extRE, '') +} + +export function getHash (path) { + const match = path.match(hashRE) + if (match) { + return match[0] + } +} + +export function isExternal (path) { + return outboundRE.test(path) +} + +export function isMailto (path) { + return /^mailto:/.test(path) +} + +export function isTel (path) { + return /^tel:/.test(path) +} + +export function ensureExt (path) { + if (isExternal(path)) { + return path + } + const hashMatch = path.match(hashRE) + const hash = hashMatch ? hashMatch[0] : '' + const normalized = normalize(path) + + if (endingSlashRE.test(normalized)) { + return path + } + return normalized + '.html' + hash +} + +export function isActive (route, path) { + const routeHash = decodeURIComponent(route.hash) + const linkHash = getHash(path) + if (linkHash && routeHash !== linkHash) { + return false + } + const routePath = normalize(route.path) + const pagePath = normalize(path) + return routePath === pagePath +} + +export function resolvePage (pages, rawPath, base) { + if (isExternal(rawPath)) { + return { + type: 'external', + path: rawPath + } + } + if (base) { + rawPath = resolvePath(rawPath, base) + } + const path = normalize(rawPath) + for (let i = 0; i < pages.length; i++) { + if (normalize(pages[i].regularPath) === path) { + return Object.assign({}, pages[i], { + type: 'page', + path: ensureExt(pages[i].path) + }) + } + } + console.error(`[vuepress] No matching page found for sidebar item "${rawPath}"`) + return {} +} + +function resolvePath (relative, base, append) { + const firstChar = relative.charAt(0) + if (firstChar === '/') { + return relative + } + + if (firstChar === '?' || firstChar === '#') { + return base + relative + } + + const stack = base.split('/') + + // remove trailing segment if: + // - not appending + // - appending to trailing slash (last segment is empty) + if (!append || !stack[stack.length - 1]) { + stack.pop() + } + + // resolve relative path + const segments = relative.replace(/^\//, '').split('/') + for (let i = 0; i < segments.length; i++) { + const segment = segments[i] + if (segment === '..') { + stack.pop() + } else if (segment !== '.') { + stack.push(segment) + } + } + + // ensure leading slash + if (stack[0] !== '') { + stack.unshift('') + } + + return stack.join('/') +} + +/** + * @param { Page } page + * @param { string } regularPath + * @param { SiteData } site + * @param { string } localePath + * @returns { SidebarGroup } + */ +export function resolveSidebarItems (page, regularPath, site, localePath) { + const { pages, themeConfig } = site + + const localeConfig = localePath && themeConfig.locales + ? themeConfig.locales[localePath] || themeConfig + : themeConfig + + const pageSidebarConfig = page.frontmatter.sidebar || localeConfig.sidebar || themeConfig.sidebar + if (pageSidebarConfig === 'auto') { + return resolveHeaders(page) + } + + const sidebarConfig = localeConfig.sidebar || themeConfig.sidebar + if (!sidebarConfig) { + return [] + } else { + const { base, config } = resolveMatchingConfig(regularPath, sidebarConfig) + if (config === 'auto') { + return resolveHeaders(page) + } + return config + ? config.map(item => resolveItem(item, pages, base)) + : [] + } +} + +/** + * @param { Page } page + * @returns { SidebarGroup } + */ +function resolveHeaders (page) { + const headers = groupHeaders(page.headers || []) + return [{ + type: 'group', + collapsable: false, + title: page.title, + path: null, + children: headers.map(h => ({ + type: 'auto', + title: h.title, + basePath: page.path, + path: page.path + '#' + h.slug, + children: h.children || [] + })) + }] +} + +export function groupHeaders (headers) { + // group h3s under h2 + headers = headers.map(h => Object.assign({}, h)) + let lastH2 + headers.forEach(h => { + if (h.level === 2) { + lastH2 = h + } else if (lastH2) { + (lastH2.children || (lastH2.children = [])).push(h) + } + }) + return headers.filter(h => h.level === 2) +} + +export function resolveNavLinkItem (linkItem) { + return Object.assign(linkItem, { + type: linkItem.items && linkItem.items.length ? 'links' : 'link' + }) +} + +/** + * @param { Route } route + * @param { Array | Array | [link: string]: SidebarConfig } config + * @returns { base: string, config: SidebarConfig } + */ +export function resolveMatchingConfig (regularPath, config) { + if (Array.isArray(config)) { + return { + base: '/', + config: config + } + } + for (const base in config) { + if (ensureEndingSlash(regularPath).indexOf(encodeURI(base)) === 0) { + return { + base, + config: config[base] + } + } + } + return {} +} + +function ensureEndingSlash (path) { + return /(\.html|\/)$/.test(path) + ? path + : path + '/' +} + +function resolveItem (item, pages, base, groupDepth = 1) { + if (typeof item === 'string') { + return resolvePage(pages, item, base) + } else if (Array.isArray(item)) { + return Object.assign(resolvePage(pages, item[0], base), { + title: item[1] + }) + } else { + const children = item.children || [] + if (children.length === 0 && item.path) { + return Object.assign(resolvePage(pages, item.path, base), { + title: item.title + }) + } + return { + type: 'group', + path: item.path, + title: item.title, + sidebarDepth: item.sidebarDepth, + initialOpenGroupIndex: item.initialOpenGroupIndex, + children: children.map(child => resolveItem(child, pages, base, groupDepth + 1)), + collapsable: item.collapsable !== false + } + } +} diff --git a/doc/docs/README.md b/doc/docs/README.md new file mode 100755 index 0000000..dfc01d1 --- /dev/null +++ b/doc/docs/README.md @@ -0,0 +1,8 @@ +--- +home: true +heroImage: ./image/yuescript.svg +tagline: A language that compiles to Lua +actionText: Quick Start → +actionLink: /doc/ +footer: Made by Jin with ❤️ +--- diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md new file mode 100755 index 0000000..0d43d04 --- /dev/null +++ b/doc/docs/doc/README.md @@ -0,0 +1,594 @@ +--- +sidebar: auto +--- + + + +# Yuescript +logo + +## Introduction + +Yuescript is a dynamic language that compiles to Lua. The codes written in Yuescript are expressive and extremely concise. And it is suitable for writing some changing application logic with more maintainable codes and runs in a Lua embeded environment such as games or website servers. + +Yue (月) is the name of moon in Chinese and it's pronounced as [jyɛ]. + +### An Overview of Yuescript +```moonscript +-- import syntax +import "yue" as :p, :to_lua + +-- implicit objects +inventory = + equipment: + * "sword" + * "shield" + items: + * name: "potion" + count: 10 + * name: "bread" + count: 3 + +-- backcall +{1, 2, 3} + |> map (x)-> x * 2 + |> filter (x)-> x > 4 + |> reduce 0, (a, b)-> a + b + |> print + +-- metatable manipulation +apple = + size: 15 + index#: {color: 0x00ffff} +p apple.color, apple.#?, apple.index# + +-- js-like export syntax +export yuescript = "月之脚本" +``` + +
+-- import syntax
+import "yue" as :p, :to_lua
+
+-- implicit objects
+inventory =
+  equipment:
+    * "sword"
+    * "shield"
+  items:
+    * name: "potion"
+      count: 10
+    * name: "bread"
+      count: 3
+
+-- backcall
+{1, 2, 3}
+  |> map (x)-> x * 2
+  |> filter (x)-> x > 4
+  |> reduce 0, (a, b)-> a + b
+  |> print
+
+-- metatable manipulation
+apple =
+  size: 15
+  index#: {color: 0x00ffff}
+p apple.color, apple.#?, apple.index#
+
+-- js-like export syntax
+export yuescript = "月之脚本"
+
+
+ +## Installation + +* **Lua Module** + +  Install [luarocks](https://luarocks.org), a package manager for Lua modules. Then install it as a Lua module and executable with: + +``` +> luarocks install yuescript +``` + +  Or you can build `yue.so` file with: + +``` +> make shared LUAI=/usr/local/include/lua LUAL=/usr/local/lib/lua +``` + +  Then get the binary file from path **bin/shared/yue.so**. + +* **Binary Tool** + +  Clone this repo, then build and install executable with: +``` +> make install +``` + +  Build Yuescript tool without macro feature: +``` +> make install NO_MACRO=true +``` + +  Build Yuescript tool without built-in Lua binary: +``` +> make install NO_LUA=true +``` + +## Usage + +  Require the Yuescript module in Lua: +```Lua +-- require `main.yue` in Lua +require("yue")("main") + +-- use the Yuescript compiler in Lua +local yue = require("yue") +local codes, err, globals = yue.to_lua([[ +f = -> + print "hello world" +f! +]],{ + implicit_return_root = true, + reserve_line_number = true, + lint_global = true +}) +``` +  Use Yuescript tool with: +``` +> yue -h +Usage: yue [options|files|directories] ... + + -h Print this message + -e str Execute a file or raw codes + -t path Specify where to place compiled files + -o file Write output to file + -s Use spaces in generated codes instead of tabs + -m Generate minified codes + -p Write output to standard out + -b Dump compile time (doesn't write output) + -l Write line numbers from source codes + -v Print version + -- Read from standard in, print to standard out + (Must be first and only argument) + + Execute without options to enter REPL, type symbol '$' + in a single line to start/stop multi-line mode +``` +  Use cases: +  Recursively compile every Yuescript file with extension **.yue** under current path: **yue .** +  Compile and save results to a target path: **yue -t /target/path/ .** +  Compile and reserve debug info: **yue -l .** +  Compile and generate minified codes: **yue -m .** +  Execute raw codes: **yue -e 'print 123'** +  Execute a Yuescript file: **yue -e main.yue** + +## Macro + +### Common Usage +Macro function is used for evaluating a string in the compile time and insert the generated codes into final compilation. + +```moonscript +macro config = (debugging)-> + global debugMode = debugging == "true" + "" + +macro asserts = (cond)-> + debugMode and "assert #{cond}" or "" + +macro assert = (cond)-> + debugMode and "assert #{cond}" or "#{cond}" + +$config true +$asserts item ~= nil + +$config false +value = $assert item + +-- the passed expressions are treated as strings +macro and = (...)-> "#{ table.concat {...}, ' and ' }" +if $and f1!, f2!, f3! + print "OK" +``` + +
+macro config = (debugging)->
+  global debugMode = debugging == "true"
+  ""
+
+macro asserts = (cond)->
+  debugMode and "assert #{cond}" or ""
+
+macro assert = (cond)->
+  debugMode and "assert #{cond}" or "#{cond}"
+
+$config true
+$asserts item ~= nil
+
+$config false
+value = $assert item
+
+-- the passed expressions are treated as strings
+macro and = (...)-> "#{ table.concat {...}, ' and ' }"
+if $and f1!, f2!, f3!
+  print "OK"
+
+
+ +### Insert Raw Codes + +A macro function can either return a Yuescript string or a config table containing Lua codes. +```moonscript +macro yueFunc = (var)-> "local #{var} = ->" +$yueFunc funcA +funcA = -> "assign the Yue defined variable" + +-- take care and let Yuescript know the +-- local variables you declared in Lua code +macro luaFunc = (var)-> { + codes: "local function #{var}() end" + type: "lua" + locals: {var} +} +$luaFunc funcB +funcB = -> "assign the Lua defined variable" + +macro lua = (code)-> { + :code + type: "lua" +} + +-- the raw string leading and ending symbols are auto trimed +$lua[==[ +-- raw Lua codes insertion +if cond then + print("output") +end +]==] +``` + +
+macro yueFunc = (var)-> "local #{var} = ->"
+$yueFunc funcA
+funcA = -> "assign the Yue defined variable"
+
+-- take care and let Yuescript know the
+-- local variables you declared in Lua codes
+macro luaFunc = (var)-> {
+  codes: "local function #{var}() end"
+  type: "lua"
+  locals: {var}
+}
+$luaFunc funcB
+funcB = -> "assign the Lua defined variable"
+
+macro lua = (code)-> {
+  :code
+  type: "lua"
+}
+
+-- the raw string leading and ending symbols are auto trimed
+$lua[==[
+-- raw Lua codes insertion
+if cond then
+  print("output")
+end
+]==]
+
+
+ +### Export Macro + +Macro functions can be exported from a module and get imported in another module. It is recommanded to export macro functions in a single file to speed up compilation. +```moonscript +-- file: utils.yue +export macro map = (items, action)-> "[#{action} for _ in *#{items}]" +export macro filter = (items, action)-> "[_ for _ in *#{items} when #{action}]" +export macro foreach = (items, action)-> "for _ in *#{items} + #{action}" + +-- file main.yue +import "utils" as { + $, -- symbol to import all macros + $foreach: $each -- rename macro $foreach to $each +} +{1, 2, 3} |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ +``` + +
+-- file: utils.yue
+export macro map = (items, action)-> "[#{action} for _ in *#{items}]"
+export macro filter = (items, action)-> "[_ for _ in *#{items} when #{action}]"
+export macro foreach = (items, action)-> "for _ in *#{items}
+  #{action}"
+
+-- file main.yue
+-- import function is not available in browser, try it in a real environment
+--[[
+import "utils" as {
+  $, -- symbol to import all macros
+  $foreach: $each -- rename macro $foreach to $each
+}
+{1, 2, 3} |> $map(_ * 2) |> $filter(_ > 4) |> $each print _
+]]
+
+
+ +## Special Operator + +### Metatable + +The **#** operator can be used as a shortcut for metatable manipulation. + +* **Metatable Creation** +Create normal table with key **#** or metamethod key that ends with **#**. + +```moonscript +mt = {} +add = (right)=> #: mt, value: @value + right.value +mt.__add = add + +a = #: mt, value: 1 + -- set field with variable of the same name +b = :add#, value: 2 +c = add#: mt.__add, value: 3 + +d = a + b + c +print d.value + +close _ = close#: -> print "out of scope" +``` + +
+mt = {}
+add = (right)=> #: mt, value: @value + right.value
+mt.__add = add
+
+a = #: mt, value: 1
+ -- set field with variable of the same name
+b = :add#, value: 2
+c = add#: mt.__add, value: 3
+
+d = a + b + c
+print d.value
+
+close _ = close#: -> print "out of scope"
+
+
+ +* **Metatable Accessing** +Accessing metatable with key **#** or metamethod key that ends with **#**. + +```moonscript +-- create with metatable containing field "value" +tb = ["value"]#: 123 +tb.index# = tb.# +print tb.value + +tb.# = __index: {item: "hello"} +print tb.item +``` + +
+-- create with metatable containing field "value"
+tb = ["value"]#: 123
+tb.index# = tb.#
+print tb.value
+
+tb.# = __index: {item: "hello"}
+print tb.item
+
+
+ +* **Metatable Destructure** +Destruct metatable with metamethod key that ends with **#**. + +```moonscript +{item, :new, :close#, index#: getter} = tb +print item, new, close, getter +``` + +
+{item, :new, :close#, index#: getter} = tb
+print item, new, close, getter
+
+
+ +### Existence + +The **?** operator can be used in a variety of contexts to check for existence. + +```moonscript +func?! +print abc?["hello world"]?.xyz + +x = tab?.value +len = utf8?.len or string?.len or (o)-> #o + +if print and x? + print x + +with? io.open "test.txt", "w" + \write "hello" + \close! +``` + +
+func?!
+print abc?["hello world"]?.xyz
+
+x = tab?.value
+len = utf8?.len or string?.len or (o)-> #o
+
+if print and x?
+  print x
+
+with? io.open "test.txt", "w"
+  \write "hello"
+  \close!
+
+
+ +### Piping + +Instead of a series of nested function calls, you can pipe values with operator **|>**. +```moonscript +"hello" |> print +1 |> print 2 -- insert pipe item as the first argument +2 |> print 1, _, 3 -- pipe with a placeholder + +-- pipe expression in multiline +readFile "example.txt" + |> extract language, {} + |> parse language + |> emit + |> render + |> print +``` + +
+"hello" |> print
+1 |> print 2 -- insert pipe item as the first argument
+2 |> print 1, _, 3 -- pipe with a placeholder
+
+-- pipe expression in multiline
+readFile "example.txt"
+  |> extract language, {}
+  |> parse language
+  |> emit
+  |> render
+  |> print
+
+
+ +## Module + +### Import + +The import statement is a syntax sugar for requiring a module or help extracting items from an imported module. + +```moonscript +-- used as table destructure +do + import C, Ct, Cmt from require "lpeg" + import insert, concat from table + +-- shortcut for requring a module +do + import 'module' + import 'module_x' + import "d-a-s-h-e-s" + import "module.part" + +-- requring module with aliasing or table destruction +do + import "player" as PlayerModule + import "lpeg" as :C, :Ct, :Cmt + import "export" as {one, two, Something:{umm:{ch}}} +``` + +
+-- used as table destruction
+do
+  import C, Ct, Cmt from require "lpeg"
+  import insert, concat from table
+
+-- shortcut for requring a module
+do
+  import 'module'
+  import 'module_x'
+  import "d-a-s-h-e-s"
+  import "module.part"
+
+-- requring module with aliasing or table destruction
+do
+  import "player" as PlayerModule
+  import "lpeg" as :C, :Ct, :Cmt
+  import "export" as {one, two, Something:{umm:{ch}}}
+
+
+ +### Export + +The export statement offers a concise way to define modules. + +* **Named Export** +Named export will define a local variable as well as adding a field in the exported table. + +```moonscript +export a, b, c = 1, 2, 3 +export cool = "cat" + +export What = if this + "abc" +else + "def" + +export y = -> + hallo = 3434 + +export class Something + umm: "cool" +``` + +
+export a, b, c = 1, 2, 3
+export cool = "cat"
+
+export What = if this
+  "abc"
+else
+  "def"
+
+export y = ->
+  hallo = 3434
+
+export class Something
+  umm: "cool"
+
+
+ +* **Unnamed Export** +Unnamed export will add the target item into the array part of the exported table. + +```moonscript +d, e, f = 3, 2, 1 +export d, e, f + +export if this + 123 +else + 456 + +export with tmp + j = 2000 +``` + +
+d, e, f = 3, 2, 1
+export d, e, f
+
+export if this
+  123
+else
+  456
+
+export with tmp
+  j = 2000
+
+
+ +* **Default Export** +Using the **default** keyword in export statement to replace the exported table with any thing. + +```moonscript +export default -> + print "hello" + 123 +``` + +
+export default ->
+  print "hello"
+  123
+
+
\ No newline at end of file diff --git a/doc/docs/try/README.md b/doc/docs/try/README.md new file mode 100755 index 0000000..d6ba5dd --- /dev/null +++ b/doc/docs/try/README.md @@ -0,0 +1,6 @@ +# Yuescript Online Compiler +--- + +Try Yuescript in the browser with WASM. + + diff --git a/doc/package.json b/doc/package.json new file mode 100755 index 0000000..d484ef9 --- /dev/null +++ b/doc/package.json @@ -0,0 +1,25 @@ +{ + "name": "Yuescript", + "version": "0.0.1", + "description": "Documentation", + "main": "index.js", + "authors": { + "name": "Li Jin", + "email": "dragon-fly@qq.com" + }, + "repository": "https://github.com/pigpigyyy/Yuescript/doc", + "scripts": { + "dev": "vuepress dev docs", + "build": "vuepress build docs" + }, + "license": "MIT", + "devDependencies": { + "@vuepress/plugin-back-to-top": "^1.3.1", + "@vuepress/plugin-medium-zoom": "^1.3.1", + "vuepress": "^1.3.1" + }, + "dependencies": { + "vue-js-modal": "^2.0.0-rc.6", + "vue-prism-editor": "^1.2.2" + } +} -- cgit v1.2.3-55-g6feb