forked from PuqiAR/Fig-TreeWalker
[VER] 0.3.7-alpha
[Fix] 修复科学表达式数字解析的问题(Lexer引起) 由 Satklomi发现,感谢 [Feat] 增加Compiler相关定义,将开发BytecodeVM [Tip] Evaluator进入Bug fix阶段,新功能延缓开发。转向VM
This commit is contained in:
@@ -7,17 +7,40 @@
|
||||
|
||||
import std.value; // `type` function and string_from
|
||||
|
||||
|
||||
struct FormatError
|
||||
{
|
||||
public msg: String;
|
||||
}
|
||||
|
||||
impl Error for FormatError
|
||||
{
|
||||
getErrorClass()
|
||||
{
|
||||
return "FormatError";
|
||||
}
|
||||
getErrorMessage()
|
||||
{
|
||||
return getErrorClass() + ": " + msg;
|
||||
}
|
||||
toString()
|
||||
{
|
||||
return getErrorMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public func format(objects ...) -> Any
|
||||
{
|
||||
if objects.length() < 1
|
||||
{
|
||||
return null;
|
||||
throw FormatError{"Require format string"};
|
||||
}
|
||||
|
||||
var fmt := objects[0];
|
||||
if value.type(fmt) != "String"
|
||||
var fmtType := value.type(fmt);
|
||||
if fmtType != "String"
|
||||
{
|
||||
return null;
|
||||
throw FormatError{"arg 0 (fmt) must be String type, got " + fmtType};
|
||||
}
|
||||
|
||||
var result := "";
|
||||
@@ -33,7 +56,7 @@ public func format(objects ...) -> Any
|
||||
{
|
||||
if (i + 1 >= length)
|
||||
{
|
||||
return null;
|
||||
throw FormatError{"unclosed brace"};
|
||||
}
|
||||
|
||||
var nextChar = fmt[i + 1];
|
||||
@@ -57,12 +80,12 @@ public func format(objects ...) -> Any
|
||||
|
||||
if endIndex == -1
|
||||
{
|
||||
return null;
|
||||
throw FormatError{"unclosed brace"};
|
||||
}
|
||||
|
||||
if argIndex >= objects.length()
|
||||
{
|
||||
return null;
|
||||
throw FormatError{"require enough format expression"};
|
||||
}
|
||||
|
||||
result += value.string_from(objects[argIndex]);
|
||||
@@ -79,7 +102,7 @@ public func format(objects ...) -> Any
|
||||
continue;
|
||||
}
|
||||
|
||||
return null;
|
||||
throw FormatError{"invalid format syntax"};
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -97,15 +120,16 @@ public func formatByListArgs(objects) -> Any
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if objects.length() < 1
|
||||
if objects.length() < 1
|
||||
{
|
||||
return null;
|
||||
throw FormatError{"Require format string"};
|
||||
}
|
||||
|
||||
var fmt := objects[0];
|
||||
if value.type(fmt) != "String"
|
||||
var fmtType := value.type(fmt);
|
||||
if fmtType != "String"
|
||||
{
|
||||
return null;
|
||||
throw FormatError{"arg 0 (fmt) must be String type, got " + fmtType};
|
||||
}
|
||||
|
||||
var result := "";
|
||||
@@ -121,7 +145,7 @@ public func formatByListArgs(objects) -> Any
|
||||
{
|
||||
if (i + 1 >= length)
|
||||
{
|
||||
return null;
|
||||
throw FormatError{"unclosed brace"};
|
||||
}
|
||||
|
||||
var nextChar = fmt[i + 1];
|
||||
@@ -145,12 +169,12 @@ public func formatByListArgs(objects) -> Any
|
||||
|
||||
if endIndex == -1
|
||||
{
|
||||
return null;
|
||||
throw FormatError{"unclosed brace"};
|
||||
}
|
||||
|
||||
if argIndex >= objects.length()
|
||||
{
|
||||
return null;
|
||||
throw FormatError{"require enough format expression"};
|
||||
}
|
||||
|
||||
result += value.string_from(objects[argIndex]);
|
||||
@@ -167,7 +191,7 @@ public func formatByListArgs(objects) -> Any
|
||||
continue;
|
||||
}
|
||||
|
||||
return null;
|
||||
throw FormatError{"invalid format syntax"};
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -43,7 +43,8 @@ public func println(objects...) -> Int
|
||||
|
||||
public func printf(objects...) -> Any
|
||||
{
|
||||
__fstdout_print(formater.formatByListArgs(objects));
|
||||
var result := formater.formatByListArgs(objects);
|
||||
__fstdout_print(result);
|
||||
}
|
||||
|
||||
// inputs
|
||||
|
||||
Reference in New Issue
Block a user