Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Kula 是一个基于 .net Framework 平台的解释型脚本语言。
![Kula_Daiamondo](https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg31.51tietu.net%2Fpic%2F2016-120803%2F20161208032542kjea4a3vlv462716.jpg&refer=http%3A%2F%2Fimg31.51tietu.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1624628894&t=79f9d7388b65c5efa64aae6f37c53c7a)

## 更新日志
### kula - ice coffin 0 (2021-5-26)
* 较为完善的基本语法
* 动态强类型系统
* 足够基本使用的内置函数
* 不完全封装的错误提示

### kula - test (2021-5-23)
* 测试级的语法
* 逻辑基本不能使用
Expand Down
2 changes: 2 additions & 0 deletions kula/kula/Core/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ static class Is
public static bool CQuote(char c) { return c == '\"' || c == '\''; }
public static bool CAssign(char c) { return (c == '='); }
}
public HashSet<string> KeyWord { get => keywordSet; }
public HashSet<string> Type { get => typeSet; }
private Lexer() { sourceCode = ""; }
public Lexer Read(string code) { sourceCode = code; return this; }
public Lexer Scan()
Expand Down
139 changes: 138 additions & 1 deletion kula/kula/Util/ConsoleUtility.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

using kula.Core;
using kula.Core.VMObj;
using kula.DataObj;

namespace kula.Util
{
static class ConsoleUtility
{
private static Dictionary<string, KvmBuiltinFunc>.KeyCollection func = Func.BuiltinFunc.Keys;
private static HashSet<string> keyword = Lexer.Instance.KeyWord;
private static HashSet<string> types = Lexer.Instance.Type;
public static Dictionary<LexTokenType, ConsoleColor> LexColorDict = new Dictionary<LexTokenType, ConsoleColor>()
{
{ LexTokenType.KEYWORD, ConsoleColor.Red },
Expand Down Expand Up @@ -72,13 +77,145 @@ public static void ReleaseRunCode(string code)
}
}

public static string Read()
{
StringBuilder ret = new StringBuilder("", 16);
StringBuilder str = new StringBuilder("", 16);
StringBuilder pre = new StringBuilder("", 16);
ConsoleKeyInfo tmp;
IEnumerator<string> i1 = func.GetEnumerator();
IEnumerator<string> i2 = keyword.GetEnumerator();
IEnumerator<string> i3 = types.GetEnumerator();
bool searching = false;
int cur = 1;
tmp=Console.ReadKey();
while (tmp.KeyChar != '\r')
{
if (tmp.KeyChar == '\t' && str.ToString() != "")
{
searching = true;
if (cur == 1 && searching)
{
while (i1.MoveNext())
{
String k = i1.Current;
if (k.Length > str.ToString().Length && k.Substring(0, str.ToString().Length) == str.ToString())
{
searching = false;
Console.SetCursorPosition(3, Console.CursorTop);
Console.Write(new string(' ', Console.WindowWidth - 4 - ret.ToString().Length));
Console.SetCursorPosition(3, Console.CursorTop);
Console.Write(ret.ToString().Substring(0, ret.ToString().Length - str.ToString().Length) + k);
if (pre.ToString().Length == 0) pre.Append(k);
else pre.Replace(pre.ToString(), k);
break;
}
}
if (searching)
{
i1 = func.GetEnumerator();
cur++;
}
}
if(cur==2 && searching)
{
while (i2.MoveNext())
{
String k = i2.Current;
if (k.Length > str.ToString().Length && k.Substring(0, str.ToString().Length) == str.ToString())
{
searching = false;
Console.SetCursorPosition(3, Console.CursorTop);
Console.Write(new string(' ', Console.WindowWidth - 4 - ret.ToString().Length));
Console.SetCursorPosition(3, Console.CursorTop);
Console.Write(ret.ToString().Substring(0, ret.ToString().Length - str.ToString().Length) + k);
if (pre.ToString().Length == 0) pre.Append(k);
else pre.Replace(pre.ToString(), k);
break;
}
}
if (searching)
{
i2 = keyword.GetEnumerator();
cur++;
}
}
if (cur == 3 && searching)
{
while (i3.MoveNext())
{
String k = i3.Current;
if (k.Length > str.ToString().Length && k.Substring(0, str.ToString().Length) == str.ToString())
{
searching = false;
Console.SetCursorPosition(3, Console.CursorTop);
Console.Write(new string(' ', Console.WindowWidth - 4 - ret.ToString().Length));
Console.SetCursorPosition(3, Console.CursorTop);
Console.Write(ret.ToString().Substring(0, ret.ToString().Length - str.ToString().Length) + k);
if (pre.ToString().Length == 0) pre.Append(k);
else pre.Replace(pre.ToString(), k);
break;
}
}
if (searching)
{
i3 = types.GetEnumerator();
cur++;
}
}
if (cur == 4)
{
Console.SetCursorPosition(3, Console.CursorTop);
Console.Write(new string(' ', Console.WindowWidth - 4 - ret.ToString().Length));
Console.SetCursorPosition(3, Console.CursorTop);
Console.Write(ret.ToString());
cur = 1;
}
}
else if (tmp.KeyChar == 8)
{
if (pre.ToString().Length > 0)
{
if (ret.ToString().Length - str.ToString().Length >= 0) ret.Replace(str.ToString(), pre.ToString(), ret.ToString().Length - str.ToString().Length, str.ToString().Length);
str.Replace(str.ToString(), pre.ToString());
pre.Replace(pre.ToString(), "");
}
if (str.ToString().Length > 0) str.Remove(str.ToString().Length - 1, 1);
if (ret.ToString().Length > 0) ret.Remove(ret.ToString().Length - 1, 1);
Console.SetCursorPosition(3, Console.CursorTop);
Console.Write(new string(' ', Console.WindowWidth - 4 - ret.ToString().Length));
Console.SetCursorPosition(3, Console.CursorTop);
Console.Write(ret.ToString());
}
else if(32<=tmp.KeyChar&&tmp.KeyChar<=126)
{
if (pre.ToString().Length > 0)
{
if (ret.ToString().Length - str.ToString().Length >= 0) ret.Replace(str.ToString(), pre.ToString(), ret.ToString().Length - str.ToString().Length, str.ToString().Length);
str.Replace(str.ToString(), "");
pre.Replace(pre.ToString(), "");
}
if (('a' <= tmp.KeyChar && tmp.KeyChar <= 'z') || ('A' <= tmp.KeyChar && tmp.KeyChar <= 'Z')) str.Append(tmp.KeyChar);
else if ((tmp.KeyChar == ' ' || tmp.KeyChar == '=') && str.ToString().Length > 0) str.Replace(str.ToString(), "");
ret.Append(tmp.KeyChar);
Console.SetCursorPosition(3, Console.CursorTop);
Console.Write(new string(' ', Console.WindowWidth - 4 - ret.ToString().Length));
Console.SetCursorPosition(3, Console.CursorTop);
Console.Write(ret.ToString());
}
tmp = Console.ReadKey();
}
Console.WriteLine();
return ret.ToString();
}

public static void DebugREPL()
{
string code;
while (true)
{
Console.Write(">> ");
code = Console.ReadLine();
code = Read();
if (code == "#exit")
{
break;
Expand Down