Skip to content

Commit 15b9232

Browse files
committed
PiccodeScript: Complete overhaul of the syntax to resemble a little bit of JAI
1 parent 2083eae commit 15b9232

37 files changed

+1236
-963
lines changed

editors/Lite/language_piccodescript.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
-- mod-version:3
12
local syntax = require "core.syntax"
23

34
syntax.add {
@@ -18,13 +19,12 @@ syntax.add {
1819
symbols = {
1920
["import"] = "keyword",
2021
["module"] = "keyword",
21-
["function"] = "keyword",
22-
["let"] = "keyword",
2322
["if"] = "keyword",
2423
["else"] = "keyword",
2524
["do"] = "keyword",
2625
["when"] = "keyword",
2726
["is"] = "keyword",
27+
["await"] = "keyword",
2828
["true"] = "literal",
2929
["false"] = "literal",
3030
},

editors/language_piccodescript.lua

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
-- mod-version:3
2+
local syntax = require "core.syntax"
3+
4+
syntax.add {
5+
files = { "%.pics$"},
6+
comment = "//",
7+
patterns = {
8+
{ pattern = "//.-\n", type = "comment" },
9+
{ pattern = { "/%*", "%*/" }, type = "comment" },
10+
{ pattern = { '"', '"', '\\' }, type = "string" },
11+
{ pattern = { "'", "'", '\\' }, type = "string" },
12+
{ pattern = "-?0x%x+", type = "number" },
13+
{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
14+
{ pattern = "-?%.?%d+f?", type = "number" },
15+
{ pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
16+
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
17+
{ pattern = "[%a_][%w_]*", type = "symbol" },
18+
},
19+
symbols = {
20+
["import"] = "keyword",
21+
["module"] = "keyword",
22+
["function"] = "keyword",
23+
["let"] = "keyword",
24+
["if"] = "keyword",
25+
["else"] = "keyword",
26+
["do"] = "keyword",
27+
["when"] = "keyword",
28+
["is"] = "keyword",
29+
["true"] = "literal",
30+
["false"] = "literal",
31+
},
32+
}
33+

src/main/antlr4/PiccodeScript.g4

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ stmts: stmt*
1313

1414
stmt:
1515
import_module
16-
| func
17-
| module
16+
| declaration
1817
| expr_stmt;
1918

2019
import_module:
@@ -29,19 +28,19 @@ symbol_lift
2928
symbol_entry
3029
: ID (symbol_lift)? ;
3130

31+
declaration: ID CC (module | func);
3232

3333
module:
34-
MODULE ID LBRACE module_stmts RBRACE;
34+
MODULE LBRACE module_stmts RBRACE;
3535

3636
module_stmts:
3737
module_stmt*;
3838

3939
module_stmt:
40-
func
41-
| var_decl
42-
| module;
40+
declaration
41+
| var_decl;
4342

44-
func: FUNCTION ID func_args ASSIGN expr ;
43+
func: func_args ASSIGN expr ;
4544

4645
func_args: '(' arg_list? ')' ;
4746

@@ -64,6 +63,7 @@ expr
6463
: expr LPAREN call_expr_list? RPAREN
6564
| var_decl
6665
| closure_decl
66+
| expr CC expr
6767
| expr DOT expr
6868
| expr MUL expr
6969
| expr DIV expr
@@ -93,7 +93,6 @@ expr
9393
| array
9494
| tuple
9595
| object
96-
| ID
9796
| NUMBER
9897
| STRING
9998
;
@@ -107,7 +106,7 @@ unary:
107106
| BAND expr;
108107

109108
if_expr:
110-
IF expr LBRACE expr RBRACE ELSE LBRACE expr RBRACE;
109+
IF expr LBRACE expr* RBRACE (ELSE LBRACE expr* RBRACE)?;
111110

112111
when_expr:
113112
WHEN expr LBRACE when_cases else_case? RBRACE;
@@ -118,7 +117,7 @@ when_case: IS expr_list ARROW expr;
118117

119118
else_case: ELSE ARROW expr;
120119

121-
var_decl: LET ID ASSIGN expr;
120+
var_decl: ID (DASSIGN expr)?;
122121
tuple: LPAREN expr_list RPAREN;
123122
array: LBRACKET expr_list? RBRACKET;
124123
object: LBRACE key_val_pairs RBRACE;
@@ -157,6 +156,7 @@ BAND: '&';
157156
BOR: '|';
158157
EXCLAIM : '!';
159158
PIPE: '|>';
159+
CC: '::';
160160

161161
LBRACE: '{';
162162
RBRACE: '}';
@@ -172,9 +172,8 @@ TILDE: '~';
172172

173173

174174
ASSIGN: '=';
175+
DASSIGN: ':=';
175176

176-
LET: 'let';
177-
FUNCTION: 'function';
178177
WHEN: 'when';
179178
IMPORT: 'import';
180179
IS: 'is';

src/main/java/org/piccode/antlr4/PiccodeScript.interp

Lines changed: 6 additions & 5 deletions
Large diffs are not rendered by default.

src/main/java/org/piccode/antlr4/PiccodeScript.tokens

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ BAND=16
1717
BOR=17
1818
EXCLAIM=18
1919
PIPE=19
20-
LBRACE=20
21-
RBRACE=21
22-
LPAREN=22
23-
RPAREN=23
24-
LBRACKET=24
25-
RBRACKET=25
26-
COLON=26
27-
COMMA=27
28-
SEMI=28
29-
ARROW=29
30-
TILDE=30
31-
ASSIGN=31
32-
LET=32
33-
FUNCTION=33
20+
CC=20
21+
LBRACE=21
22+
RBRACE=22
23+
LPAREN=23
24+
RPAREN=24
25+
LBRACKET=25
26+
RBRACKET=26
27+
COLON=27
28+
COMMA=28
29+
SEMI=29
30+
ARROW=30
31+
TILDE=31
32+
ASSIGN=32
33+
DASSIGN=33
3434
WHEN=34
3535
IMPORT=35
3636
IS=36
@@ -64,20 +64,20 @@ WS=47
6464
'|'=17
6565
'!'=18
6666
'|>'=19
67-
'{'=20
68-
'}'=21
69-
'('=22
70-
')'=23
71-
'['=24
72-
']'=25
73-
':'=26
74-
','=27
75-
';'=28
76-
'->'=29
77-
'~'=30
78-
'='=31
79-
'let'=32
80-
'function'=33
67+
'::'=20
68+
'{'=21
69+
'}'=22
70+
'('=23
71+
')'=24
72+
'['=25
73+
']'=26
74+
':'=27
75+
','=28
76+
';'=29
77+
'->'=30
78+
'~'=31
79+
'='=32
80+
':='=33
8181
'when'=34
8282
'import'=35
8383
'is'=36

src/main/java/org/piccode/antlr4/PiccodeScriptBaseListener.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ public class PiccodeScriptBaseListener implements PiccodeScriptListener {
8585
* <p>The default implementation does nothing.</p>
8686
*/
8787
@Override public void exitSymbol_entry(PiccodeScriptParser.Symbol_entryContext ctx) { }
88+
/**
89+
* {@inheritDoc}
90+
*
91+
* <p>The default implementation does nothing.</p>
92+
*/
93+
@Override public void enterDeclaration(PiccodeScriptParser.DeclarationContext ctx) { }
94+
/**
95+
* {@inheritDoc}
96+
*
97+
* <p>The default implementation does nothing.</p>
98+
*/
99+
@Override public void exitDeclaration(PiccodeScriptParser.DeclarationContext ctx) { }
88100
/**
89101
* {@inheritDoc}
90102
*

src/main/java/org/piccode/antlr4/PiccodeScriptBaseVisitor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ public class PiccodeScriptBaseVisitor<T> extends AbstractParseTreeVisitor<T> imp
5555
* {@link #visitChildren} on {@code ctx}.</p>
5656
*/
5757
@Override public T visitSymbol_entry(PiccodeScriptParser.Symbol_entryContext ctx) { return visitChildren(ctx); }
58+
/**
59+
* {@inheritDoc}
60+
*
61+
* <p>The default implementation returns the result of calling
62+
* {@link #visitChildren} on {@code ctx}.</p>
63+
*/
64+
@Override public T visitDeclaration(PiccodeScriptParser.DeclarationContext ctx) { return visitChildren(ctx); }
5865
/**
5966
* {@inheritDoc}
6067
*

src/main/java/org/piccode/antlr4/PiccodeScriptLexer.interp

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)