Skip to content

Commit

Permalink
支持文言。Fix #88
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed Sep 7, 2020
1 parent 1d73b95 commit 907cf01
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/languages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export type Lang =
| 'viml'
| 'vue'
| 'wasm'
| 'wenyan'
| 'xml'
| 'xsl'
| 'yaml'
Expand Down
129 changes: 129 additions & 0 deletions packages/languages/data/wenyan.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"scopeName": "source.wenyan",
"patterns": [
{
"include": "#keywords"
},
{
"include": "#constants"
},
{
"include": "#operators"
},
{
"include": "#symbols"
},
{
"include": "#expression"
},
{
"include": "#comment-blocks"
},
{
"include": "#comment-lines"
}
],
"repository": {
"expression": {
"patterns": [
{
"include": "#variables"
}
]
},
"keywords": {
"patterns": [
{
"name": "storage.type",
"match": "數|列|言|術|爻|物|元"
},
{
"name": "keyword.control",
"match": "乃行是術曰|若其不然者|乃歸空無|欲行是術|乃止是遍|若其然者|其物如是|乃得矣|之術也|必先得|是術曰|恆為是|之物也|乃得|是謂|云云|中之|為是|乃止|若非|或若|之長|其餘"
},
{
"name": "keyword.control",
"match": "或云|蓋謂"
},
{
"name": "keyword.operator",
"match": "中有陽乎|中無陰乎|所餘幾何|不等於|不大於|不小於|等於|大於|小於|加|減|乘|除|變|以|於"
},
{
"name": "keyword.other",
"match": "不知何禍歟|不復存矣|姑妄行此|如事不諧|名之曰|吾嘗觀|之禍歟|乃作罷|吾有|今有|物之|書之|以施|昔之|是矣|之書|方悟|之義|嗚呼|之禍|有|施|曰|噫|取|今|夫|中|豈"
},
{
"name": "keyword.control",
"match": "也|凡|遍|若|者|之|充|銜"
}
]
},
"comment-lines": {
"name": "comment.line",
"begin": "注曰|疏曰|批曰",
"end": "$",
"patterns": [
{
"name": "constant.character",
"match": "\\\\."
}
]
},
"comment-blocks": {
"name": "comment.block",
"begin": "(注曰|疏曰|批曰)。?(「「|『)",
"end": "(」」|』)",
"patterns": [
{
"name": "constant.character",
"match": "\\\\."
}
]
},
"constants": {
"patterns": [
{
"name": "constant.numeric",
"match": "負|·|又|零|〇|一|二|三|四|五|六|七|八|九|十|百|千|萬|億|兆|京|垓|秭|穰|溝|澗|正|載|極|分|釐|毫|絲|忽|微|纖|沙|塵|埃|渺|漠"
},
{
"name": "constant.language",
"match": "其|陰|陽"
},
{
"name": "string.quoted",
"begin": "「「|『",
"end": "」」|』",
"patterns": [
{
"name": "constant.character",
"match": "\\\\."
}
]
}
]
},
"symbols": {
"patterns": [
{
"name": "punctuation.separator",
"match": "。|、"
}
]
},
"variables": {
"name": "variable.other",
"begin": "",
"end": "",
"patterns": [
{
"name": "constant.character",
"match": "\\\\."
}
]
}
},
"name": "wenyan"
}
6 changes: 6 additions & 0 deletions packages/languages/src/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export type Lang =
| 'viml'
| 'vue'
| 'wasm'
| 'wenyan'
| 'xml'
| 'xsl'
| 'yaml'
Expand Down Expand Up @@ -591,6 +592,11 @@ export const languages: ILanguageRegistration[] = [
scopeName: 'source.wat',
path: path.resolve(__dirname, '../data/wasm.tmLanguage.json')
},
{
id: 'wenyan',
scopeName: 'source.wenyan',
path: path.resolve(__dirname, '../data/wenyan.tmLanguage.json')
},
{
id: 'xml',
scopeName: 'text.xml',
Expand Down
7 changes: 6 additions & 1 deletion scripts/normalizeGrammarFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ function normalizeGrammarFile(file, newName) {
? json5.parse(fs.readFileSync(oldPath, 'utf-8'))
: plistParse(fs.readFileSync(oldPath, 'utf-8'))

const kebabName = newName || kebabCase(parsedContent.name.toLowerCase())
let kebabName = newName
if (!kebabName && parsedContent.name) {
kebabName = kebabCase(parsedContent.name.toLowerCase())
} else if (!kebabName && parsedContent.scopeName) {
kebabName = kebabCase(parsedContent.scopeName.split('.').pop())
}
const newPath = path.resolve(GRAMMAR_FOLDER_PATH, `${kebabName}.tmLanguage.json`)
parsedContent.name = kebabName
if (newPath !== oldPath) {
Expand Down
3 changes: 2 additions & 1 deletion scripts/pullGrammarsFromGitHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const languageSources = [
'https://github.com/nwolverson/vscode-language-purescript/blob/master/syntaxes/purescript.json',
'https://github.com/sveltejs/language-tools/blob/master/packages/svelte-vscode/syntaxes/svelte.tmLanguage.json',
'https://github.com/samuelcolvin/jinjahtml-vscode/blob/master/syntaxes/jinja.tmLanguage.json',
'https://github.com/samuelcolvin/jinjahtml-vscode/blob/master/syntaxes/jinja-html.tmLanguage.json'
'https://github.com/samuelcolvin/jinjahtml-vscode/blob/master/syntaxes/jinja-html.tmLanguage.json',
'https://github.com/wenyan-lang/highlight/blob/master/tmGrammar.json'
]

async function go() {
Expand Down

0 comments on commit 907cf01

Please sign in to comment.