]> git.lizzy.rs Git - nothing.git/commitdiff
(#303) Introduce string and stream readers
authorrexim <reximkut@gmail.com>
Tue, 28 Aug 2018 11:57:33 +0000 (18:57 +0700)
committerrexim <reximkut@gmail.com>
Tue, 28 Aug 2018 11:57:33 +0000 (18:57 +0700)
src/script/parser.c
src/script/parser.h

index 9f063a42f0729f0a1e97a59807b59851eca6b97e..88b3451e8f0f0dd0272be7569c6bfa80202592cd 100644 (file)
@@ -1,16 +1,19 @@
 #include <assert.h>
-#include <stdlib.h>
 #include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
 
 #include "script/parser.h"
 
+static struct ParseResult parse_expr(struct Token current_token);
+
 static struct ParseResult parse_cdr(struct Token current_token)
 {
     if (*current_token.begin != '.') {
         return parse_failure("Expected .", current_token.begin);
     }
 
-    struct ParseResult cdr = parse_expr(next_token(current_token.end));
+    struct ParseResult cdr = read_expr_from_string(current_token.end);
     if (cdr.is_error) {
         return cdr;
     }
@@ -131,7 +134,7 @@ static struct ParseResult parse_symbol(struct Token current_token)
         current_token.end);
 }
 
-struct ParseResult parse_expr(struct Token current_token)
+static struct ParseResult parse_expr(struct Token current_token)
 {
     if (*current_token.begin == 0) {
         return parse_failure("EOF", current_token.begin);
@@ -151,6 +154,18 @@ struct ParseResult parse_expr(struct Token current_token)
     return parse_symbol(current_token);
 }
 
+struct ParseResult read_expr_from_string(const char *str)
+{
+    assert(str);
+    return parse_expr(next_token(str));
+}
+
+struct ParseResult read_expr_from_stream(FILE *stream)
+{
+    assert(stream);
+    return parse_failure("not implemented", NULL);
+}
+
 struct ParseResult parse_success(struct Expr expr,
                                  const char *end)
 {
index 01b0b672ef9b0061489e57c65a36441c2d801c24..5f04fc56246e3a9a74708a97889b7ac833370ea2 100644 (file)
@@ -21,7 +21,8 @@ struct ParseResult parse_success(struct Expr expr,
 struct ParseResult parse_failure(const char *error,
                                  const char *end);
 
-struct ParseResult parse_expr(struct Token token);
+struct ParseResult read_expr_from_string(const char *str);
+struct ParseResult read_expr_from_stream(FILE *stream);
 
 void print_parse_error(FILE *stream,
                        const char *str,