aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-10-30 09:39:04 +0200
committerBad Diode <bd@badd10de.dev>2021-10-30 09:39:04 +0200
commitf9a6691243d59915dad8785a321ca021bb27de27 (patch)
tree3e0e662799d83a2d132d6950812dee3406d3d439
parent58dfde37752f87e5df850ebe3a324dcb825fdb35 (diff)
downloadbdl-f9a6691243d59915dad8785a321ca021bb27de27.tar.gz
bdl-f9a6691243d59915dad8785a321ca021bb27de27.zip
Add minimal syntax file for vim
-rwxr-xr-xREADME.md2
-rw-r--r--misc/bdl.vim18
-rw-r--r--src/parser.c8
3 files changed, 22 insertions, 6 deletions
diff --git a/README.md b/README.md
index 8ffd273..cdb30a8 100755
--- a/README.md
+++ b/README.md
@@ -47,7 +47,6 @@ program : <statement>* EOF
47 47
48<definition> : ( def <symbol> <expression> ) 48<definition> : ( def <symbol> <expression> )
49 | ( fun <symbol> ( <symbol>* ) <body> ) 49 | ( fun <symbol> ( <symbol>* ) <body> )
50 ;
51 50
52<expression> : <constant> 51<expression> : <constant>
53 | ( lambda ( <symbol>* ) <body> ) 52 | ( lambda ( <symbol>* ) <body> )
@@ -55,7 +54,6 @@ program : <statement>* EOF
55 | ( if <expression> <expression> ) 54 | ( if <expression> <expression> )
56 | ( set! <symbol> <expression> ) 55 | ( set! <symbol> <expression> )
57 | ( <expression> <expression>* ) 56 | ( <expression> <expression>* )
58 ;
59 57
60<body> : <statement>* 58<body> : <statement>*
61 59
diff --git a/misc/bdl.vim b/misc/bdl.vim
new file mode 100644
index 0000000..438fc86
--- /dev/null
+++ b/misc/bdl.vim
@@ -0,0 +1,18 @@
1if exists("b:current_syntax")
2 finish
3endif
4
5let b:current_syntax = "bdl"
6
7syn keyword bdlKeyword lambda if def set! fun
8syn match bdlComment ";.*$"
9
10syn match bdlNumber '\d\+'
11syn match bdlNumber '[-+]\d\+'
12
13syn region bdlString start=/\v"/ skip=/\v\\./ end=/\v"/
14
15hi def link bdlKeyword Keyword
16hi def link bdlComment Comment
17hi def link bdlNumber Number
18hi def link bdlString String
diff --git a/src/parser.c b/src/parser.c
index e32a571..2215fad 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -375,12 +375,13 @@ parse_tree(Parser *parser, Errors *errors) {
375 375
376Root * 376Root *
377parse(Token *tokens, Errors *errors) { 377parse(Token *tokens, Errors *errors) {
378 // Build initial AST.
379 array_init(roots, 0); 378 array_init(roots, 0);
380 Parser parser = { 379 Parser parser = {
381 .tokens = tokens, 380 .tokens = tokens,
382 .current = 0, 381 .current = 0,
383 }; 382 };
383
384 // Build initial ASTs. This also ensures the core grammar is correct.
384 while (has_next_token(&parser)) { 385 while (has_next_token(&parser)) {
385 Object *root = parse_tree(&parser, errors); 386 Object *root = parse_tree(&parser, errors);
386 OBJ_PRINT(root); 387 OBJ_PRINT(root);
@@ -391,9 +392,8 @@ parse(Token *tokens, Errors *errors) {
391 } 392 }
392 393
393 // Perform semantic analysis. 394 // Perform semantic analysis.
394 // 1. Ensure core grammar is correct. 395 // TODO: Check that symbols are defined before usage.
395 // 2. Check that symbols are defined before usage. 396 // TODO: Remove unnecessary statements.
396 // 3. Remove unnecessary statements.
397 return roots; 397 return roots;
398} 398}
399 399