-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c629ae7
commit 835234d
Showing
8 changed files
with
478 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# --------------------------------------------------------- | ||
# なでしこ3のバージョンをkonawiki2/3/nako3storageに反映 | ||
# --------------------------------------------------------- | ||
前提条件=「Gitリポジトリを以下のように設定してください。 | ||
# /path/to/nadesiko3 | ||
# /path/to/konawiki2 | ||
# /path/to/konawiki3 | ||
# /path/to/nako3storage | ||
」。 | ||
# --------------------------------------------------------- | ||
母艦パス取得してパス抽出して基本パスに代入。 | ||
DIR_REPO = (基本パスからパス抽出) | ||
VER=ナデシコバージョン。 | ||
VER_PHP=「<?php | ||
define('NAKO_DEFAULT_VERSION', '{VER}'); | ||
|
||
」 | ||
# --------------------------------------------------------- | ||
# リポジトリごとに処理 | ||
ファイル一覧=[ | ||
"/nako3storage/nako_version.inc.php", | ||
"/konawiki2/kona-engine/plugins/nako_version.inc.php", | ||
"/konawiki3/kona3engine/plugins/nako3/nako_version.inc.php" | ||
] | ||
ファイル一覧を反復 | ||
パス=DIR_REPO&対象 | ||
確認パス=(パスからパス抽出)。 | ||
もし、確認パスが存在しなければ | ||
「[ERROR] レポジトリ: {対象}」を表示。 | ||
前提条件を表示。終わり。 | ||
ここまで。 | ||
# コピー | ||
VER_PHPをパスに保存。 | ||
「=== === === ===」を表示; | ||
「[OK] {パス}」を表示。 | ||
# コミットする | ||
MSG="updated nako3 ver."&ナデシコバージョン; | ||
CMD=「cd "{確認パス}" && git commit -a -m "{MSG}" && git push」 | ||
エラー監視 | ||
CMDを起動待機。 | ||
エラーならば | ||
「コミットできません: {確認パス}」を表示。 | ||
ここまで。 | ||
ここまで。 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const a = require('caniuse-db/data.json').agents | ||
const e = {} | ||
const t = {} | ||
for (let key in a) { | ||
e[key] = a[key]['browser']; | ||
let type = a[key]['type']; | ||
if (t[type] === undefined) { | ||
t[type] = []; | ||
} | ||
t[type].push(key) | ||
} | ||
console.log(JSON.stringify(e)) | ||
// console.log(JSON.stringify(t)) | ||
// console.log(JSON.stringify(a)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"and_chr":["100"],"and_ff":["98"],"and_qq":["10.4"],"and_uc":["12.12"],"android":["99"],"baidu":["7.12"],"chrome":["100","99","98","97","96"],"edge":["99","98","97"],"firefox":["98","97","96","91"],"ie":["11"],"ios_saf":["15.4","15.2-15.3","15.0-15.1","14.5-14.8","14.0-14.4","12.2-12.5"],"kaios":["2.5"],"node":["17.4.0","16.13.0","14.19.0","12.22.0"],"op_mini":["all"],"op_mob":["64"],"opera":["83","82"],"safari":["15.4","15.2-15.3","14.1"],"samsung":["16.0","15.0"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
and_chr 100 | ||
and_ff 98 | ||
and_qq 10.4 | ||
and_uc 12.12 | ||
android 99 | ||
baidu 7.12 | ||
chrome 100 | ||
chrome 99 | ||
chrome 98 | ||
chrome 97 | ||
chrome 96 | ||
edge 99 | ||
edge 98 | ||
edge 97 | ||
firefox 98 | ||
firefox 97 | ||
firefox 96 | ||
firefox 91 | ||
ie 11 | ||
ios_saf 15.4 | ||
ios_saf 15.2-15.3 | ||
ios_saf 15.0-15.1 | ||
ios_saf 14.5-14.8 | ||
ios_saf 14.0-14.4 | ||
ios_saf 12.2-12.5 | ||
kaios 2.5 | ||
node 17.4.0 | ||
node 16.13.0 | ||
node 14.19.0 | ||
node 12.22.0 | ||
op_mini all | ||
op_mob 64 | ||
opera 83 | ||
opera 82 | ||
safari 15.4 | ||
safari 15.2-15.3 | ||
safari 14.1 | ||
samsung 16.0 | ||
samsung 15.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{"ie":"IE","edge":"Edge","firefox":"Firefox","chrome":"Chrome","safari":"Safari","opera":"Opera","ios_saf":"Safari on iOS","op_mini":"Opera Mini","android":"Android Browser","bb":"Blackberry Browser","op_mob":"Opera Mobile","and_chr":"Chrome for Android","and_ff":"Firefox for Android","ie_mob":"IE Mobile","and_uc":"UC Browser for Android","samsung":"Samsung Internet","and_qq":"QQ Browser","baidu":"Baidu Browser","kaios":"KaiOS Browser"} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,264 @@ | ||
/** | ||
* DNCLに対応する構文 | ||
*/ | ||
const { NakoIndentError } = require('./nako_errors') | ||
const NakoPrepare = require('./nako_prepare') | ||
|
||
const DNCL_KEYWORDS = ['!DNCLモード'] | ||
/** | ||
* DNCLのソースコードをなでしこに変換する | ||
* @param {String} src | ||
* @param {String} filename | ||
* @returns {String} converted soruce | ||
*/ | ||
function convert(src, filename) { | ||
// 改行を合わせる | ||
src = src.replace(/(\r\n|\r)/g, '\n') | ||
// 「!DNCLモード」を使うかチェック | ||
if (!isIndentSyntaxEnabled(src)) { return src } | ||
let result = dncl2nako(src, filename) | ||
// console.log("=====\n" + result) | ||
// process.exit() | ||
return result | ||
} | ||
|
||
function isIndentSyntaxEnabled(src) { | ||
// プログラム冒頭に「!DNCLモード」があればDNCL構文が有効 | ||
const keywords = DNCL_KEYWORDS | ||
const lines = src.split('\n', 30) | ||
for (const line of lines) { | ||
const line2 = line.replace('!', '!') | ||
if (keywords.indexOf(line2) >= 0) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
/** | ||
* make space string | ||
* @param {number} n | ||
*/ | ||
function make_spaces(n) { | ||
let s = '' | ||
for (let i = 0; i < n; i++) { | ||
s += ' ' | ||
} | ||
return s | ||
} | ||
|
||
/** | ||
* DNCLからなでしこに変換する(判定なし) | ||
* @param {string} src | ||
* @param {string} filename | ||
* @returns {string} converted source | ||
*/ | ||
function dncl2nako(src, filename) { | ||
// 全角半角を統一 | ||
src = conv2half(src) | ||
// 行頭の「|」はインデントを表す記号なので無視する | ||
// 後判定の「繰り返し,」を「後判定で繰り返す」に置換する | ||
const a = src.split('\n') | ||
for (let i = 0; i < a.length; i++) { | ||
// インデントを消す | ||
let line = a[i] | ||
a[i] = line.replace(/^(\s*[|\s]+)(.*$)/, (m0, m1, m2) => { | ||
return make_spaces(m1.length) + m2 | ||
}) | ||
line = a[i] | ||
// 後判定の繰り返しの実装のため | ||
const line2 = line.replace(/^\s+/, '').replace(/\s+$/, '') | ||
if (line2 === '繰り返し,' || line2 === '繰り返し') { | ||
a[i] = '後判定で繰り返し' | ||
} | ||
const r = line.match(/^\s*を,?(.+)になるまで(繰り返す|実行する)/) | ||
if (r) { | ||
a[i] = `ここまで、(${r[1]})になるまでの間` | ||
continue | ||
} | ||
// 『もしj>hakosuならばhakosu←jを実行する』のような単文のもし文 | ||
const rif = line.match(/^もし(.+)を実行する(。|.)*/) | ||
if (rif) { | ||
const sent = dncl2nako(rif[1], filename) | ||
a[i] = `もし、${sent};` | ||
continue | ||
} | ||
//'のすべての値を0にする' | ||
//'のすべての要素を0にする' | ||
//'のすべての要素に0を代入する' | ||
const rall = line.match(/^(.+?)のすべての(要素|値)(を|に)(.+?)(にする|を代入)/) | ||
if (rall) { | ||
const varname = rall[1] | ||
const v = rall[4] | ||
a[i] = `${varname} = [${v},${v},${v},${v},${v},${v},${v},${v},${v},${v},${v},${v},${v},${v},${v},${v},${v},${v},${v},${v},${v}]` | ||
continue | ||
} | ||
} | ||
src = a.join('\n') | ||
// --------------------------------- | ||
// 置換開始 | ||
// --------------------------------- | ||
// 単純置換リスト | ||
const simple_conv_list = { | ||
'を実行する': 'ここまで', | ||
'を実行し,そうでなくもし': '違えば、もし', | ||
'を実行し,そうでなくもし': '違えば、もし', | ||
'を実行し、そうでなくもし': '違えば、もし', | ||
'を実行し,そうでなければ': '違えば', | ||
'を実行し,そうでなければ': '違えば', | ||
'を実行し、そうでなければ': '違えば', | ||
'を繰り返す': 'ここまで', | ||
'改行なしで表示': '連続無改行表示', | ||
'ずつ増やしながら':'ずつ増やし繰り返す', | ||
'ずつ減らしながら':'ずつ減らし繰り返す', | ||
'二進で表示': '二進表示', | ||
'でないならば': 'でなければ', | ||
} | ||
let peekChar = () => src.charAt(0) | ||
let nextChar = () => { | ||
let ch = src.charAt(0) | ||
src = src.substring(1) | ||
return ch | ||
} | ||
// 文字列を判定するフラグ | ||
let flagStr = false | ||
let poolStr = '' | ||
let endStr = '' | ||
// 結果 | ||
let result = '' | ||
while (src !='') { | ||
// 代入記号を変更 | ||
const ch = src.charAt(0) | ||
if (flagStr) { | ||
if (ch === endStr) { | ||
result += poolStr + endStr | ||
poolStr = '' | ||
flagStr = false | ||
nextChar() | ||
continue | ||
} | ||
poolStr += nextChar() | ||
continue | ||
} | ||
// 文字列? | ||
if (ch == '"') { | ||
flagStr = true | ||
endStr = '"' | ||
poolStr = nextChar() | ||
continue | ||
} | ||
if (ch == '「') { | ||
flagStr = true | ||
endStr = '」' | ||
poolStr = nextChar() | ||
continue | ||
} | ||
if (ch == '『') { | ||
flagStr = true | ||
endStr = '』' | ||
poolStr = nextChar() | ||
continue | ||
} | ||
// 空白を飛ばす | ||
if (ch === ' ' || ch === ' ' || ch == '\t') { | ||
result += nextChar() | ||
continue | ||
} | ||
// 表示を連続表示に置き換える | ||
const ch3 = src.substring(0, 3) | ||
if (ch3 === 'を表示') { | ||
result += 'を連続表示' | ||
src = src.substring(3) | ||
continue | ||
} | ||
if (src.substring(0, 4) === 'を 表示') { | ||
result += 'を連続表示' | ||
src = src.substring(4) | ||
continue | ||
} | ||
// 乱数を乱数範囲に置き換える | ||
if (src.substring(0, 2) === '乱数' && src.substring(0, 4) !== '乱数範囲') { | ||
result += '乱数範囲' | ||
src = src.substring(2) | ||
continue | ||
} | ||
// 増やす・減らすの前に「だけ」を追加する #1149 | ||
if (ch3 === '増やす' || ch3 === '減らす') { | ||
if (result.substring(result.length - 2) !== 'だけ') { | ||
result += 'だけ' | ||
} | ||
result += ch3 | ||
src = src.substring(3) | ||
} | ||
// 一覧から単純な変換 | ||
{ | ||
let flag = false | ||
for (let key in simple_conv_list) { | ||
const src_key = src.substring(0, key.length) | ||
if (src_key === key) { | ||
result += simple_conv_list[key] | ||
src = src.substring(key.length) | ||
flag = true | ||
break | ||
} | ||
} | ||
if (flag) { continue } | ||
} | ||
|
||
// 1文字削る | ||
result += nextChar() | ||
} | ||
return result | ||
} | ||
|
||
/** | ||
* 半角に変換 | ||
* @param {String} src | ||
* @returns {string} converted source | ||
*/ | ||
function conv2half(src) { | ||
const prepare = new NakoPrepare() // `※`, `//`, `/*` といったパターン全てに対応するために必要 | ||
// 全角半角の統一 | ||
let result = '' | ||
let flagStr = false | ||
let flagStrClose = '' | ||
for (let i = 0; i < src.length; i++) { | ||
let c = src.charAt(i) | ||
let cHalf = prepare.convert1ch(c) | ||
if (flagStr) { | ||
if (cHalf === flagStrClose) { | ||
flagStr = false | ||
flagStrClose = '' | ||
result += cHalf | ||
continue | ||
} | ||
result += c | ||
continue | ||
} | ||
if (cHalf === '「') { | ||
flagStr = true | ||
flagStrClose = '」' | ||
result += cHalf | ||
continue | ||
} | ||
if (cHalf === '"') { | ||
flagStr = true | ||
flagStrClose = '"' | ||
result += cHalf | ||
continue | ||
} | ||
// 単純な置き換えはここでやってしまう | ||
// 配列記号の { ... } を [ ... ] に置換 | ||
if (cHalf === '{') { cHalf = '[' } | ||
if (cHalf === '}') { cHalf = ']' } | ||
if (cHalf === '←') { cHalf = '=' } | ||
if (cHalf === '÷') { cHalf = '÷÷' } // #1152 | ||
result += cHalf | ||
} | ||
return result | ||
} | ||
|
||
|
||
module.exports = { | ||
convert, | ||
} |
Oops, something went wrong.