Compare commits
98
Commits
dev
...
6822faaaad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6822faaaad | ||
|
|
6a7e3ee1d6 | ||
|
|
befd4e979c | ||
|
|
b1e165b919 | ||
|
|
ec681eb97a | ||
|
|
01df4b4ba7 | ||
|
|
3d9a147aad | ||
|
|
9aa33cef96 | ||
|
|
ab72951088 | ||
|
|
4ed12bc3f8 | ||
|
|
b79b00e2d9 | ||
|
|
154e9597ae | ||
|
|
c502131aa7 | ||
|
|
aeec086b95 | ||
|
|
459c7f47cd | ||
|
|
fec3c39de2 | ||
|
|
370106b67d | ||
|
|
010225d8d6 | ||
|
|
5b08de7d16 | ||
|
|
ab840b36e4 | ||
|
|
7f23772ec9 | ||
|
|
74f3d36c08 | ||
|
|
607e023ca4 | ||
|
|
c48cad6817 | ||
|
|
1aab723c3f | ||
|
|
2829b8834e | ||
|
|
653cf509ba | ||
|
|
4b1fbb0cc5 | ||
|
|
3a09288a52 | ||
|
|
82bb846e09 | ||
|
|
023ada1506 | ||
|
|
9e5079151b | ||
|
|
84c69df276 | ||
|
|
573ba1f745 | ||
|
|
f4759f01c8 | ||
|
|
58af9cdd95 | ||
|
|
30ed01f5a0 | ||
|
|
0137beff70 | ||
|
|
e3ebe9d8d3 | ||
|
|
9b755b1821 | ||
|
|
3cb1ab90fd | ||
|
|
41c6b99e26 | ||
|
|
001636c799 | ||
|
|
d561682136 | ||
|
|
e9237eaf9a | ||
|
|
beff172ff4 | ||
|
|
8cbe87d59c | ||
|
|
3d694d4931 | ||
|
|
910b638458 | ||
|
|
15e0ff362c | ||
|
|
9a614ef367 | ||
|
|
1490a367c2 | ||
|
|
472ee1cb81 | ||
|
|
387b247823 | ||
|
|
1edc714213 | ||
|
|
ea7222255a | ||
|
|
3434b4c0bd | ||
|
|
a19a864965 | ||
|
|
c9a135f6d7 | ||
|
|
d9dcce3ea3 | ||
|
|
ad00c78f0c | ||
|
|
e82dae5dfc | ||
|
|
5fd9ab86bc | ||
|
|
d3b252fb28 | ||
|
|
8348c36394 | ||
|
|
ed60ab7af4 | ||
|
|
7699809a28 | ||
|
|
5d27d5b4a9 | ||
|
|
a11ca49c35 | ||
|
|
ee4b8e5891 | ||
|
|
57d99b9526 | ||
|
|
c5331279da | ||
|
|
a6a5b46a01 | ||
|
|
35653cff1f | ||
|
|
5c367e6b44 | ||
|
|
15ff863fbe | ||
|
|
0b513c49c3 | ||
|
|
e048e0e10c | ||
|
|
5fafd054b1 | ||
|
|
4cbf46da53 | ||
|
|
b3db964a8e | ||
|
|
0dd3410141 | ||
|
|
1da6b3db09 | ||
|
|
8c32610737 | ||
|
|
93ba413251 | ||
|
|
33fc1d85dc | ||
|
|
5ca3722150 | ||
|
|
ae281d70d1 | ||
|
|
a5e23db625 | ||
|
|
9dc8712364 | ||
|
|
e7142f6d80 | ||
|
|
02245401b9 | ||
|
|
9d7e560feb | ||
|
|
ff84b62d3b | ||
|
|
86bf9778ee | ||
|
|
e95990b293 | ||
|
|
2fb2d7ef76 | ||
|
|
7aae829763 |
+17
-16
@@ -1,24 +1,25 @@
|
|||||||
# Generated by Cargo
|
|
||||||
# will have compiled files and executables
|
|
||||||
debug/
|
|
||||||
target/
|
|
||||||
|
|
||||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
# Binaries for programs and plugins
|
||||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
*.exe
|
||||||
Cargo.lock
|
*.exe~
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
|
||||||
# These are backup files generated by rustfmt
|
# Test binary, built with `go test -c`
|
||||||
**/*.rs.bk
|
*.test
|
||||||
|
|
||||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
*.pdb
|
*.out
|
||||||
|
|
||||||
|
# Dependency directories (remove the comment below to include it)
|
||||||
|
# vendor/
|
||||||
|
|
||||||
# Added by cargo
|
# Go workspace file
|
||||||
/target
|
go.work
|
||||||
|
|
||||||
#MacOS
|
# Mac OS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
#Wyst files for testing
|
#vscode
|
||||||
*.wst
|
.vscode
|
||||||
|
|||||||
Generated
-8
@@ -1,8 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
||||||
Generated
-8
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/wyst.iml" filepath="$PROJECT_DIR$/.idea/wyst.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
Generated
-6
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
Generated
-11
@@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="EMPTY_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
Vendored
-6
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"rust-analyzer.linkedProjects": [
|
|
||||||
"./Cargo.toml"
|
|
||||||
],
|
|
||||||
"rust-analyzer.showUnlinkedFileNotification": false
|
|
||||||
}
|
|
||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "wyst"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
regex = "1.10.4"
|
|
||||||
once_cell = "1.19.0"
|
|
||||||
clap = { version = "4.0", features = ["derive"] }
|
|
||||||
@@ -5,7 +5,17 @@
|
|||||||
<h1 align="center">Wyst
|
<h1 align="center">Wyst
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<h3 align="center">Wyst is a programing language that has similar syntax to C and transpiles to Rust</h3>
|
<h3 align="center">Wyst is a programing language that is inspired by C and transpiles to Go</h3>
|
||||||
|
|
||||||
# Alpha
|
```c
|
||||||
We are on pure alpha. if you would like to contribute please open a new issue.
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
printf("Hello, World!");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
# For developers
|
||||||
|
|
||||||
|
If the grammar has been updated run: `antlr -Dlanguage=Go -o parser Wyst.g4`
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
grammar Wyst;
|
||||||
|
|
||||||
|
WS: [ \t\r\n]+ -> skip;
|
||||||
|
NUMBER: [1-9][0-9]* | '0';
|
||||||
|
HEX: '0x' [a-fA-F0-9]*;
|
||||||
|
IDENTIFIER: [a-zA-Z_] ([a-zA-Z0-9] | '::')*;
|
||||||
|
MATH: '+' | '-' | '*' | '/';
|
||||||
|
fragment ESC: '\\' ['"\\] ;
|
||||||
|
STRING: '"' (ESC | ~["\\])* '"';
|
||||||
|
round_def: '(' (var_def (',' var_def)* ','?)? ')';
|
||||||
|
func_def: IDENTIFIER IDENTIFIER round_def code_block;
|
||||||
|
var_def: IDENTIFIER IDENTIFIER;
|
||||||
|
var_def_set: var_def '=' expr;
|
||||||
|
asm: '%' IDENTIFIER expr (',' expr)* ';';
|
||||||
|
|
||||||
|
expr:
|
||||||
|
( NUMBER |
|
||||||
|
HEX |
|
||||||
|
IDENTIFIER |
|
||||||
|
STRING
|
||||||
|
) (MATH expr)*;
|
||||||
|
|
||||||
|
code_block: '{' ((
|
||||||
|
expr |
|
||||||
|
var_def |
|
||||||
|
var_def_set
|
||||||
|
) ';')* '}';
|
||||||
|
top: (asm|func_def)*;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
module github.com/wyst-lang/wyst
|
||||||
|
|
||||||
|
go 1.22
|
||||||
|
|
||||||
|
toolchain go1.22.6
|
||||||
|
|
||||||
|
require github.com/antlr4-go/antlr/v4 v4.13.1 // direct
|
||||||
|
|
||||||
|
require (
|
||||||
|
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
|
||||||
|
)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
github.com/antlr4-go/antlr v0.0.0-20230518091524-98b52378c522 h1:o+W7GDFUwWtVkN28CW/nhh/aCmHn6OJddUs3+8vMMjs=
|
||||||
|
github.com/antlr4-go/antlr v0.0.0-20230518091524-98b52378c522/go.mod h1:srLVvW4JLxy+tCG9Nn2l8al77mUIMCwAOLQocfLDU2w=
|
||||||
|
github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ=
|
||||||
|
github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw=
|
||||||
|
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
|
||||||
|
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
token literal names:
|
||||||
|
null
|
||||||
|
'('
|
||||||
|
','
|
||||||
|
')'
|
||||||
|
'='
|
||||||
|
'%'
|
||||||
|
';'
|
||||||
|
'{'
|
||||||
|
'}'
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
|
||||||
|
token symbolic names:
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
WS
|
||||||
|
NUMBER
|
||||||
|
HEX
|
||||||
|
IDENTIFIER
|
||||||
|
MATH
|
||||||
|
STRING
|
||||||
|
|
||||||
|
rule names:
|
||||||
|
round_def
|
||||||
|
func_def
|
||||||
|
var_def
|
||||||
|
var_def_set
|
||||||
|
asm
|
||||||
|
expr
|
||||||
|
code_block
|
||||||
|
top
|
||||||
|
|
||||||
|
|
||||||
|
atn:
|
||||||
|
[4, 1, 14, 87, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 1, 0, 1, 0, 1, 0, 1, 0, 5, 0, 21, 8, 0, 10, 0, 12, 0, 24, 9, 0, 1, 0, 3, 0, 27, 8, 0, 3, 0, 29, 8, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 5, 4, 50, 8, 4, 10, 4, 12, 4, 53, 9, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 5, 5, 60, 8, 5, 10, 5, 12, 5, 63, 9, 5, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 69, 8, 6, 1, 6, 1, 6, 5, 6, 73, 8, 6, 10, 6, 12, 6, 76, 9, 6, 1, 6, 1, 6, 1, 7, 1, 7, 5, 7, 82, 8, 7, 10, 7, 12, 7, 85, 9, 7, 1, 7, 0, 0, 8, 0, 2, 4, 6, 8, 10, 12, 14, 0, 1, 2, 0, 10, 12, 14, 14, 88, 0, 16, 1, 0, 0, 0, 2, 32, 1, 0, 0, 0, 4, 37, 1, 0, 0, 0, 6, 40, 1, 0, 0, 0, 8, 44, 1, 0, 0, 0, 10, 56, 1, 0, 0, 0, 12, 64, 1, 0, 0, 0, 14, 83, 1, 0, 0, 0, 16, 28, 5, 1, 0, 0, 17, 22, 3, 4, 2, 0, 18, 19, 5, 2, 0, 0, 19, 21, 3, 4, 2, 0, 20, 18, 1, 0, 0, 0, 21, 24, 1, 0, 0, 0, 22, 20, 1, 0, 0, 0, 22, 23, 1, 0, 0, 0, 23, 26, 1, 0, 0, 0, 24, 22, 1, 0, 0, 0, 25, 27, 5, 2, 0, 0, 26, 25, 1, 0, 0, 0, 26, 27, 1, 0, 0, 0, 27, 29, 1, 0, 0, 0, 28, 17, 1, 0, 0, 0, 28, 29, 1, 0, 0, 0, 29, 30, 1, 0, 0, 0, 30, 31, 5, 3, 0, 0, 31, 1, 1, 0, 0, 0, 32, 33, 5, 12, 0, 0, 33, 34, 5, 12, 0, 0, 34, 35, 3, 0, 0, 0, 35, 36, 3, 12, 6, 0, 36, 3, 1, 0, 0, 0, 37, 38, 5, 12, 0, 0, 38, 39, 5, 12, 0, 0, 39, 5, 1, 0, 0, 0, 40, 41, 3, 4, 2, 0, 41, 42, 5, 4, 0, 0, 42, 43, 3, 10, 5, 0, 43, 7, 1, 0, 0, 0, 44, 45, 5, 5, 0, 0, 45, 46, 5, 12, 0, 0, 46, 51, 3, 10, 5, 0, 47, 48, 5, 2, 0, 0, 48, 50, 3, 10, 5, 0, 49, 47, 1, 0, 0, 0, 50, 53, 1, 0, 0, 0, 51, 49, 1, 0, 0, 0, 51, 52, 1, 0, 0, 0, 52, 54, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 54, 55, 5, 6, 0, 0, 55, 9, 1, 0, 0, 0, 56, 61, 7, 0, 0, 0, 57, 58, 5, 13, 0, 0, 58, 60, 3, 10, 5, 0, 59, 57, 1, 0, 0, 0, 60, 63, 1, 0, 0, 0, 61, 59, 1, 0, 0, 0, 61, 62, 1, 0, 0, 0, 62, 11, 1, 0, 0, 0, 63, 61, 1, 0, 0, 0, 64, 74, 5, 7, 0, 0, 65, 69, 3, 10, 5, 0, 66, 69, 3, 4, 2, 0, 67, 69, 3, 6, 3, 0, 68, 65, 1, 0, 0, 0, 68, 66, 1, 0, 0, 0, 68, 67, 1, 0, 0, 0, 69, 70, 1, 0, 0, 0, 70, 71, 5, 6, 0, 0, 71, 73, 1, 0, 0, 0, 72, 68, 1, 0, 0, 0, 73, 76, 1, 0, 0, 0, 74, 72, 1, 0, 0, 0, 74, 75, 1, 0, 0, 0, 75, 77, 1, 0, 0, 0, 76, 74, 1, 0, 0, 0, 77, 78, 5, 8, 0, 0, 78, 13, 1, 0, 0, 0, 79, 82, 3, 8, 4, 0, 80, 82, 3, 2, 1, 0, 81, 79, 1, 0, 0, 0, 81, 80, 1, 0, 0, 0, 82, 85, 1, 0, 0, 0, 83, 81, 1, 0, 0, 0, 83, 84, 1, 0, 0, 0, 84, 15, 1, 0, 0, 0, 85, 83, 1, 0, 0, 0, 9, 22, 26, 28, 51, 61, 68, 74, 81, 83]
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
T__0=1
|
||||||
|
T__1=2
|
||||||
|
T__2=3
|
||||||
|
T__3=4
|
||||||
|
T__4=5
|
||||||
|
T__5=6
|
||||||
|
T__6=7
|
||||||
|
T__7=8
|
||||||
|
WS=9
|
||||||
|
NUMBER=10
|
||||||
|
HEX=11
|
||||||
|
IDENTIFIER=12
|
||||||
|
MATH=13
|
||||||
|
STRING=14
|
||||||
|
'('=1
|
||||||
|
','=2
|
||||||
|
')'=3
|
||||||
|
'='=4
|
||||||
|
'%'=5
|
||||||
|
';'=6
|
||||||
|
'{'=7
|
||||||
|
'}'=8
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
token literal names:
|
||||||
|
null
|
||||||
|
'('
|
||||||
|
','
|
||||||
|
')'
|
||||||
|
'='
|
||||||
|
'%'
|
||||||
|
';'
|
||||||
|
'{'
|
||||||
|
'}'
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
|
||||||
|
token symbolic names:
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
WS
|
||||||
|
NUMBER
|
||||||
|
HEX
|
||||||
|
IDENTIFIER
|
||||||
|
MATH
|
||||||
|
STRING
|
||||||
|
|
||||||
|
rule names:
|
||||||
|
T__0
|
||||||
|
T__1
|
||||||
|
T__2
|
||||||
|
T__3
|
||||||
|
T__4
|
||||||
|
T__5
|
||||||
|
T__6
|
||||||
|
T__7
|
||||||
|
WS
|
||||||
|
NUMBER
|
||||||
|
HEX
|
||||||
|
IDENTIFIER
|
||||||
|
MATH
|
||||||
|
ESC
|
||||||
|
STRING
|
||||||
|
|
||||||
|
channel names:
|
||||||
|
DEFAULT_TOKEN_CHANNEL
|
||||||
|
HIDDEN
|
||||||
|
|
||||||
|
mode names:
|
||||||
|
DEFAULT_MODE
|
||||||
|
|
||||||
|
atn:
|
||||||
|
[4, 0, 14, 97, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 4, 8, 49, 8, 8, 11, 8, 12, 8, 50, 1, 8, 1, 8, 1, 9, 1, 9, 5, 9, 57, 8, 9, 10, 9, 12, 9, 60, 9, 9, 1, 9, 3, 9, 63, 8, 9, 1, 10, 1, 10, 1, 10, 1, 10, 5, 10, 69, 8, 10, 10, 10, 12, 10, 72, 9, 10, 1, 11, 1, 11, 1, 11, 1, 11, 5, 11, 78, 8, 11, 10, 11, 12, 11, 81, 9, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 5, 14, 91, 8, 14, 10, 14, 12, 14, 94, 9, 14, 1, 14, 1, 14, 0, 0, 15, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 0, 29, 14, 1, 0, 9, 3, 0, 9, 10, 13, 13, 32, 32, 1, 0, 49, 57, 1, 0, 48, 57, 3, 0, 48, 57, 65, 70, 97, 102, 3, 0, 65, 90, 95, 95, 97, 122, 3, 0, 48, 57, 65, 90, 97, 122, 3, 0, 42, 43, 45, 45, 47, 47, 3, 0, 34, 34, 39, 39, 92, 92, 2, 0, 34, 34, 92, 92, 103, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 1, 31, 1, 0, 0, 0, 3, 33, 1, 0, 0, 0, 5, 35, 1, 0, 0, 0, 7, 37, 1, 0, 0, 0, 9, 39, 1, 0, 0, 0, 11, 41, 1, 0, 0, 0, 13, 43, 1, 0, 0, 0, 15, 45, 1, 0, 0, 0, 17, 48, 1, 0, 0, 0, 19, 62, 1, 0, 0, 0, 21, 64, 1, 0, 0, 0, 23, 73, 1, 0, 0, 0, 25, 82, 1, 0, 0, 0, 27, 84, 1, 0, 0, 0, 29, 87, 1, 0, 0, 0, 31, 32, 5, 40, 0, 0, 32, 2, 1, 0, 0, 0, 33, 34, 5, 44, 0, 0, 34, 4, 1, 0, 0, 0, 35, 36, 5, 41, 0, 0, 36, 6, 1, 0, 0, 0, 37, 38, 5, 61, 0, 0, 38, 8, 1, 0, 0, 0, 39, 40, 5, 37, 0, 0, 40, 10, 1, 0, 0, 0, 41, 42, 5, 59, 0, 0, 42, 12, 1, 0, 0, 0, 43, 44, 5, 123, 0, 0, 44, 14, 1, 0, 0, 0, 45, 46, 5, 125, 0, 0, 46, 16, 1, 0, 0, 0, 47, 49, 7, 0, 0, 0, 48, 47, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 50, 51, 1, 0, 0, 0, 51, 52, 1, 0, 0, 0, 52, 53, 6, 8, 0, 0, 53, 18, 1, 0, 0, 0, 54, 58, 7, 1, 0, 0, 55, 57, 7, 2, 0, 0, 56, 55, 1, 0, 0, 0, 57, 60, 1, 0, 0, 0, 58, 56, 1, 0, 0, 0, 58, 59, 1, 0, 0, 0, 59, 63, 1, 0, 0, 0, 60, 58, 1, 0, 0, 0, 61, 63, 5, 48, 0, 0, 62, 54, 1, 0, 0, 0, 62, 61, 1, 0, 0, 0, 63, 20, 1, 0, 0, 0, 64, 65, 5, 48, 0, 0, 65, 66, 5, 120, 0, 0, 66, 70, 1, 0, 0, 0, 67, 69, 7, 3, 0, 0, 68, 67, 1, 0, 0, 0, 69, 72, 1, 0, 0, 0, 70, 68, 1, 0, 0, 0, 70, 71, 1, 0, 0, 0, 71, 22, 1, 0, 0, 0, 72, 70, 1, 0, 0, 0, 73, 79, 7, 4, 0, 0, 74, 78, 7, 5, 0, 0, 75, 76, 5, 58, 0, 0, 76, 78, 5, 58, 0, 0, 77, 74, 1, 0, 0, 0, 77, 75, 1, 0, 0, 0, 78, 81, 1, 0, 0, 0, 79, 77, 1, 0, 0, 0, 79, 80, 1, 0, 0, 0, 80, 24, 1, 0, 0, 0, 81, 79, 1, 0, 0, 0, 82, 83, 7, 6, 0, 0, 83, 26, 1, 0, 0, 0, 84, 85, 5, 92, 0, 0, 85, 86, 7, 7, 0, 0, 86, 28, 1, 0, 0, 0, 87, 92, 5, 34, 0, 0, 88, 91, 3, 27, 13, 0, 89, 91, 8, 8, 0, 0, 90, 88, 1, 0, 0, 0, 90, 89, 1, 0, 0, 0, 91, 94, 1, 0, 0, 0, 92, 90, 1, 0, 0, 0, 92, 93, 1, 0, 0, 0, 93, 95, 1, 0, 0, 0, 94, 92, 1, 0, 0, 0, 95, 96, 5, 34, 0, 0, 96, 30, 1, 0, 0, 0, 9, 0, 50, 58, 62, 70, 77, 79, 90, 92, 1, 6, 0, 0]
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
T__0=1
|
||||||
|
T__1=2
|
||||||
|
T__2=3
|
||||||
|
T__3=4
|
||||||
|
T__4=5
|
||||||
|
T__5=6
|
||||||
|
T__6=7
|
||||||
|
T__7=8
|
||||||
|
WS=9
|
||||||
|
NUMBER=10
|
||||||
|
HEX=11
|
||||||
|
IDENTIFIER=12
|
||||||
|
MATH=13
|
||||||
|
STRING=14
|
||||||
|
'('=1
|
||||||
|
','=2
|
||||||
|
')'=3
|
||||||
|
'='=4
|
||||||
|
'%'=5
|
||||||
|
';'=6
|
||||||
|
'{'=7
|
||||||
|
'}'=8
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
// Code generated from Wyst.g4 by ANTLR 4.13.2. DO NOT EDIT.
|
||||||
|
|
||||||
|
package parser // Wyst
|
||||||
|
|
||||||
|
import "github.com/antlr4-go/antlr/v4"
|
||||||
|
|
||||||
|
// BaseWystListener is a complete listener for a parse tree produced by WystParser.
|
||||||
|
type BaseWystListener struct{}
|
||||||
|
|
||||||
|
var _ WystListener = &BaseWystListener{}
|
||||||
|
|
||||||
|
// VisitTerminal is called when a terminal node is visited.
|
||||||
|
func (s *BaseWystListener) VisitTerminal(node antlr.TerminalNode) {}
|
||||||
|
|
||||||
|
// VisitErrorNode is called when an error node is visited.
|
||||||
|
func (s *BaseWystListener) VisitErrorNode(node antlr.ErrorNode) {}
|
||||||
|
|
||||||
|
// EnterEveryRule is called when any rule is entered.
|
||||||
|
func (s *BaseWystListener) EnterEveryRule(ctx antlr.ParserRuleContext) {}
|
||||||
|
|
||||||
|
// ExitEveryRule is called when any rule is exited.
|
||||||
|
func (s *BaseWystListener) ExitEveryRule(ctx antlr.ParserRuleContext) {}
|
||||||
|
|
||||||
|
// EnterRound_def is called when production round_def is entered.
|
||||||
|
func (s *BaseWystListener) EnterRound_def(ctx *Round_defContext) {}
|
||||||
|
|
||||||
|
// ExitRound_def is called when production round_def is exited.
|
||||||
|
func (s *BaseWystListener) ExitRound_def(ctx *Round_defContext) {}
|
||||||
|
|
||||||
|
// EnterFunc_def is called when production func_def is entered.
|
||||||
|
func (s *BaseWystListener) EnterFunc_def(ctx *Func_defContext) {}
|
||||||
|
|
||||||
|
// ExitFunc_def is called when production func_def is exited.
|
||||||
|
func (s *BaseWystListener) ExitFunc_def(ctx *Func_defContext) {}
|
||||||
|
|
||||||
|
// EnterVar_def is called when production var_def is entered.
|
||||||
|
func (s *BaseWystListener) EnterVar_def(ctx *Var_defContext) {}
|
||||||
|
|
||||||
|
// ExitVar_def is called when production var_def is exited.
|
||||||
|
func (s *BaseWystListener) ExitVar_def(ctx *Var_defContext) {}
|
||||||
|
|
||||||
|
// EnterVar_def_set is called when production var_def_set is entered.
|
||||||
|
func (s *BaseWystListener) EnterVar_def_set(ctx *Var_def_setContext) {}
|
||||||
|
|
||||||
|
// ExitVar_def_set is called when production var_def_set is exited.
|
||||||
|
func (s *BaseWystListener) ExitVar_def_set(ctx *Var_def_setContext) {}
|
||||||
|
|
||||||
|
// EnterAsm is called when production asm is entered.
|
||||||
|
func (s *BaseWystListener) EnterAsm(ctx *AsmContext) {}
|
||||||
|
|
||||||
|
// ExitAsm is called when production asm is exited.
|
||||||
|
func (s *BaseWystListener) ExitAsm(ctx *AsmContext) {}
|
||||||
|
|
||||||
|
// EnterExpr is called when production expr is entered.
|
||||||
|
func (s *BaseWystListener) EnterExpr(ctx *ExprContext) {}
|
||||||
|
|
||||||
|
// ExitExpr is called when production expr is exited.
|
||||||
|
func (s *BaseWystListener) ExitExpr(ctx *ExprContext) {}
|
||||||
|
|
||||||
|
// EnterCode_block is called when production code_block is entered.
|
||||||
|
func (s *BaseWystListener) EnterCode_block(ctx *Code_blockContext) {}
|
||||||
|
|
||||||
|
// ExitCode_block is called when production code_block is exited.
|
||||||
|
func (s *BaseWystListener) ExitCode_block(ctx *Code_blockContext) {}
|
||||||
|
|
||||||
|
// EnterTop is called when production top is entered.
|
||||||
|
func (s *BaseWystListener) EnterTop(ctx *TopContext) {}
|
||||||
|
|
||||||
|
// ExitTop is called when production top is exited.
|
||||||
|
func (s *BaseWystListener) ExitTop(ctx *TopContext) {}
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
// Code generated from Wyst.g4 by ANTLR 4.13.2. DO NOT EDIT.
|
||||||
|
|
||||||
|
package parser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/antlr4-go/antlr/v4"
|
||||||
|
"sync"
|
||||||
|
"unicode"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Suppress unused import error
|
||||||
|
var _ = fmt.Printf
|
||||||
|
var _ = sync.Once{}
|
||||||
|
var _ = unicode.IsLetter
|
||||||
|
|
||||||
|
type WystLexer struct {
|
||||||
|
*antlr.BaseLexer
|
||||||
|
channelNames []string
|
||||||
|
modeNames []string
|
||||||
|
// TODO: EOF string
|
||||||
|
}
|
||||||
|
|
||||||
|
var WystLexerLexerStaticData struct {
|
||||||
|
once sync.Once
|
||||||
|
serializedATN []int32
|
||||||
|
ChannelNames []string
|
||||||
|
ModeNames []string
|
||||||
|
LiteralNames []string
|
||||||
|
SymbolicNames []string
|
||||||
|
RuleNames []string
|
||||||
|
PredictionContextCache *antlr.PredictionContextCache
|
||||||
|
atn *antlr.ATN
|
||||||
|
decisionToDFA []*antlr.DFA
|
||||||
|
}
|
||||||
|
|
||||||
|
func wystlexerLexerInit() {
|
||||||
|
staticData := &WystLexerLexerStaticData
|
||||||
|
staticData.ChannelNames = []string{
|
||||||
|
"DEFAULT_TOKEN_CHANNEL", "HIDDEN",
|
||||||
|
}
|
||||||
|
staticData.ModeNames = []string{
|
||||||
|
"DEFAULT_MODE",
|
||||||
|
}
|
||||||
|
staticData.LiteralNames = []string{
|
||||||
|
"", "'('", "','", "')'", "'='", "'%'", "';'", "'{'", "'}'",
|
||||||
|
}
|
||||||
|
staticData.SymbolicNames = []string{
|
||||||
|
"", "", "", "", "", "", "", "", "", "WS", "NUMBER", "HEX", "IDENTIFIER",
|
||||||
|
"MATH", "STRING",
|
||||||
|
}
|
||||||
|
staticData.RuleNames = []string{
|
||||||
|
"T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "WS",
|
||||||
|
"NUMBER", "HEX", "IDENTIFIER", "MATH", "ESC", "STRING",
|
||||||
|
}
|
||||||
|
staticData.PredictionContextCache = antlr.NewPredictionContextCache()
|
||||||
|
staticData.serializedATN = []int32{
|
||||||
|
4, 0, 14, 97, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2,
|
||||||
|
4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2,
|
||||||
|
10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 1, 0,
|
||||||
|
1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6,
|
||||||
|
1, 6, 1, 7, 1, 7, 1, 8, 4, 8, 49, 8, 8, 11, 8, 12, 8, 50, 1, 8, 1, 8, 1,
|
||||||
|
9, 1, 9, 5, 9, 57, 8, 9, 10, 9, 12, 9, 60, 9, 9, 1, 9, 3, 9, 63, 8, 9,
|
||||||
|
1, 10, 1, 10, 1, 10, 1, 10, 5, 10, 69, 8, 10, 10, 10, 12, 10, 72, 9, 10,
|
||||||
|
1, 11, 1, 11, 1, 11, 1, 11, 5, 11, 78, 8, 11, 10, 11, 12, 11, 81, 9, 11,
|
||||||
|
1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 5, 14, 91, 8, 14,
|
||||||
|
10, 14, 12, 14, 94, 9, 14, 1, 14, 1, 14, 0, 0, 15, 1, 1, 3, 2, 5, 3, 7,
|
||||||
|
4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27,
|
||||||
|
0, 29, 14, 1, 0, 9, 3, 0, 9, 10, 13, 13, 32, 32, 1, 0, 49, 57, 1, 0, 48,
|
||||||
|
57, 3, 0, 48, 57, 65, 70, 97, 102, 3, 0, 65, 90, 95, 95, 97, 122, 3, 0,
|
||||||
|
48, 57, 65, 90, 97, 122, 3, 0, 42, 43, 45, 45, 47, 47, 3, 0, 34, 34, 39,
|
||||||
|
39, 92, 92, 2, 0, 34, 34, 92, 92, 103, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0,
|
||||||
|
0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0,
|
||||||
|
0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0,
|
||||||
|
0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 29, 1,
|
||||||
|
0, 0, 0, 1, 31, 1, 0, 0, 0, 3, 33, 1, 0, 0, 0, 5, 35, 1, 0, 0, 0, 7, 37,
|
||||||
|
1, 0, 0, 0, 9, 39, 1, 0, 0, 0, 11, 41, 1, 0, 0, 0, 13, 43, 1, 0, 0, 0,
|
||||||
|
15, 45, 1, 0, 0, 0, 17, 48, 1, 0, 0, 0, 19, 62, 1, 0, 0, 0, 21, 64, 1,
|
||||||
|
0, 0, 0, 23, 73, 1, 0, 0, 0, 25, 82, 1, 0, 0, 0, 27, 84, 1, 0, 0, 0, 29,
|
||||||
|
87, 1, 0, 0, 0, 31, 32, 5, 40, 0, 0, 32, 2, 1, 0, 0, 0, 33, 34, 5, 44,
|
||||||
|
0, 0, 34, 4, 1, 0, 0, 0, 35, 36, 5, 41, 0, 0, 36, 6, 1, 0, 0, 0, 37, 38,
|
||||||
|
5, 61, 0, 0, 38, 8, 1, 0, 0, 0, 39, 40, 5, 37, 0, 0, 40, 10, 1, 0, 0, 0,
|
||||||
|
41, 42, 5, 59, 0, 0, 42, 12, 1, 0, 0, 0, 43, 44, 5, 123, 0, 0, 44, 14,
|
||||||
|
1, 0, 0, 0, 45, 46, 5, 125, 0, 0, 46, 16, 1, 0, 0, 0, 47, 49, 7, 0, 0,
|
||||||
|
0, 48, 47, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 50, 51,
|
||||||
|
1, 0, 0, 0, 51, 52, 1, 0, 0, 0, 52, 53, 6, 8, 0, 0, 53, 18, 1, 0, 0, 0,
|
||||||
|
54, 58, 7, 1, 0, 0, 55, 57, 7, 2, 0, 0, 56, 55, 1, 0, 0, 0, 57, 60, 1,
|
||||||
|
0, 0, 0, 58, 56, 1, 0, 0, 0, 58, 59, 1, 0, 0, 0, 59, 63, 1, 0, 0, 0, 60,
|
||||||
|
58, 1, 0, 0, 0, 61, 63, 5, 48, 0, 0, 62, 54, 1, 0, 0, 0, 62, 61, 1, 0,
|
||||||
|
0, 0, 63, 20, 1, 0, 0, 0, 64, 65, 5, 48, 0, 0, 65, 66, 5, 120, 0, 0, 66,
|
||||||
|
70, 1, 0, 0, 0, 67, 69, 7, 3, 0, 0, 68, 67, 1, 0, 0, 0, 69, 72, 1, 0, 0,
|
||||||
|
0, 70, 68, 1, 0, 0, 0, 70, 71, 1, 0, 0, 0, 71, 22, 1, 0, 0, 0, 72, 70,
|
||||||
|
1, 0, 0, 0, 73, 79, 7, 4, 0, 0, 74, 78, 7, 5, 0, 0, 75, 76, 5, 58, 0, 0,
|
||||||
|
76, 78, 5, 58, 0, 0, 77, 74, 1, 0, 0, 0, 77, 75, 1, 0, 0, 0, 78, 81, 1,
|
||||||
|
0, 0, 0, 79, 77, 1, 0, 0, 0, 79, 80, 1, 0, 0, 0, 80, 24, 1, 0, 0, 0, 81,
|
||||||
|
79, 1, 0, 0, 0, 82, 83, 7, 6, 0, 0, 83, 26, 1, 0, 0, 0, 84, 85, 5, 92,
|
||||||
|
0, 0, 85, 86, 7, 7, 0, 0, 86, 28, 1, 0, 0, 0, 87, 92, 5, 34, 0, 0, 88,
|
||||||
|
91, 3, 27, 13, 0, 89, 91, 8, 8, 0, 0, 90, 88, 1, 0, 0, 0, 90, 89, 1, 0,
|
||||||
|
0, 0, 91, 94, 1, 0, 0, 0, 92, 90, 1, 0, 0, 0, 92, 93, 1, 0, 0, 0, 93, 95,
|
||||||
|
1, 0, 0, 0, 94, 92, 1, 0, 0, 0, 95, 96, 5, 34, 0, 0, 96, 30, 1, 0, 0, 0,
|
||||||
|
9, 0, 50, 58, 62, 70, 77, 79, 90, 92, 1, 6, 0, 0,
|
||||||
|
}
|
||||||
|
deserializer := antlr.NewATNDeserializer(nil)
|
||||||
|
staticData.atn = deserializer.Deserialize(staticData.serializedATN)
|
||||||
|
atn := staticData.atn
|
||||||
|
staticData.decisionToDFA = make([]*antlr.DFA, len(atn.DecisionToState))
|
||||||
|
decisionToDFA := staticData.decisionToDFA
|
||||||
|
for index, state := range atn.DecisionToState {
|
||||||
|
decisionToDFA[index] = antlr.NewDFA(state, index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WystLexerInit initializes any static state used to implement WystLexer. By default the
|
||||||
|
// static state used to implement the lexer is lazily initialized during the first call to
|
||||||
|
// NewWystLexer(). You can call this function if you wish to initialize the static state ahead
|
||||||
|
// of time.
|
||||||
|
func WystLexerInit() {
|
||||||
|
staticData := &WystLexerLexerStaticData
|
||||||
|
staticData.once.Do(wystlexerLexerInit)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewWystLexer produces a new lexer instance for the optional input antlr.CharStream.
|
||||||
|
func NewWystLexer(input antlr.CharStream) *WystLexer {
|
||||||
|
WystLexerInit()
|
||||||
|
l := new(WystLexer)
|
||||||
|
l.BaseLexer = antlr.NewBaseLexer(input)
|
||||||
|
staticData := &WystLexerLexerStaticData
|
||||||
|
l.Interpreter = antlr.NewLexerATNSimulator(l, staticData.atn, staticData.decisionToDFA, staticData.PredictionContextCache)
|
||||||
|
l.channelNames = staticData.ChannelNames
|
||||||
|
l.modeNames = staticData.ModeNames
|
||||||
|
l.RuleNames = staticData.RuleNames
|
||||||
|
l.LiteralNames = staticData.LiteralNames
|
||||||
|
l.SymbolicNames = staticData.SymbolicNames
|
||||||
|
l.GrammarFileName = "Wyst.g4"
|
||||||
|
// TODO: l.EOF = antlr.TokenEOF
|
||||||
|
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
|
||||||
|
// WystLexer tokens.
|
||||||
|
const (
|
||||||
|
WystLexerT__0 = 1
|
||||||
|
WystLexerT__1 = 2
|
||||||
|
WystLexerT__2 = 3
|
||||||
|
WystLexerT__3 = 4
|
||||||
|
WystLexerT__4 = 5
|
||||||
|
WystLexerT__5 = 6
|
||||||
|
WystLexerT__6 = 7
|
||||||
|
WystLexerT__7 = 8
|
||||||
|
WystLexerWS = 9
|
||||||
|
WystLexerNUMBER = 10
|
||||||
|
WystLexerHEX = 11
|
||||||
|
WystLexerIDENTIFIER = 12
|
||||||
|
WystLexerMATH = 13
|
||||||
|
WystLexerSTRING = 14
|
||||||
|
)
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
// Code generated from Wyst.g4 by ANTLR 4.13.2. DO NOT EDIT.
|
||||||
|
|
||||||
|
package parser // Wyst
|
||||||
|
|
||||||
|
import "github.com/antlr4-go/antlr/v4"
|
||||||
|
|
||||||
|
// WystListener is a complete listener for a parse tree produced by WystParser.
|
||||||
|
type WystListener interface {
|
||||||
|
antlr.ParseTreeListener
|
||||||
|
|
||||||
|
// EnterRound_def is called when entering the round_def production.
|
||||||
|
EnterRound_def(c *Round_defContext)
|
||||||
|
|
||||||
|
// EnterFunc_def is called when entering the func_def production.
|
||||||
|
EnterFunc_def(c *Func_defContext)
|
||||||
|
|
||||||
|
// EnterVar_def is called when entering the var_def production.
|
||||||
|
EnterVar_def(c *Var_defContext)
|
||||||
|
|
||||||
|
// EnterVar_def_set is called when entering the var_def_set production.
|
||||||
|
EnterVar_def_set(c *Var_def_setContext)
|
||||||
|
|
||||||
|
// EnterAsm is called when entering the asm production.
|
||||||
|
EnterAsm(c *AsmContext)
|
||||||
|
|
||||||
|
// EnterExpr is called when entering the expr production.
|
||||||
|
EnterExpr(c *ExprContext)
|
||||||
|
|
||||||
|
// EnterCode_block is called when entering the code_block production.
|
||||||
|
EnterCode_block(c *Code_blockContext)
|
||||||
|
|
||||||
|
// EnterTop is called when entering the top production.
|
||||||
|
EnterTop(c *TopContext)
|
||||||
|
|
||||||
|
// ExitRound_def is called when exiting the round_def production.
|
||||||
|
ExitRound_def(c *Round_defContext)
|
||||||
|
|
||||||
|
// ExitFunc_def is called when exiting the func_def production.
|
||||||
|
ExitFunc_def(c *Func_defContext)
|
||||||
|
|
||||||
|
// ExitVar_def is called when exiting the var_def production.
|
||||||
|
ExitVar_def(c *Var_defContext)
|
||||||
|
|
||||||
|
// ExitVar_def_set is called when exiting the var_def_set production.
|
||||||
|
ExitVar_def_set(c *Var_def_setContext)
|
||||||
|
|
||||||
|
// ExitAsm is called when exiting the asm production.
|
||||||
|
ExitAsm(c *AsmContext)
|
||||||
|
|
||||||
|
// ExitExpr is called when exiting the expr production.
|
||||||
|
ExitExpr(c *ExprContext)
|
||||||
|
|
||||||
|
// ExitCode_block is called when exiting the code_block production.
|
||||||
|
ExitCode_block(c *Code_blockContext)
|
||||||
|
|
||||||
|
// ExitTop is called when exiting the top production.
|
||||||
|
ExitTop(c *TopContext)
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,55 +0,0 @@
|
|||||||
use std::fs;
|
|
||||||
use std::path::Path;
|
|
||||||
use std::process::Command;
|
|
||||||
use std::io::{Error, ErrorKind};
|
|
||||||
|
|
||||||
pub fn write_to_rust_file(transpiled_code: &str, file_name: &str) -> Result<(), Error> {
|
|
||||||
// Determine the file extension based on the provided file_name
|
|
||||||
let mut output_file = String::from(file_name);
|
|
||||||
if let Some(extension) = Path::new(file_name).extension() {
|
|
||||||
if let Some(ext_str) = extension.to_str() {
|
|
||||||
// Replace the existing extension with ".rs" if it's not already ".rs"
|
|
||||||
if ext_str != "rs" {
|
|
||||||
output_file.push_str(".rs");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// If no extension is provided, append ".rs" to the file_name
|
|
||||||
output_file.push_str(".rs");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the transpiled_code to the determined output file
|
|
||||||
fs::write(&output_file, transpiled_code)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn compile_to_executable(rust_file: &str, output_exe: &str) -> Result<(), Error> {
|
|
||||||
let output = Command::new("rustc")
|
|
||||||
.arg(rust_file)
|
|
||||||
.arg("-o")
|
|
||||||
.arg(output_exe)
|
|
||||||
.output()?;
|
|
||||||
|
|
||||||
// Check if compilation was successful
|
|
||||||
if output.status.success() {
|
|
||||||
println!("Compilation successful!");
|
|
||||||
} else {
|
|
||||||
if let Some(code) = output.status.code() {
|
|
||||||
eprintln!("Compilation failed with error code: {}", code);
|
|
||||||
}
|
|
||||||
if !output.stdout.is_empty() {
|
|
||||||
eprintln!("Compiler output:\n{}", String::from_utf8_lossy(&output.stdout));
|
|
||||||
}
|
|
||||||
if !output.stderr.is_empty() {
|
|
||||||
eprintln!("Compiler errors:\n{}", String::from_utf8_lossy(&output.stderr));
|
|
||||||
}
|
|
||||||
// Compilation failed, delete the temporary Rust file
|
|
||||||
if let Err(err) = fs::remove_file(rust_file) {
|
|
||||||
eprintln!("Failed to delete temporary Rust file: {}", err);
|
|
||||||
}
|
|
||||||
return Err(Error::new(ErrorKind::Other, "Compilation failed"));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
-288
@@ -1,288 +0,0 @@
|
|||||||
use regex::Regex;
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
pub struct LexerState {
|
|
||||||
pub line: usize,
|
|
||||||
pub column: usize
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define token types
|
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
|
||||||
pub enum TokenType {
|
|
||||||
Keyword,
|
|
||||||
Newline,
|
|
||||||
Whitespace,
|
|
||||||
Number,
|
|
||||||
Identifier,
|
|
||||||
Ptr,
|
|
||||||
Operator,
|
|
||||||
SecondOperator,
|
|
||||||
Semicolon,
|
|
||||||
Round,
|
|
||||||
Curly,
|
|
||||||
Square,
|
|
||||||
Include,
|
|
||||||
String,
|
|
||||||
// EOF,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Token {
|
|
||||||
pub token_type: TokenType,
|
|
||||||
pub value: String,
|
|
||||||
pub line: usize,
|
|
||||||
pub column: usize
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for Token {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "(TokenType: {:?}, TokenValue: {}, Line: {}, Column {})", self.token_type, self.value.replace("\n", "\\n"), self.line, self.column)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Token {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "(\x1b[33mTokenType:\x1b[0m \x1b[35m{:?}\x1b[0m, \x1b[33mTokenValue:\x1b[0m \x1b[32m\"{}\"\x1b[0m, \x1b[33mLine:\x1b[0m \x1b[36m{}\x1b[0m, \x1b[33mColumn:\x1b[0m \x1b[36m{}\x1b[0m)", self.token_type, self.value.replace("\n", "\\n"), self.line, self.column)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Node {
|
|
||||||
token_type: TokenType,
|
|
||||||
token_regex: Lazy<Regex>
|
|
||||||
}
|
|
||||||
|
|
||||||
const SYNTAX: [Node; 14] = [
|
|
||||||
Node {
|
|
||||||
token_type: TokenType::Semicolon,
|
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^\;").unwrap())
|
|
||||||
},
|
|
||||||
Node {
|
|
||||||
token_type: TokenType::SecondOperator,
|
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^,").unwrap())
|
|
||||||
},
|
|
||||||
Node {
|
|
||||||
token_type: TokenType::String,
|
|
||||||
token_regex: Lazy::new(|| Regex::new("^\"").unwrap())
|
|
||||||
},
|
|
||||||
Node {
|
|
||||||
token_type: TokenType::Whitespace,
|
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^\s+").unwrap())
|
|
||||||
},
|
|
||||||
Node {
|
|
||||||
token_type: TokenType::Keyword,
|
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^mut|try|catch|return|fn\b").unwrap())
|
|
||||||
},
|
|
||||||
Node {
|
|
||||||
token_type: TokenType::Identifier,
|
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^[._a-zA-Z][a-zA-Z0-9_]*(:?\s*<[._a-zA-Z][a-zA-Z0-9_<>]*>)?").unwrap())
|
|
||||||
},
|
|
||||||
Node {
|
|
||||||
token_type: TokenType::Number,
|
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^(:?.)?(:?0[x|X])?\d+(:?.\d+)?\b").unwrap())
|
|
||||||
},
|
|
||||||
Node {
|
|
||||||
token_type: TokenType::Ptr,
|
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^->").unwrap())
|
|
||||||
},
|
|
||||||
Node {
|
|
||||||
token_type: TokenType::Operator,
|
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^[|\-|\+|\*|\=|\!]").unwrap())
|
|
||||||
},
|
|
||||||
Node {
|
|
||||||
token_type: TokenType::Round,
|
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^[\(|\)]").unwrap())
|
|
||||||
},
|
|
||||||
Node {
|
|
||||||
token_type: TokenType::Curly,
|
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^[\{|\}]").unwrap())
|
|
||||||
},
|
|
||||||
Node {
|
|
||||||
token_type: TokenType::Square,
|
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^[\[|\]]").unwrap())
|
|
||||||
},
|
|
||||||
Node {
|
|
||||||
token_type: TokenType::Include,
|
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^#include *<(.*?)>").unwrap())
|
|
||||||
},
|
|
||||||
Node {
|
|
||||||
token_type: TokenType::Include,
|
|
||||||
token_regex: Lazy::new(|| Regex::new(r#"^#include *"(.*?)""#).unwrap())
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
fn get_first_char(value: &str) -> String {
|
|
||||||
value.chars().next().unwrap().to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn lex(mut code: &str, use_whitespace: bool, state: LexerState) -> Result<Vec<Token>, (LexerState, Vec<Token>)> {
|
|
||||||
let mut state = state;
|
|
||||||
let mut tokens: Vec<Token> = Vec::new();
|
|
||||||
let mut brstr: String = String::new();
|
|
||||||
let mut br_state: LexerState = LexerState { line: 0, column: 0 };
|
|
||||||
let mut brtp: Vec<u8> = Vec::new();
|
|
||||||
while !code.is_empty() {
|
|
||||||
let mut is_match = false;
|
|
||||||
let fch = get_first_char(code);
|
|
||||||
let brln = brtp.len();
|
|
||||||
match fch.as_str() {
|
|
||||||
"\"" => {
|
|
||||||
brstr += "\"";
|
|
||||||
code = code.strip_prefix(fch.as_str()).expect("");
|
|
||||||
if brln > 0 && brtp[brln-1] == 0 {
|
|
||||||
brtp.pop();
|
|
||||||
tokens.push(Token {
|
|
||||||
token_type: TokenType::String,
|
|
||||||
value: brstr.clone(),
|
|
||||||
column: br_state.column,
|
|
||||||
line: br_state.line
|
|
||||||
});
|
|
||||||
brstr = String::new();
|
|
||||||
} else if brln == 0 {
|
|
||||||
brtp.push(0);
|
|
||||||
br_state.line = state.line;
|
|
||||||
br_state.column = state.column;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"'" => {
|
|
||||||
brstr += "'";
|
|
||||||
code = code.strip_prefix(fch.as_str()).expect("");
|
|
||||||
if brln > 0 && brtp[brln-1] == 1 {
|
|
||||||
brtp.pop();
|
|
||||||
tokens.push(Token {
|
|
||||||
token_type: TokenType::String,
|
|
||||||
value: brstr.clone(),
|
|
||||||
column: br_state.column,
|
|
||||||
line: br_state.line
|
|
||||||
});
|
|
||||||
brstr = String::new();
|
|
||||||
} else if brln == 0 {
|
|
||||||
brtp.push(1);
|
|
||||||
br_state.line = state.line;
|
|
||||||
br_state.column = state.column;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"(" => {
|
|
||||||
code = code.strip_prefix(fch.as_str()).expect("");
|
|
||||||
if brln > 0 {
|
|
||||||
brstr += fch.as_str();
|
|
||||||
} else {
|
|
||||||
br_state.line = state.line;
|
|
||||||
br_state.column = state.column;
|
|
||||||
}
|
|
||||||
brtp.push(2);
|
|
||||||
}
|
|
||||||
")" => {
|
|
||||||
code = code.strip_prefix(fch.as_str()).expect("");
|
|
||||||
if brln > 0 && brtp[brln-1] == 2 {
|
|
||||||
brtp.pop();
|
|
||||||
if brln == 1 {
|
|
||||||
tokens.push(Token {
|
|
||||||
token_type: TokenType::Round,
|
|
||||||
value: brstr.clone(),
|
|
||||||
column: br_state.column,
|
|
||||||
line: br_state.line
|
|
||||||
});
|
|
||||||
brstr = String::new();
|
|
||||||
} else {brstr += fch.as_str();}
|
|
||||||
} else {brstr += fch.as_str();}
|
|
||||||
}
|
|
||||||
"{" => {
|
|
||||||
code = code.strip_prefix(fch.as_str()).expect("");
|
|
||||||
if brln > 0 {
|
|
||||||
brstr += fch.as_str();
|
|
||||||
} else {
|
|
||||||
br_state.line = state.line;
|
|
||||||
br_state.column = state.column;
|
|
||||||
}
|
|
||||||
brtp.push(3);
|
|
||||||
}
|
|
||||||
"}" => {
|
|
||||||
code = code.strip_prefix(fch.as_str()).expect("");
|
|
||||||
if brln > 0 && brtp[brln-1] == 3 {
|
|
||||||
brtp.pop();
|
|
||||||
if brln == 1 {
|
|
||||||
tokens.push(Token {
|
|
||||||
token_type: TokenType::Curly,
|
|
||||||
value: brstr.clone(),
|
|
||||||
column: br_state.column,
|
|
||||||
line: br_state.line
|
|
||||||
});
|
|
||||||
brstr = String::new();
|
|
||||||
} else {brstr += fch.as_str();}
|
|
||||||
} else {brstr += fch.as_str();}
|
|
||||||
}
|
|
||||||
"[" => {
|
|
||||||
code = code.strip_prefix(fch.as_str()).expect("");
|
|
||||||
if brln > 0 {
|
|
||||||
brstr += fch.as_str();
|
|
||||||
} else {
|
|
||||||
br_state.line = state.line;
|
|
||||||
br_state.column = state.column;
|
|
||||||
}
|
|
||||||
brtp.push(3);
|
|
||||||
}
|
|
||||||
"]" => {
|
|
||||||
code = code.strip_prefix(fch.as_str()).expect("");
|
|
||||||
if brln > 0 && brtp[brln-1] == 3 {
|
|
||||||
brtp.pop();
|
|
||||||
if brln == 1 {
|
|
||||||
tokens.push(Token {
|
|
||||||
token_type: TokenType::Square,
|
|
||||||
value: brstr.clone(),
|
|
||||||
column: br_state.column,
|
|
||||||
line: br_state.line
|
|
||||||
});
|
|
||||||
brstr = String::new();
|
|
||||||
} else {brstr += fch.as_str();}
|
|
||||||
} else {brstr += fch.as_str();}
|
|
||||||
}
|
|
||||||
"\\" => {
|
|
||||||
brstr += "\\";
|
|
||||||
code = code.strip_prefix(fch.as_str()).expect("");
|
|
||||||
if code.len() > 0 {
|
|
||||||
let sch = get_first_char(code);
|
|
||||||
code = code.strip_prefix(sch.as_str()).expect("");
|
|
||||||
brstr += &sch;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"\n" => {
|
|
||||||
code = code.strip_prefix(fch.as_str()).expect("");
|
|
||||||
if brln > 0 {
|
|
||||||
brstr += "\n";
|
|
||||||
}
|
|
||||||
state.line += 1;
|
|
||||||
state.column = 0;
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
if brln > 0 {
|
|
||||||
code = code.strip_prefix(fch.as_str()).expect("");
|
|
||||||
brstr += fch.as_str();
|
|
||||||
} else {
|
|
||||||
for s in &SYNTAX {
|
|
||||||
if let Some(caps) = s.token_regex.captures(code) {
|
|
||||||
is_match = true;
|
|
||||||
code = code.strip_prefix(&caps[0]).unwrap_or(code);
|
|
||||||
if (!use_whitespace && s.token_type!=TokenType::Whitespace) || use_whitespace {
|
|
||||||
tokens.push(Token {
|
|
||||||
token_type: s.token_type,
|
|
||||||
value: caps[0].to_string(),
|
|
||||||
line: state.line,
|
|
||||||
column: state.column
|
|
||||||
});
|
|
||||||
}
|
|
||||||
state.column += caps[0].len();
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if !is_match {
|
|
||||||
return Err((state, tokens));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(tokens)
|
|
||||||
}
|
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
content, err := os.ReadFile("test/main.wst")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error reading file:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
code := Transpile(string(content))
|
||||||
|
fmt.Printf("output:\n%s\n", code)
|
||||||
|
}
|
||||||
-55
@@ -1,55 +0,0 @@
|
|||||||
mod transpiler;
|
|
||||||
mod parser;
|
|
||||||
mod lexer;
|
|
||||||
mod compile;
|
|
||||||
use std::fs;
|
|
||||||
use clap::Parser;
|
|
||||||
use lexer::LexerState;
|
|
||||||
|
|
||||||
// Arguments for Wyst (short and long version)
|
|
||||||
#[derive(Parser)]
|
|
||||||
struct Args {
|
|
||||||
#[clap()]
|
|
||||||
file: std::path::PathBuf,
|
|
||||||
|
|
||||||
#[clap(short, long)]
|
|
||||||
rust: Option<String>,
|
|
||||||
|
|
||||||
#[clap(short, long)]
|
|
||||||
compile: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let args = Args::parse();
|
|
||||||
let file_content = fs::read_to_string(&args.file)
|
|
||||||
.expect("Error reading file");
|
|
||||||
|
|
||||||
let transpiled_code = transpiler::transpile(file_content, 0, LexerState { line: 1, column: 0 });
|
|
||||||
|
|
||||||
match args.rust {
|
|
||||||
Some(ref rust_file_name) => {
|
|
||||||
// Write transpiled code to Rust file
|
|
||||||
compile::write_to_rust_file(&transpiled_code, rust_file_name)
|
|
||||||
.expect("Error writing to Rust file");
|
|
||||||
println!("Transpiled code written to {}", rust_file_name);
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
// No Rust file specified, print transpiled code
|
|
||||||
println!("{}", transpiled_code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match args.compile {
|
|
||||||
Some(ref exe_name) => {
|
|
||||||
// Compile transpiled Rust code into executable
|
|
||||||
compile::write_to_rust_file(&transpiled_code, "temp.rs")
|
|
||||||
.expect("Error writing to temporary Rust file");
|
|
||||||
compile::compile_to_executable("temp.rs", exe_name)
|
|
||||||
.expect("Error compiling to executable");
|
|
||||||
fs::remove_file("temp.rs")
|
|
||||||
.expect("Error removing temporary Rust file");
|
|
||||||
println!("Compiled executable: {}", exe_name);
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/antlr4-go/antlr/v4"
|
||||||
|
"github.com/wyst-lang/wyst/parser"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ASTNode struct {
|
||||||
|
Rule string
|
||||||
|
Text string
|
||||||
|
Inner []ASTNode
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTokenName(tokenType int, lexer *parser.WystLexer) string {
|
||||||
|
if tokenType >= 0 && tokenType < len(lexer.SymbolicNames) {
|
||||||
|
if lexer.SymbolicNames[tokenType] != "" {
|
||||||
|
return lexer.SymbolicNames[tokenType]
|
||||||
|
}
|
||||||
|
return lexer.LiteralNames[tokenType]
|
||||||
|
}
|
||||||
|
return "UNKNOWN"
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConvertAST(node antlr.Tree, wparser *parser.WystParser, lexer *parser.WystLexer) ASTNode {
|
||||||
|
var ast = ASTNode{}
|
||||||
|
switch node := node.(type) {
|
||||||
|
case antlr.TerminalNode:
|
||||||
|
token := node.GetSymbol()
|
||||||
|
ast.Text = token.GetText()
|
||||||
|
ast.Rule = getTokenName(token.GetTokenType(), lexer)
|
||||||
|
default:
|
||||||
|
if ruleContext, ok := node.(antlr.RuleContext); ok {
|
||||||
|
ast.Rule = wparser.RuleNames[ruleContext.GetRuleIndex()]
|
||||||
|
}
|
||||||
|
if parseTree, ok := node.(antlr.ParseTree); ok {
|
||||||
|
ast.Text = parseTree.GetText()
|
||||||
|
}
|
||||||
|
for i := 0; i < node.GetChildCount(); i++ {
|
||||||
|
l := ConvertAST(node.GetChild(i), wparser, lexer)
|
||||||
|
if l.Rule != ("'"+l.Text+"'") || l.Text == ";" {
|
||||||
|
ast.Inner = append(ast.Inner, l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ast
|
||||||
|
}
|
||||||
|
|
||||||
|
func Parse(code string) ASTNode {
|
||||||
|
chars := antlr.NewInputStream(code)
|
||||||
|
lexer := parser.NewWystLexer(chars)
|
||||||
|
stream := antlr.NewCommonTokenStream(lexer, 0)
|
||||||
|
p := parser.NewWystParser(stream)
|
||||||
|
// p.AddErrorListener(antlr.NewDiagnosticErrorListener(true).WithContext(p))
|
||||||
|
tree := p.Top()
|
||||||
|
return ConvertAST(tree, p, lexer)
|
||||||
|
}
|
||||||
-120
@@ -1,120 +0,0 @@
|
|||||||
use crate::lexer::{Token, TokenType};
|
|
||||||
use std::fmt;
|
|
||||||
use regex::Regex;
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub enum AstType {
|
|
||||||
FunctionDeceleration,
|
|
||||||
VoidFunctionDeceleration,
|
|
||||||
VariableDeceleration,
|
|
||||||
MutVariableDeceleration,
|
|
||||||
Include,
|
|
||||||
IncludeLocal,
|
|
||||||
CodeBlock,
|
|
||||||
Other
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Ast {
|
|
||||||
pub tokens: Vec<Token>,
|
|
||||||
pub ast_type: AstType
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Ast {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "\x1b[36m{:?}:\x1b[0m [\n", self.ast_type)?;
|
|
||||||
for (i, token) in self.tokens.iter().enumerate() {
|
|
||||||
if i < self.tokens.len() - 1 {
|
|
||||||
write!(f, " {},\n", token)?;
|
|
||||||
} else {
|
|
||||||
write!(f, " {}\n", token)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
write!(f, "]")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for Ast {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "{:?}: [\n", self.ast_type)?;
|
|
||||||
for (i, token) in self.tokens.iter().enumerate() {
|
|
||||||
if i < self.tokens.len() - 1 {
|
|
||||||
write!(f, " {:?},\n", token)?;
|
|
||||||
} else {
|
|
||||||
write!(f, " {:?}\n", token)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
write!(f, "]")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Parser {
|
|
||||||
pub tokens: Vec<Token>,
|
|
||||||
pub index: u32,
|
|
||||||
pub include_regex: Lazy<Regex>,
|
|
||||||
pub include_regex_local: Lazy<Regex>
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Parser {
|
|
||||||
pub fn new(tokens: Vec<Token>) -> Parser {
|
|
||||||
Parser {
|
|
||||||
tokens: tokens,
|
|
||||||
index: 0,
|
|
||||||
include_regex: Lazy::new(|| Regex::new(r"^(#include *)<(.*?)>").unwrap()),
|
|
||||||
include_regex_local: Lazy::new(|| Regex::new(r#"^(#include *)"(.*?)""#).unwrap())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn next(&mut self) -> Ast {
|
|
||||||
let mut ast_res: Ast = Ast {tokens: vec![], ast_type: AstType::Other};
|
|
||||||
let index = self.index as usize;
|
|
||||||
if index == self.tokens.len() {panic!("Reached the end of tokens")}
|
|
||||||
let token = &self.tokens[index];
|
|
||||||
match token.token_type {
|
|
||||||
TokenType::Identifier => {
|
|
||||||
ast_res.tokens.push(self.tokens[index].clone());
|
|
||||||
if self.tokens.len()-index > 3 && self.tokens[index+1].token_type==TokenType::Identifier && self.tokens[index+2].token_type==TokenType::Round && self.tokens[index+3].token_type==TokenType::Curly {
|
|
||||||
ast_res.tokens.push(self.tokens[index+1].clone());
|
|
||||||
ast_res.tokens.push(self.tokens[index+2].clone());
|
|
||||||
ast_res.tokens.push(self.tokens[index+3].clone());
|
|
||||||
if token.value == "void" {
|
|
||||||
ast_res.ast_type = AstType::VoidFunctionDeceleration;
|
|
||||||
} else {
|
|
||||||
ast_res.ast_type = AstType::FunctionDeceleration;
|
|
||||||
}
|
|
||||||
self.index += 3;
|
|
||||||
} else if self.tokens.len()-index > 1 {
|
|
||||||
if token.value == "cb" && self.tokens[index+1].token_type == TokenType::Curly {
|
|
||||||
ast_res.tokens.push(self.tokens[index+1].clone());
|
|
||||||
ast_res.ast_type = AstType::CodeBlock;
|
|
||||||
self.index += 1;
|
|
||||||
} else if self.tokens[index+1].token_type==TokenType::Identifier {
|
|
||||||
ast_res.tokens.push(self.tokens[index+1].clone());
|
|
||||||
ast_res.ast_type = AstType::VariableDeceleration;
|
|
||||||
self.index += 1;
|
|
||||||
} else if self.tokens[index+1].value=="mut" && self.tokens[index+2].token_type==TokenType::Identifier {
|
|
||||||
ast_res.tokens.push(self.tokens[index+2].clone());
|
|
||||||
ast_res.ast_type = AstType::MutVariableDeceleration;
|
|
||||||
self.index += 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TokenType::Include => {
|
|
||||||
if let Some(caps) = self.include_regex.captures(&token.value) {
|
|
||||||
ast_res.tokens.push(Token {token_type: TokenType::String, value: caps[2].to_owned().to_string(), line: 0, column: 0});
|
|
||||||
ast_res.ast_type = AstType::Include;
|
|
||||||
} else if let Some(caps) = self.include_regex_local.captures(&token.value) {
|
|
||||||
ast_res.tokens.push(Token {token_type: TokenType::String, value: caps[2].to_owned().to_string(), line: 0, column: 0});
|
|
||||||
ast_res.ast_type = AstType::IncludeLocal;
|
|
||||||
} else {
|
|
||||||
ast_res.tokens.push(token.clone());
|
|
||||||
ast_res.ast_type = AstType::Include;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
ast_res.tokens.push(token.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.index += 1;
|
|
||||||
ast_res
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type wmap [2]string
|
||||||
|
|
||||||
|
var wyst_map []wmap
|
||||||
|
|
||||||
|
func TranspileToken(node ASTNode) string {
|
||||||
|
res := ""
|
||||||
|
switch node.Rule {
|
||||||
|
|
||||||
|
case "NUMBER":
|
||||||
|
res += node.Text
|
||||||
|
case "IDENTIFIER":
|
||||||
|
for _, i := range wyst_map {
|
||||||
|
if node.Text == i[0] {
|
||||||
|
return i[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res += "_0x"
|
||||||
|
for _, c := range node.Text {
|
||||||
|
if c == ':' || c == '.' {
|
||||||
|
res += string(c)
|
||||||
|
} else {
|
||||||
|
res += fmt.Sprintf("%x", c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "HEX":
|
||||||
|
res += node.Text
|
||||||
|
case "MATH":
|
||||||
|
res += node.Text
|
||||||
|
case "STRING":
|
||||||
|
res += node.Text
|
||||||
|
case "';'":
|
||||||
|
res += "\n "
|
||||||
|
default:
|
||||||
|
fmt.Printf("\x1b[33mDEV NOTICE:\x1b[0m Missing token case for '%s'\n", node.Rule)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func TranspileNode(node ASTNode) string {
|
||||||
|
res := ""
|
||||||
|
if node.Rule == strings.ToUpper(node.Rule) {
|
||||||
|
return TranspileToken(node)
|
||||||
|
}
|
||||||
|
switch node.Rule {
|
||||||
|
|
||||||
|
case "func_def":
|
||||||
|
res += fmt.Sprintf("func %s%s %s %s", TranspileNode(node.Inner[1]), TranspileNode(node.Inner[2]), TranspileNode(node.Inner[0]), TranspileNode(node.Inner[3]))
|
||||||
|
case "expr":
|
||||||
|
res += TranspileNodes(node.Inner)
|
||||||
|
case "code_block":
|
||||||
|
res += "{\n "
|
||||||
|
res += strings.TrimSuffix(TranspileNodes(node.Inner), " ")
|
||||||
|
res += "}\n"
|
||||||
|
case "var_def":
|
||||||
|
res += fmt.Sprintf("var %s %s", TranspileNode(node.Inner[1]), TranspileNode(node.Inner[0]))
|
||||||
|
case "round_def":
|
||||||
|
res += "("
|
||||||
|
res += strings.TrimSuffix(strings.ReplaceAll(TranspileNodes(node.Inner), "var ", ""), " ")
|
||||||
|
res += ")"
|
||||||
|
case "asm":
|
||||||
|
if node.Inner[0].Text == "map" && len(node.Inner) == 4 {
|
||||||
|
wyst_map = append(wyst_map, wmap{node.Inner[1].Text, node.Inner[2].Text})
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
fmt.Printf("\x1b[33mDEV NOTICE:\x1b[0m Missing case for '%s'\n", node.Rule)
|
||||||
|
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func TranspileNodes(nodes []ASTNode) string {
|
||||||
|
res := ""
|
||||||
|
for i := 0; i < len(nodes); i++ {
|
||||||
|
res += TranspileNode(nodes[i])
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func Transpile(code string) string {
|
||||||
|
ast := Parse(code)
|
||||||
|
res := TranspileNodes(ast.Inner)
|
||||||
|
return res
|
||||||
|
}
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
use crate::lexer::{lex, LexerState, TokenType};
|
|
||||||
use crate::parser::{Parser, AstType};
|
|
||||||
|
|
||||||
pub fn transpile(input: String, indent: u32, state: LexerState) -> String {
|
|
||||||
let mut result = String::new();
|
|
||||||
|
|
||||||
if indent == 0 {
|
|
||||||
result += "type int = i32;\n";
|
|
||||||
} else {
|
|
||||||
result += " ".repeat((indent as usize) * 2).as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
let lexer_out = lex(input.as_str(), false, state);
|
|
||||||
|
|
||||||
match lexer_out {
|
|
||||||
Ok(tokens) => {
|
|
||||||
let mut full_ast = Parser::new(tokens.clone());
|
|
||||||
|
|
||||||
while full_ast.tokens.len() > full_ast.index as usize {
|
|
||||||
let ast = full_ast.next();
|
|
||||||
println!("{ast}");
|
|
||||||
|
|
||||||
if ast.ast_type == AstType::FunctionDeceleration {
|
|
||||||
result += format!(
|
|
||||||
"fn {}({}) -> {} {}",
|
|
||||||
ast.tokens[1].value,
|
|
||||||
transpile_round(ast.tokens[2].value.clone(), LexerState {
|
|
||||||
line: ast.tokens[2].line,
|
|
||||||
column: ast.tokens[2].column
|
|
||||||
}),
|
|
||||||
ast.tokens[0].value,
|
|
||||||
transpile(
|
|
||||||
ast.tokens[3].value.clone(),
|
|
||||||
indent + 1,
|
|
||||||
LexerState {
|
|
||||||
line: ast.tokens[3].line,
|
|
||||||
column: ast.tokens[3].column
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.as_str();
|
|
||||||
} else if ast.ast_type == AstType::VoidFunctionDeceleration {
|
|
||||||
result += format!(
|
|
||||||
"fn {}({}) {}",
|
|
||||||
ast.tokens[1].value,
|
|
||||||
transpile_round(ast.tokens[2].value.clone(), LexerState {
|
|
||||||
line: ast.tokens[2].line,
|
|
||||||
column: ast.tokens[2].column
|
|
||||||
}),
|
|
||||||
transpile(
|
|
||||||
ast.tokens[3].value.clone(),
|
|
||||||
indent + 1,
|
|
||||||
LexerState {
|
|
||||||
line: ast.tokens[3].line,
|
|
||||||
column: ast.tokens[3].column
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.as_str();
|
|
||||||
} else if ast.ast_type == AstType::VariableDeceleration {
|
|
||||||
result += format!("let {}: {}", ast.tokens[1].value, ast.tokens[0].value).as_str();
|
|
||||||
} else if ast.ast_type == AstType::MutVariableDeceleration {
|
|
||||||
result += format!("let mut {}: {}", ast.tokens[1].value, ast.tokens[0].value).as_str();
|
|
||||||
} else if ast.tokens.len() == 1 && ast.tokens[0].token_type == TokenType::Round {
|
|
||||||
result += format!(
|
|
||||||
"({})",
|
|
||||||
transpile_round(ast.tokens[0].value.clone(), LexerState {
|
|
||||||
line: ast.tokens[0].line,
|
|
||||||
column: ast.tokens[0].column
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.as_str();
|
|
||||||
} else if ast.tokens.len() == 1 && ast.tokens[0].token_type == TokenType::Curly {
|
|
||||||
if ast.tokens[0].token_type == TokenType::Newline {
|
|
||||||
result += (ast.tokens[0].value.as_str().to_owned()
|
|
||||||
+ (" ".repeat((indent as usize) * 2).as_str()))
|
|
||||||
.as_str();
|
|
||||||
} else {
|
|
||||||
result += ast.tokens[0].value.as_str();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ast.tokens[0].token_type == TokenType::Newline {
|
|
||||||
result += (ast.tokens[0].value.as_str().to_owned()
|
|
||||||
+ (" ".repeat((indent as usize) * 2).as_str()))
|
|
||||||
.as_str();
|
|
||||||
} else if ast.tokens[0].token_type == TokenType::Semicolon {
|
|
||||||
result += ";\n";
|
|
||||||
result += " ".repeat((indent as usize) * 2).as_str();
|
|
||||||
} else {
|
|
||||||
result += ast.tokens[0].value.as_str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result = result.trim_end().to_string();
|
|
||||||
|
|
||||||
if indent > 0 {
|
|
||||||
result += "\n";
|
|
||||||
result += " ".repeat((indent as usize - 1) * 2).as_str();
|
|
||||||
return "{\n".to_owned() + result.as_str() + "}";
|
|
||||||
} else {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err((state, _tokens)) => {
|
|
||||||
println!("Invalid syntax at code.ws:{}:{}", state.line, state.column);
|
|
||||||
return "".to_string();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn transpile_round(input: String, state: LexerState) -> String {
|
|
||||||
let mut result = String::new();
|
|
||||||
let lexer_out = lex(input.as_str(), false, state);
|
|
||||||
|
|
||||||
match lexer_out {
|
|
||||||
Ok(tokens) => {
|
|
||||||
let mut full_ast = Parser::new(tokens.clone());
|
|
||||||
|
|
||||||
while full_ast.tokens.len() > full_ast.index as usize {
|
|
||||||
let ast = full_ast.next();
|
|
||||||
println!("{ast}");
|
|
||||||
|
|
||||||
if ast.ast_type == AstType::VariableDeceleration {
|
|
||||||
result += format!("{}: {}", ast.tokens[1].value, ast.tokens[0].value).as_str();
|
|
||||||
} else if ast.ast_type == AstType::MutVariableDeceleration {
|
|
||||||
result += format!("mut {}: {}", ast.tokens[1].value, ast.tokens[0].value).as_str();
|
|
||||||
} else if ast.tokens.len() == 1 && ast.tokens[0].token_type == TokenType::Round {
|
|
||||||
result += format!(
|
|
||||||
"({})",
|
|
||||||
transpile_round(ast.tokens[0].value.clone(), LexerState {
|
|
||||||
line: ast.tokens[0].line,
|
|
||||||
column: ast.tokens[0].column
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.as_str();
|
|
||||||
} else {
|
|
||||||
result += ast.tokens[0].value.as_str()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result = result.trim_end().to_string();
|
|
||||||
result
|
|
||||||
}
|
|
||||||
Err((state, _tokens)) => {
|
|
||||||
println!("Invalid syntax at code.ws:{}:{}", state.line, state.column);
|
|
||||||
return "".to_string();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
%map test, hi;
|
||||||
|
int main(test x) {}
|
||||||
Reference in New Issue
Block a user