CatyScript2.0ãä¼ç»ãã¦ã¾ãããå®éã«ä½¿ããããã«ãªãã®ã¯ã ãã¶å ããªã
ããã°ã©ãã³ã°è¨èªãããç¨åº¦ã®è¡¨ç¾è½åãæã£ã¦ãããã¨ã®åºæºã¨ãã¦ããèªåã§èªåãè¨è¿°ã§ããããã¨ãããã¾ããCatyScript2.0ã¯ãCatyã®ã¡ã«ããºã ãè¨è¿°ã§ããè½åãæãããã¤ããã§ããã¨ã¯ãããã¢ã«ã´ãªãºã ã®è©³ç´°ãæ¸ããããªç¨éã«ã¯ã¾ã£ããä¸åãã§ããæ¦ç¥ã説æããæ¬ä¼¼ã³ã¼ãã®ããã«ä½¿ããããæ¬ä¼¼ãããªãã¦å®éã«åããã¨ããã®ãç®æ¨ã
CatyScriptã使ã£ã¦Catyèªèº«ãè¨è¿°ããã¨ã¯ã©ããããã¨ããCatyã®å¯¾è©±çã·ã§ã«ãé¡æã«ãã¦å®éã«ãã£ã¦ã¿ã¾ãããã®éç¨ã§ãCatyScript2.0ã®ï¼äºå®ããã¦ããï¼æ©è½ãç´¹ä»ãã¾ãã
ã¿ã°ã¨åå²
Catyã®æ±ããã¼ã¿æ§é ã¯JSONããããã«æ¡å¼µãããã®ï¼XJSONï¼ã§ããæ¡å¼µããç¹ã¯ã¿ã°ãä»ãããããã¨ã§ããã¿ã°ã¯ã¢ãããã¼ã¯ã§å§ã¾ãååã§ã@yen 1200 ã @person {"name" : "åæ±ãã³å", "age" : 25} ããã®ä¾ã§ãã"hello" ã¨ã [2, 3] ã«ã¯ã¿ã°ãä»ãã¦ã¾ããããããã㯠@string "hello"ã@array [2, 3] ã¨ã¿ãªããã¾ãã
ã¿ã°ã¯åå²æ§æã§ä½¿ããã¾ããåã«ããæ¯ãåãï¼type dispatchï¼ã¯æ¬¡ã®ãããªæãã
when {
number => ï¼numberåãã¼ã¿ã®å¦çï¼,
string => ï¼stringåãã¼ã¿ã®å¦çï¼,
array => ï¼arrayåãã¼ã¿ã®å¦çï¼,
object => ï¼objectåãã¼ã¿ã®å¦çï¼
}
ã¿ã°ã®ç¨éã¯åã®ç®å°ã ãã¨ã¯éãã¾ãããé常ã«ãã使ãã®ã¯ãå¦çãæåããç®å°ã«@OKã失æããã@NGãä»ãããã¼ã¿ãè¿ãæ¹æ³ã§ãã
some-command |
when {
OK => ï¼æåæã®å¦çï¼,
NG => ï¼å¤±ææã®å¦çï¼
}
if-then-elseã®ããã«ä½¿ãã¨ãã¯ãè¿°èªã³ãã³ãï¼predicate commandï¼ã使ãã¾ããè¿°èªã³ãã³ãã¯ãå ¥åã«å¯¾ãã¦@True, @Falseã¨ããã¿ã°ãä»ãã¦åºåãã¾ãã
pred-command |
when {
True => ï¼è¿°èªãçã®ã¨ãã®å¦çï¼,
False => ï¼è¿°èªãå½ã®ã¨ãã®å¦çï¼
}
ãããã®æ©è½ã¯ç¾ç¶ã§ä½¿ãã¾ãã
ä¾å¤å¦ç
CatyScript2.0ã®ä¾å¤å¦çã®äºç´èªã¯ãä¸éã§ä¸çªãã使ããã¦ããã§ããããtryãã«ãããã¨æãã¾ããtry {...} ã¨ãããããã¯å ã§çºçããä¾å¤ã¯ææããã¾ããä¾å¤ã«ã¯@#exceptã¨ããç¹æ®ãªã¿ã°ãä»ããããæ£å¸¸çµäºããã°@#normalã¨ããç¹æ®ãªã¿ã°ãä»ãããã¾ããã¤ã¾ããtryå¼ã®åºåã¯ã#exceptã¾ãã¯#normalã¨ããç¹æ®ãªã·ã³ãã«ã§ã¿ã°ä»ããããå¤ã¨ãªãã¾ãã
ä¾å¤å¦çã¯æ¬¡ã®ããã«æ¸ãã¾ãã
try {ï¼ä¾å¤ãèµ·ãããããããªãã³ã¼ãï¼} |
when {
#except => ï¼ä¾å¤ãã³ããªã³ã°ã³ã¼ãï¼,
#nromal => ï¼æ£å¸¸å¦çã®ç¶ãï¼
}
è²ä»ãã®çµµã§æãã¨æ¬¡ã®ããã
ç¹°ãè¿ã
ç¹°ãè¿ãã«ã¼ãã¯ãbegin/repeatæ§æã使ãã¾ããbegin {...} ã¨ããbeginãããã¯å ã§repeatãå®è¡ãããã¨ãbeginãããã¯ã®å é ããå®è¡ãç¹°ãè¿ããã¾ããrepeatã«åºä¼ããªããªããbeginãããã¯ãæãã¾ãã
begin/repeatã使ã£ã¦ãCatyã®å¯¾è©±çã·ã§ã«ã¯æ¬¡ã®ããã«æ¸ãã¾ãã
"Caty interactive shell" | cout; // ãªã¼ããã³ã°ããã¼
/* ãããã¬ãã«ã»ã«ã¼ã */
begin {
"> " | cout --no-nl; // ããã³ãããæ¹è¡ããªã
cin | eval | xjson:pretty | cout; // read-eval-print
repeat
}
使ããã¦ããã³ãã³ãã¯ï¼
- cout -- å ¥åãã³ã³ã½ã¼ã«ã«ï¼å¯ä½ç¨ã¨ãã¦ï¼æ¸ãåºããåºåã¯voidã
- cin -- ãã¼ãã¼ããã1è¡å ¥åãã¦ãåºåã¨ããã
- eval -- å ¥åãCatyScriptã¨ãã¦è©ä¾¡ãã¦ãå¤ï¼XJSONãã¼ã¿ï¼ãåºåã
- xjson:pretty -- XJSONãã¼ã¿ãæ´å½¢ããããã¹ãã¨ãã¦åºåã
ããã ã¨æ°¸ä¹ ã«çµãããªãã®ã§ãæååã "quit" ã§ãããã©ãããå¤å®ããè¿°èªã³ãã³ãã quit-p ã¨ãã¦ãçµäºã§ããããã«ãã¾ãããã
"Caty interactive shell" | cout;
begin {
"> " | cout --no-nl;
cin | quit-p |
when {
True => void, // ãããã¯ãæãã¦çµäº
False => eval | xjson:pretty | cout; repeat
}
}
evalã¯ä¾å¤ãèµ·ããå¯è½æ§ãããã®ã§ã次ã®å½¢ã§ä½¿ã£ãã»ããããã§ãããã
try {eval} |
when {
#except => print-error, // ã¨ã©ã¼ãé©åã«è¡¨ç¤ºããã³ãã³ã
#normal => xjson:pretty | cout
}; repeat
ã¹ã¯ãªããã«ããshellã³ãã³ãã®å®ç¾©
ç¾ç¶ã®Catyã§ã¯ãã¹ã¯ãªãããã³ãã³ãã¨ãã¦ä½¿ãã«ã¯ãã©ããªçãã¹ã¯ãªããã§ããã¡ã¤ã«ã«ããå¿ è¦ãããã¾ããããã¯ä¸ä¾¿ãªã®ã§ã次ã®å½¢ã®ã³ãã³ãå®ç¾©ããµãã¼ãããããã¨ï¼
command ï¼ååï¼ ï¼ã³ãã³ã宣è¨é é¨ï¼ {ï¼ã¹ã¯ãªããã³ã¼ãï¼};
ä¾ãã°ã次ã®ããã«ãªãã¾ãã
command eval-print :: string -> void {
try {eval} |
when {
#except => print-error,
#normal => xjson:pretty | cout
}
};command shell :: void -> void {
"Caty interactive shell" | cout;
begin {
"> " | cout --no-nl;
cin | quit-p |
when {
True => void, // ãããã¯ãæãã¦çµäº
False => eval-print; repeat
}
}
};
Catyã·ã§ã«å ã§shellã³ãã³ããå®è¡ããã¨ãCatyScriptã§æ¸ãããã·ã§ã«ãåãåºãã¾ãï¼ãããªãäºå®ï¼ã