mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
New failable based error handling. Labelled break/continue/next.
This commit is contained in:
committed by
Christoffer Lerno
parent
10f715cec0
commit
dc86c21210
@@ -8,10 +8,10 @@ func int main()
|
||||
}
|
||||
}
|
||||
|
||||
func string@ bin(int x)
|
||||
func string bin(int x)
|
||||
{
|
||||
int bits = (x == 0) ? 1 : log10(cast(x, double)) / log10(2);
|
||||
string@ ret = string.make_repeat('0', bits);
|
||||
string ret = str.make_repeat('0', bits);
|
||||
for (int i = 0; i < bits; i++)
|
||||
{
|
||||
ret[bits - i - 1] = x & 1 ? '1' : '0';
|
||||
|
||||
@@ -21,12 +21,7 @@ func void main()
|
||||
{
|
||||
string s = match.string;
|
||||
printf("Enter a value for '%s': ", s.slice(1, s.size - 2));
|
||||
string! word = strin.readln().strip();
|
||||
catch (word)
|
||||
{
|
||||
// Exit on error.
|
||||
return;
|
||||
}
|
||||
string word = strin.readln().strip() else return;
|
||||
story = story.replace(s, word);
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ struct Parser
|
||||
/**
|
||||
* @ensure const(input)
|
||||
*/
|
||||
func Parser.parse(Parser* p, char* input, char* diagMsg, Blocks* blocks) throws
|
||||
func void! Parser.parse(Parser* p, char* input, char* diagMsg, Blocks* blocks)
|
||||
{
|
||||
p.tokenizer.init(input);
|
||||
p.tok.init();
|
||||
@@ -125,15 +125,9 @@ func Parser.parse(Parser* p, char* input, char* diagMsg, Blocks* blocks) throws
|
||||
|
||||
try p.consumeToken();
|
||||
try p.parseTopLevel();
|
||||
return true;
|
||||
|
||||
catch (error e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
func void Parser.parseTopLevel(Parser* p) throws ParseError
|
||||
func void! Parser.parseTopLevel(Parser* p)
|
||||
{
|
||||
// key = value
|
||||
// | [[array]]
|
||||
@@ -150,7 +144,7 @@ func void Parser.parseTopLevel(Parser* p) throws ParseError
|
||||
p.parseTableArray();
|
||||
default:
|
||||
sprintf(p.errorMsg, "syntax error %s", p.tok.loc.str());
|
||||
throw ParseError.SYNTAX_ERROR;
|
||||
return SyntaxError!;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user