Skip to content

Commit 5b21d0e

Browse files
committed
parsed
1 parent 88680e6 commit 5b21d0e

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

source/app.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ int main(string[] args) {
266266
break;
267267
}
268268
case "--help": {
269-
writeln(usage.strip());
269+
writefln(usage.strip(), args[0]);
270270
return 0;
271271
}
272272
default: {

source/parser.d

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,25 @@ class IntegerNode : Node {
7979
}
8080

8181
class FuncDefNode : Node {
82-
string name;
83-
Node[] nodes;
84-
bool inline;
85-
bool raw;
82+
string name;
83+
Node[] nodes;
84+
bool inline;
85+
bool raw;
86+
string[] paramTypes;
87+
string[] params;
8688

8789
this(ErrorInfo perror) {
8890
type = NodeType.FuncDef;
8991
error = perror;
9092
}
9193

9294
override string toString() {
93-
string ret = format("func %s\n", name);
95+
string ret = format("func %s", name);
96+
97+
foreach (i, ref param ; params) {
98+
ret ~= format(" %s %s", paramTypes[i], param);
99+
}
100+
ret ~= " begin\n";
94101

95102
foreach (ref node ; nodes) {
96103
ret ~= " " ~ node.toString() ~ '\n';
@@ -526,6 +533,12 @@ class Parser {
526533
}
527534
}
528535

536+
bool IsIdentifier(string identifier) {
537+
return
538+
(tokens[i].type == TokenType.Identifier) &&
539+
(tokens[i].contents == identifier);
540+
}
541+
529542
Node ParseFuncDef(bool inline) {
530543
auto ret = new FuncDefNode(GetError());
531544
ret.inline = inline;
@@ -543,10 +556,16 @@ class Parser {
543556
ret.name = tokens[i].contents;
544557

545558
Next();
546-
Expect(TokenType.Identifier);
547-
if (tokens[i].contents != "begin") {
548-
Error("Expected begin keyword"); // TODO: add parameters
559+
560+
while (!IsIdentifier("begin")) {
561+
Expect(TokenType.Identifier);
562+
ret.paramTypes ~= tokens[i].contents;
563+
Next();
564+
Expect(TokenType.Identifier);
565+
ret.params ~= tokens[i].contents;
566+
Next();
549567
}
568+
550569
Next();
551570

552571
while (true) {

0 commit comments

Comments
 (0)