Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d631cf24bd | ||
|
|
d0dd25eb89 | ||
|
|
22c66083c4 | ||
|
|
2ca95bcc03 | ||
|
|
3e776ec65f | ||
|
|
4672889a59 | ||
|
|
0da965ece3 | ||
|
|
b3ef058080 | ||
|
|
2f7cdb97cc | ||
|
|
e99549fd97 | ||
|
|
6822faaaad | ||
|
|
6a7e3ee1d6 | ||
|
|
befd4e979c | ||
|
|
b1e165b919 | ||
|
|
ec681eb97a | ||
|
|
01df4b4ba7 | ||
|
|
3d9a147aad | ||
|
|
9aa33cef96 | ||
|
|
ab72951088 | ||
|
|
4ed12bc3f8 | ||
|
|
b79b00e2d9 | ||
|
|
154e9597ae | ||
|
|
c502131aa7 | ||
|
|
aeec086b95 | ||
|
|
459c7f47cd | ||
|
|
fec3c39de2 | ||
|
|
370106b67d |
+19
-26
@@ -1,38 +1,31 @@
|
|||||||
# Generated by Cargo
|
|
||||||
# will have compiled files and executables
|
|
||||||
debug/
|
|
||||||
target/
|
|
||||||
test/
|
|
||||||
.vscode/
|
|
||||||
.idea/
|
|
||||||
|
|
||||||
# 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
|
||||||
|
|
||||||
# Mac OS
|
# Mac OS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
#Wyst files for testing
|
#vscode
|
||||||
*.wst
|
.vscode
|
||||||
|
|
||||||
|
.antlr/
|
||||||
|
|
||||||
# Wyst build output taht contains rust files
|
test/
|
||||||
/build
|
|
||||||
|
|
||||||
# Wyst compiled output
|
|
||||||
out
|
|
||||||
|
|
||||||
/log.txt
|
|
||||||
/lsp.log
|
|
||||||
|
|
||||||
|
build/
|
||||||
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
-7
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"rust-analyzer.linkedProjects": [
|
|
||||||
"./Cargo.toml"
|
|
||||||
],
|
|
||||||
"rust-analyzer.showUnlinkedFileNotification": false,
|
|
||||||
"cSpell.enabled": false
|
|
||||||
}
|
|
||||||
-20
@@ -1,20 +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]
|
|
||||||
rand = "0.8.5"
|
|
||||||
serde_json = "1.0"
|
|
||||||
serde = "1.0.203"
|
|
||||||
serde_derive = "1.0.203"
|
|
||||||
lsp-types = "0.97.0"
|
|
||||||
zip = "2.1.3"
|
|
||||||
dirs = "5.0.1"
|
|
||||||
pest = "2"
|
|
||||||
pest_derive = "2.1"
|
|
||||||
clap = "3"
|
|
||||||
hex = "0.4"
|
|
||||||
regex = "1.10.5"
|
|
||||||
@@ -5,16 +5,16 @@
|
|||||||
<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>
|
||||||
|
|
||||||
```c
|
```c
|
||||||
#include <stdio.h>
|
include io;
|
||||||
|
|
||||||
int main() {
|
void main() {
|
||||||
printf("Hello, World!");
|
printf("Hello, World!");
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
# Alpha
|
# For developers
|
||||||
We are on pure alpha. if you would like to contribute please open a new issue.
|
|
||||||
|
If the grammar has been updated run: `antlr -Dlanguage=Go -o parser Wyst.g4`
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
grammar Wyst;
|
||||||
|
|
||||||
|
COMMENT: '//' ~[\r\n]* -> skip;
|
||||||
|
MULTILINE_COMMENT: '/*' .*? '*/' -> skip;
|
||||||
|
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_]* ('::' [a-zA-Z_] [a-zA-Z0-9_]*)*;
|
||||||
|
GOIDENTIFIER: '^' [a-zA-Z_] [a-zA-Z0-9_]* ('.' [a-zA-Z_] [a-zA-Z0-9_]*)*;
|
||||||
|
MATH: '+' | '-' | '*' | '/' | '==' | '!=' | '>=' | '<=';
|
||||||
|
fragment ESC: '\\' . ;
|
||||||
|
STRING: ('"' (ESC | ~["\\])* '"') | ('\'' (ESC | ~["\\])* '\'') ;
|
||||||
|
MODULE_NAME: [a-zA-Z_] [a-zA-Z0-9_]*;
|
||||||
|
|
||||||
|
round_def: '(' (var_def (',' var_def)* ','?)? ')';
|
||||||
|
enum_curly: '{' (var_def ';')* '}';
|
||||||
|
round_call: '(' (expr (',' expr)* ','?)? ')';
|
||||||
|
fn_call: IDENTIFIER round_call;
|
||||||
|
func_def: IDENTIFIER IDENTIFIER round_def code_block;
|
||||||
|
var_def: IDENTIFIER IDENTIFIER;
|
||||||
|
var_def_set: var_def '=' expr;
|
||||||
|
call_tree: (fn_call|IDENTIFIER) ('.' (fn_call|IDENTIFIER))*;
|
||||||
|
struct_def: 'struct' IDENTIFIER enum_curly;
|
||||||
|
namespace: 'namespace' IDENTIFIER '{' (((var_def|var_def_set) ';')|func_def)* '}';
|
||||||
|
import_statement: 'include' MODULE_NAME ';';
|
||||||
|
use_statement: 'use' IDENTIFIER ';';
|
||||||
|
go_import: '%import' STRING ';';
|
||||||
|
map: '%map' IDENTIFIER ',' IDENTIFIER ';';
|
||||||
|
go_call: GOIDENTIFIER round_call;
|
||||||
|
|
||||||
|
// if else statements
|
||||||
|
if_expr: '(' expr (('&&'|'||') expr)* ')';
|
||||||
|
if_statement: 'if' if_expr code_block*;
|
||||||
|
elseif_statement: 'else' if_statement;
|
||||||
|
else_statement: 'else' code_block*;
|
||||||
|
if_tree: if_statement elseif_statement* else_statement?;
|
||||||
|
|
||||||
|
expr:
|
||||||
|
(
|
||||||
|
call_tree |
|
||||||
|
NUMBER |
|
||||||
|
HEX |
|
||||||
|
IDENTIFIER |
|
||||||
|
STRING |
|
||||||
|
go_call |
|
||||||
|
GOIDENTIFIER
|
||||||
|
) (MATH expr)*;
|
||||||
|
|
||||||
|
code_block: '{' (((
|
||||||
|
expr |
|
||||||
|
var_def |
|
||||||
|
var_def_set
|
||||||
|
) ';') | (
|
||||||
|
if_tree
|
||||||
|
))* '}';
|
||||||
|
|
||||||
|
top: (
|
||||||
|
func_def |
|
||||||
|
struct_def |
|
||||||
|
namespace |
|
||||||
|
import_statement |
|
||||||
|
use_statement |
|
||||||
|
go_import |
|
||||||
|
map
|
||||||
|
)*;
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
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 (
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
|
||||||
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
|
github.com/urfave/cli/v2 v2.27.4 // direct
|
||||||
|
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
|
||||||
|
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
|
||||||
|
|
||||||
|
)
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
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=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
|
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||||
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
|
github.com/urfave/cli/v2 v2.27.4 h1:o1owoI+02Eb+K107p27wEX9Bb8eqIoZCfLXloLUSWJ8=
|
||||||
|
github.com/urfave/cli/v2 v2.27.4/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ=
|
||||||
|
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
|
||||||
|
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
|
||||||
|
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=
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
# Wyst stdlib
|
|
||||||
|
|
||||||
## > [!NOTE]
|
|
||||||
> any changes made here should be documented before pushed to master
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#[macro_export]
|
|
||||||
|
|
||||||
macro_rules! _0x7072696e7466 {
|
|
||||||
($($arg:tt)*) => {
|
|
||||||
print!($($arg)*)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
use std::alloc::{alloc, Layout};
|
|
||||||
use std::ptr::null_mut;
|
|
||||||
|
|
||||||
// Malloc
|
|
||||||
pub fn _0x6d616c6c6f63(size: usize) -> *mut u8 {
|
|
||||||
if size == 0 {
|
|
||||||
return null_mut();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a memory layout for the requested size
|
|
||||||
let layout = Layout::from_size_align(size, std::mem::align_of::<u8>()).unwrap();
|
|
||||||
|
|
||||||
// Allocate the memory
|
|
||||||
unsafe {
|
|
||||||
let ptr = alloc(layout);
|
|
||||||
if ptr.is_null() {
|
|
||||||
// Allocation failed
|
|
||||||
null_mut()
|
|
||||||
} else {
|
|
||||||
ptr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,46 @@
|
|||||||
|
T__0=1
|
||||||
|
T__1=2
|
||||||
|
T__2=3
|
||||||
|
T__3=4
|
||||||
|
T__4=5
|
||||||
|
T__5=6
|
||||||
|
T__6=7
|
||||||
|
T__7=8
|
||||||
|
T__8=9
|
||||||
|
T__9=10
|
||||||
|
T__10=11
|
||||||
|
T__11=12
|
||||||
|
T__12=13
|
||||||
|
T__13=14
|
||||||
|
T__14=15
|
||||||
|
T__15=16
|
||||||
|
T__16=17
|
||||||
|
T__17=18
|
||||||
|
COMMENT=19
|
||||||
|
MULTILINE_COMMENT=20
|
||||||
|
WS=21
|
||||||
|
NUMBER=22
|
||||||
|
HEX=23
|
||||||
|
IDENTIFIER=24
|
||||||
|
GOIDENTIFIER=25
|
||||||
|
MATH=26
|
||||||
|
STRING=27
|
||||||
|
MODULE_NAME=28
|
||||||
|
'('=1
|
||||||
|
','=2
|
||||||
|
')'=3
|
||||||
|
'{'=4
|
||||||
|
';'=5
|
||||||
|
'}'=6
|
||||||
|
'='=7
|
||||||
|
'.'=8
|
||||||
|
'struct'=9
|
||||||
|
'namespace'=10
|
||||||
|
'include'=11
|
||||||
|
'use'=12
|
||||||
|
'%import'=13
|
||||||
|
'%map'=14
|
||||||
|
'&&'=15
|
||||||
|
'||'=16
|
||||||
|
'if'=17
|
||||||
|
'else'=18
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,46 @@
|
|||||||
|
T__0=1
|
||||||
|
T__1=2
|
||||||
|
T__2=3
|
||||||
|
T__3=4
|
||||||
|
T__4=5
|
||||||
|
T__5=6
|
||||||
|
T__6=7
|
||||||
|
T__7=8
|
||||||
|
T__8=9
|
||||||
|
T__9=10
|
||||||
|
T__10=11
|
||||||
|
T__11=12
|
||||||
|
T__12=13
|
||||||
|
T__13=14
|
||||||
|
T__14=15
|
||||||
|
T__15=16
|
||||||
|
T__16=17
|
||||||
|
T__17=18
|
||||||
|
COMMENT=19
|
||||||
|
MULTILINE_COMMENT=20
|
||||||
|
WS=21
|
||||||
|
NUMBER=22
|
||||||
|
HEX=23
|
||||||
|
IDENTIFIER=24
|
||||||
|
GOIDENTIFIER=25
|
||||||
|
MATH=26
|
||||||
|
STRING=27
|
||||||
|
MODULE_NAME=28
|
||||||
|
'('=1
|
||||||
|
','=2
|
||||||
|
')'=3
|
||||||
|
'{'=4
|
||||||
|
';'=5
|
||||||
|
'}'=6
|
||||||
|
'='=7
|
||||||
|
'.'=8
|
||||||
|
'struct'=9
|
||||||
|
'namespace'=10
|
||||||
|
'include'=11
|
||||||
|
'use'=12
|
||||||
|
'%import'=13
|
||||||
|
'%map'=14
|
||||||
|
'&&'=15
|
||||||
|
'||'=16
|
||||||
|
'if'=17
|
||||||
|
'else'=18
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
// 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) {}
|
||||||
|
|
||||||
|
// EnterEnum_curly is called when production enum_curly is entered.
|
||||||
|
func (s *BaseWystListener) EnterEnum_curly(ctx *Enum_curlyContext) {}
|
||||||
|
|
||||||
|
// ExitEnum_curly is called when production enum_curly is exited.
|
||||||
|
func (s *BaseWystListener) ExitEnum_curly(ctx *Enum_curlyContext) {}
|
||||||
|
|
||||||
|
// EnterRound_call is called when production round_call is entered.
|
||||||
|
func (s *BaseWystListener) EnterRound_call(ctx *Round_callContext) {}
|
||||||
|
|
||||||
|
// ExitRound_call is called when production round_call is exited.
|
||||||
|
func (s *BaseWystListener) ExitRound_call(ctx *Round_callContext) {}
|
||||||
|
|
||||||
|
// EnterFn_call is called when production fn_call is entered.
|
||||||
|
func (s *BaseWystListener) EnterFn_call(ctx *Fn_callContext) {}
|
||||||
|
|
||||||
|
// ExitFn_call is called when production fn_call is exited.
|
||||||
|
func (s *BaseWystListener) ExitFn_call(ctx *Fn_callContext) {}
|
||||||
|
|
||||||
|
// 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) {}
|
||||||
|
|
||||||
|
// EnterCall_tree is called when production call_tree is entered.
|
||||||
|
func (s *BaseWystListener) EnterCall_tree(ctx *Call_treeContext) {}
|
||||||
|
|
||||||
|
// ExitCall_tree is called when production call_tree is exited.
|
||||||
|
func (s *BaseWystListener) ExitCall_tree(ctx *Call_treeContext) {}
|
||||||
|
|
||||||
|
// EnterStruct_def is called when production struct_def is entered.
|
||||||
|
func (s *BaseWystListener) EnterStruct_def(ctx *Struct_defContext) {}
|
||||||
|
|
||||||
|
// ExitStruct_def is called when production struct_def is exited.
|
||||||
|
func (s *BaseWystListener) ExitStruct_def(ctx *Struct_defContext) {}
|
||||||
|
|
||||||
|
// EnterNamespace is called when production namespace is entered.
|
||||||
|
func (s *BaseWystListener) EnterNamespace(ctx *NamespaceContext) {}
|
||||||
|
|
||||||
|
// ExitNamespace is called when production namespace is exited.
|
||||||
|
func (s *BaseWystListener) ExitNamespace(ctx *NamespaceContext) {}
|
||||||
|
|
||||||
|
// EnterImport_statement is called when production import_statement is entered.
|
||||||
|
func (s *BaseWystListener) EnterImport_statement(ctx *Import_statementContext) {}
|
||||||
|
|
||||||
|
// ExitImport_statement is called when production import_statement is exited.
|
||||||
|
func (s *BaseWystListener) ExitImport_statement(ctx *Import_statementContext) {}
|
||||||
|
|
||||||
|
// EnterUse_statement is called when production use_statement is entered.
|
||||||
|
func (s *BaseWystListener) EnterUse_statement(ctx *Use_statementContext) {}
|
||||||
|
|
||||||
|
// ExitUse_statement is called when production use_statement is exited.
|
||||||
|
func (s *BaseWystListener) ExitUse_statement(ctx *Use_statementContext) {}
|
||||||
|
|
||||||
|
// EnterGo_import is called when production go_import is entered.
|
||||||
|
func (s *BaseWystListener) EnterGo_import(ctx *Go_importContext) {}
|
||||||
|
|
||||||
|
// ExitGo_import is called when production go_import is exited.
|
||||||
|
func (s *BaseWystListener) ExitGo_import(ctx *Go_importContext) {}
|
||||||
|
|
||||||
|
// EnterMap is called when production map is entered.
|
||||||
|
func (s *BaseWystListener) EnterMap(ctx *MapContext) {}
|
||||||
|
|
||||||
|
// ExitMap is called when production map is exited.
|
||||||
|
func (s *BaseWystListener) ExitMap(ctx *MapContext) {}
|
||||||
|
|
||||||
|
// EnterGo_call is called when production go_call is entered.
|
||||||
|
func (s *BaseWystListener) EnterGo_call(ctx *Go_callContext) {}
|
||||||
|
|
||||||
|
// ExitGo_call is called when production go_call is exited.
|
||||||
|
func (s *BaseWystListener) ExitGo_call(ctx *Go_callContext) {}
|
||||||
|
|
||||||
|
// EnterIf_expr is called when production if_expr is entered.
|
||||||
|
func (s *BaseWystListener) EnterIf_expr(ctx *If_exprContext) {}
|
||||||
|
|
||||||
|
// ExitIf_expr is called when production if_expr is exited.
|
||||||
|
func (s *BaseWystListener) ExitIf_expr(ctx *If_exprContext) {}
|
||||||
|
|
||||||
|
// EnterIf_statement is called when production if_statement is entered.
|
||||||
|
func (s *BaseWystListener) EnterIf_statement(ctx *If_statementContext) {}
|
||||||
|
|
||||||
|
// ExitIf_statement is called when production if_statement is exited.
|
||||||
|
func (s *BaseWystListener) ExitIf_statement(ctx *If_statementContext) {}
|
||||||
|
|
||||||
|
// EnterElseif_statement is called when production elseif_statement is entered.
|
||||||
|
func (s *BaseWystListener) EnterElseif_statement(ctx *Elseif_statementContext) {}
|
||||||
|
|
||||||
|
// ExitElseif_statement is called when production elseif_statement is exited.
|
||||||
|
func (s *BaseWystListener) ExitElseif_statement(ctx *Elseif_statementContext) {}
|
||||||
|
|
||||||
|
// EnterElse_statement is called when production else_statement is entered.
|
||||||
|
func (s *BaseWystListener) EnterElse_statement(ctx *Else_statementContext) {}
|
||||||
|
|
||||||
|
// ExitElse_statement is called when production else_statement is exited.
|
||||||
|
func (s *BaseWystListener) ExitElse_statement(ctx *Else_statementContext) {}
|
||||||
|
|
||||||
|
// EnterIf_tree is called when production if_tree is entered.
|
||||||
|
func (s *BaseWystListener) EnterIf_tree(ctx *If_treeContext) {}
|
||||||
|
|
||||||
|
// ExitIf_tree is called when production if_tree is exited.
|
||||||
|
func (s *BaseWystListener) ExitIf_tree(ctx *If_treeContext) {}
|
||||||
|
|
||||||
|
// 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,253 @@
|
|||||||
|
// 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{
|
||||||
|
"", "'('", "','", "')'", "'{'", "';'", "'}'", "'='", "'.'", "'struct'",
|
||||||
|
"'namespace'", "'include'", "'use'", "'%import'", "'%map'", "'&&'",
|
||||||
|
"'||'", "'if'", "'else'",
|
||||||
|
}
|
||||||
|
staticData.SymbolicNames = []string{
|
||||||
|
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
|
||||||
|
"", "", "COMMENT", "MULTILINE_COMMENT", "WS", "NUMBER", "HEX", "IDENTIFIER",
|
||||||
|
"GOIDENTIFIER", "MATH", "STRING", "MODULE_NAME",
|
||||||
|
}
|
||||||
|
staticData.RuleNames = []string{
|
||||||
|
"T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8",
|
||||||
|
"T__9", "T__10", "T__11", "T__12", "T__13", "T__14", "T__15", "T__16",
|
||||||
|
"T__17", "COMMENT", "MULTILINE_COMMENT", "WS", "NUMBER", "HEX", "IDENTIFIER",
|
||||||
|
"GOIDENTIFIER", "MATH", "ESC", "STRING", "MODULE_NAME",
|
||||||
|
}
|
||||||
|
staticData.PredictionContextCache = antlr.NewPredictionContextCache()
|
||||||
|
staticData.serializedATN = []int32{
|
||||||
|
4, 0, 28, 266, 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, 2, 15,
|
||||||
|
7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7,
|
||||||
|
20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25,
|
||||||
|
2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 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,
|
||||||
|
1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9,
|
||||||
|
1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10,
|
||||||
|
1, 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1,
|
||||||
|
12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14,
|
||||||
|
1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, 17, 1,
|
||||||
|
17, 1, 18, 1, 18, 1, 18, 1, 18, 5, 18, 136, 8, 18, 10, 18, 12, 18, 139,
|
||||||
|
9, 18, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1, 19, 5, 19, 147, 8, 19, 10,
|
||||||
|
19, 12, 19, 150, 9, 19, 1, 19, 1, 19, 1, 19, 1, 19, 1, 19, 1, 20, 4, 20,
|
||||||
|
158, 8, 20, 11, 20, 12, 20, 159, 1, 20, 1, 20, 1, 21, 1, 21, 5, 21, 166,
|
||||||
|
8, 21, 10, 21, 12, 21, 169, 9, 21, 1, 21, 3, 21, 172, 8, 21, 1, 22, 1,
|
||||||
|
22, 1, 22, 1, 22, 5, 22, 178, 8, 22, 10, 22, 12, 22, 181, 9, 22, 1, 23,
|
||||||
|
1, 23, 5, 23, 185, 8, 23, 10, 23, 12, 23, 188, 9, 23, 1, 23, 1, 23, 1,
|
||||||
|
23, 1, 23, 1, 23, 5, 23, 195, 8, 23, 10, 23, 12, 23, 198, 9, 23, 5, 23,
|
||||||
|
200, 8, 23, 10, 23, 12, 23, 203, 9, 23, 1, 24, 1, 24, 1, 24, 5, 24, 208,
|
||||||
|
8, 24, 10, 24, 12, 24, 211, 9, 24, 1, 24, 1, 24, 1, 24, 5, 24, 216, 8,
|
||||||
|
24, 10, 24, 12, 24, 219, 9, 24, 5, 24, 221, 8, 24, 10, 24, 12, 24, 224,
|
||||||
|
9, 24, 1, 25, 1, 25, 1, 25, 1, 25, 1, 25, 1, 25, 1, 25, 1, 25, 1, 25, 3,
|
||||||
|
25, 235, 8, 25, 1, 26, 1, 26, 1, 26, 1, 27, 1, 27, 1, 27, 5, 27, 243, 8,
|
||||||
|
27, 10, 27, 12, 27, 246, 9, 27, 1, 27, 1, 27, 1, 27, 1, 27, 5, 27, 252,
|
||||||
|
8, 27, 10, 27, 12, 27, 255, 9, 27, 1, 27, 3, 27, 258, 8, 27, 1, 28, 1,
|
||||||
|
28, 5, 28, 262, 8, 28, 10, 28, 12, 28, 265, 9, 28, 1, 148, 0, 29, 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, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41,
|
||||||
|
21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 26, 53, 0, 55, 27, 57, 28, 1, 0,
|
||||||
|
9, 2, 0, 10, 10, 13, 13, 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,
|
||||||
|
4, 0, 48, 57, 65, 90, 95, 95, 97, 122, 3, 0, 42, 43, 45, 45, 47, 47, 2,
|
||||||
|
0, 34, 34, 92, 92, 286, 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, 27, 1, 0, 0, 0, 0,
|
||||||
|
29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0,
|
||||||
|
0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0,
|
||||||
|
0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0,
|
||||||
|
0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 1, 59, 1, 0, 0, 0, 3, 61, 1,
|
||||||
|
0, 0, 0, 5, 63, 1, 0, 0, 0, 7, 65, 1, 0, 0, 0, 9, 67, 1, 0, 0, 0, 11, 69,
|
||||||
|
1, 0, 0, 0, 13, 71, 1, 0, 0, 0, 15, 73, 1, 0, 0, 0, 17, 75, 1, 0, 0, 0,
|
||||||
|
19, 82, 1, 0, 0, 0, 21, 92, 1, 0, 0, 0, 23, 100, 1, 0, 0, 0, 25, 104, 1,
|
||||||
|
0, 0, 0, 27, 112, 1, 0, 0, 0, 29, 117, 1, 0, 0, 0, 31, 120, 1, 0, 0, 0,
|
||||||
|
33, 123, 1, 0, 0, 0, 35, 126, 1, 0, 0, 0, 37, 131, 1, 0, 0, 0, 39, 142,
|
||||||
|
1, 0, 0, 0, 41, 157, 1, 0, 0, 0, 43, 171, 1, 0, 0, 0, 45, 173, 1, 0, 0,
|
||||||
|
0, 47, 182, 1, 0, 0, 0, 49, 204, 1, 0, 0, 0, 51, 234, 1, 0, 0, 0, 53, 236,
|
||||||
|
1, 0, 0, 0, 55, 257, 1, 0, 0, 0, 57, 259, 1, 0, 0, 0, 59, 60, 5, 40, 0,
|
||||||
|
0, 60, 2, 1, 0, 0, 0, 61, 62, 5, 44, 0, 0, 62, 4, 1, 0, 0, 0, 63, 64, 5,
|
||||||
|
41, 0, 0, 64, 6, 1, 0, 0, 0, 65, 66, 5, 123, 0, 0, 66, 8, 1, 0, 0, 0, 67,
|
||||||
|
68, 5, 59, 0, 0, 68, 10, 1, 0, 0, 0, 69, 70, 5, 125, 0, 0, 70, 12, 1, 0,
|
||||||
|
0, 0, 71, 72, 5, 61, 0, 0, 72, 14, 1, 0, 0, 0, 73, 74, 5, 46, 0, 0, 74,
|
||||||
|
16, 1, 0, 0, 0, 75, 76, 5, 115, 0, 0, 76, 77, 5, 116, 0, 0, 77, 78, 5,
|
||||||
|
114, 0, 0, 78, 79, 5, 117, 0, 0, 79, 80, 5, 99, 0, 0, 80, 81, 5, 116, 0,
|
||||||
|
0, 81, 18, 1, 0, 0, 0, 82, 83, 5, 110, 0, 0, 83, 84, 5, 97, 0, 0, 84, 85,
|
||||||
|
5, 109, 0, 0, 85, 86, 5, 101, 0, 0, 86, 87, 5, 115, 0, 0, 87, 88, 5, 112,
|
||||||
|
0, 0, 88, 89, 5, 97, 0, 0, 89, 90, 5, 99, 0, 0, 90, 91, 5, 101, 0, 0, 91,
|
||||||
|
20, 1, 0, 0, 0, 92, 93, 5, 105, 0, 0, 93, 94, 5, 110, 0, 0, 94, 95, 5,
|
||||||
|
99, 0, 0, 95, 96, 5, 108, 0, 0, 96, 97, 5, 117, 0, 0, 97, 98, 5, 100, 0,
|
||||||
|
0, 98, 99, 5, 101, 0, 0, 99, 22, 1, 0, 0, 0, 100, 101, 5, 117, 0, 0, 101,
|
||||||
|
102, 5, 115, 0, 0, 102, 103, 5, 101, 0, 0, 103, 24, 1, 0, 0, 0, 104, 105,
|
||||||
|
5, 37, 0, 0, 105, 106, 5, 105, 0, 0, 106, 107, 5, 109, 0, 0, 107, 108,
|
||||||
|
5, 112, 0, 0, 108, 109, 5, 111, 0, 0, 109, 110, 5, 114, 0, 0, 110, 111,
|
||||||
|
5, 116, 0, 0, 111, 26, 1, 0, 0, 0, 112, 113, 5, 37, 0, 0, 113, 114, 5,
|
||||||
|
109, 0, 0, 114, 115, 5, 97, 0, 0, 115, 116, 5, 112, 0, 0, 116, 28, 1, 0,
|
||||||
|
0, 0, 117, 118, 5, 38, 0, 0, 118, 119, 5, 38, 0, 0, 119, 30, 1, 0, 0, 0,
|
||||||
|
120, 121, 5, 124, 0, 0, 121, 122, 5, 124, 0, 0, 122, 32, 1, 0, 0, 0, 123,
|
||||||
|
124, 5, 105, 0, 0, 124, 125, 5, 102, 0, 0, 125, 34, 1, 0, 0, 0, 126, 127,
|
||||||
|
5, 101, 0, 0, 127, 128, 5, 108, 0, 0, 128, 129, 5, 115, 0, 0, 129, 130,
|
||||||
|
5, 101, 0, 0, 130, 36, 1, 0, 0, 0, 131, 132, 5, 47, 0, 0, 132, 133, 5,
|
||||||
|
47, 0, 0, 133, 137, 1, 0, 0, 0, 134, 136, 8, 0, 0, 0, 135, 134, 1, 0, 0,
|
||||||
|
0, 136, 139, 1, 0, 0, 0, 137, 135, 1, 0, 0, 0, 137, 138, 1, 0, 0, 0, 138,
|
||||||
|
140, 1, 0, 0, 0, 139, 137, 1, 0, 0, 0, 140, 141, 6, 18, 0, 0, 141, 38,
|
||||||
|
1, 0, 0, 0, 142, 143, 5, 47, 0, 0, 143, 144, 5, 42, 0, 0, 144, 148, 1,
|
||||||
|
0, 0, 0, 145, 147, 9, 0, 0, 0, 146, 145, 1, 0, 0, 0, 147, 150, 1, 0, 0,
|
||||||
|
0, 148, 149, 1, 0, 0, 0, 148, 146, 1, 0, 0, 0, 149, 151, 1, 0, 0, 0, 150,
|
||||||
|
148, 1, 0, 0, 0, 151, 152, 5, 42, 0, 0, 152, 153, 5, 47, 0, 0, 153, 154,
|
||||||
|
1, 0, 0, 0, 154, 155, 6, 19, 0, 0, 155, 40, 1, 0, 0, 0, 156, 158, 7, 1,
|
||||||
|
0, 0, 157, 156, 1, 0, 0, 0, 158, 159, 1, 0, 0, 0, 159, 157, 1, 0, 0, 0,
|
||||||
|
159, 160, 1, 0, 0, 0, 160, 161, 1, 0, 0, 0, 161, 162, 6, 20, 0, 0, 162,
|
||||||
|
42, 1, 0, 0, 0, 163, 167, 7, 2, 0, 0, 164, 166, 7, 3, 0, 0, 165, 164, 1,
|
||||||
|
0, 0, 0, 166, 169, 1, 0, 0, 0, 167, 165, 1, 0, 0, 0, 167, 168, 1, 0, 0,
|
||||||
|
0, 168, 172, 1, 0, 0, 0, 169, 167, 1, 0, 0, 0, 170, 172, 5, 48, 0, 0, 171,
|
||||||
|
163, 1, 0, 0, 0, 171, 170, 1, 0, 0, 0, 172, 44, 1, 0, 0, 0, 173, 174, 5,
|
||||||
|
48, 0, 0, 174, 175, 5, 120, 0, 0, 175, 179, 1, 0, 0, 0, 176, 178, 7, 4,
|
||||||
|
0, 0, 177, 176, 1, 0, 0, 0, 178, 181, 1, 0, 0, 0, 179, 177, 1, 0, 0, 0,
|
||||||
|
179, 180, 1, 0, 0, 0, 180, 46, 1, 0, 0, 0, 181, 179, 1, 0, 0, 0, 182, 186,
|
||||||
|
7, 5, 0, 0, 183, 185, 7, 6, 0, 0, 184, 183, 1, 0, 0, 0, 185, 188, 1, 0,
|
||||||
|
0, 0, 186, 184, 1, 0, 0, 0, 186, 187, 1, 0, 0, 0, 187, 201, 1, 0, 0, 0,
|
||||||
|
188, 186, 1, 0, 0, 0, 189, 190, 5, 58, 0, 0, 190, 191, 5, 58, 0, 0, 191,
|
||||||
|
192, 1, 0, 0, 0, 192, 196, 7, 5, 0, 0, 193, 195, 7, 6, 0, 0, 194, 193,
|
||||||
|
1, 0, 0, 0, 195, 198, 1, 0, 0, 0, 196, 194, 1, 0, 0, 0, 196, 197, 1, 0,
|
||||||
|
0, 0, 197, 200, 1, 0, 0, 0, 198, 196, 1, 0, 0, 0, 199, 189, 1, 0, 0, 0,
|
||||||
|
200, 203, 1, 0, 0, 0, 201, 199, 1, 0, 0, 0, 201, 202, 1, 0, 0, 0, 202,
|
||||||
|
48, 1, 0, 0, 0, 203, 201, 1, 0, 0, 0, 204, 205, 5, 94, 0, 0, 205, 209,
|
||||||
|
7, 5, 0, 0, 206, 208, 7, 6, 0, 0, 207, 206, 1, 0, 0, 0, 208, 211, 1, 0,
|
||||||
|
0, 0, 209, 207, 1, 0, 0, 0, 209, 210, 1, 0, 0, 0, 210, 222, 1, 0, 0, 0,
|
||||||
|
211, 209, 1, 0, 0, 0, 212, 213, 5, 46, 0, 0, 213, 217, 7, 5, 0, 0, 214,
|
||||||
|
216, 7, 6, 0, 0, 215, 214, 1, 0, 0, 0, 216, 219, 1, 0, 0, 0, 217, 215,
|
||||||
|
1, 0, 0, 0, 217, 218, 1, 0, 0, 0, 218, 221, 1, 0, 0, 0, 219, 217, 1, 0,
|
||||||
|
0, 0, 220, 212, 1, 0, 0, 0, 221, 224, 1, 0, 0, 0, 222, 220, 1, 0, 0, 0,
|
||||||
|
222, 223, 1, 0, 0, 0, 223, 50, 1, 0, 0, 0, 224, 222, 1, 0, 0, 0, 225, 235,
|
||||||
|
7, 7, 0, 0, 226, 227, 5, 61, 0, 0, 227, 235, 5, 61, 0, 0, 228, 229, 5,
|
||||||
|
33, 0, 0, 229, 235, 5, 61, 0, 0, 230, 231, 5, 62, 0, 0, 231, 235, 5, 61,
|
||||||
|
0, 0, 232, 233, 5, 60, 0, 0, 233, 235, 5, 61, 0, 0, 234, 225, 1, 0, 0,
|
||||||
|
0, 234, 226, 1, 0, 0, 0, 234, 228, 1, 0, 0, 0, 234, 230, 1, 0, 0, 0, 234,
|
||||||
|
232, 1, 0, 0, 0, 235, 52, 1, 0, 0, 0, 236, 237, 5, 92, 0, 0, 237, 238,
|
||||||
|
9, 0, 0, 0, 238, 54, 1, 0, 0, 0, 239, 244, 5, 34, 0, 0, 240, 243, 3, 53,
|
||||||
|
26, 0, 241, 243, 8, 8, 0, 0, 242, 240, 1, 0, 0, 0, 242, 241, 1, 0, 0, 0,
|
||||||
|
243, 246, 1, 0, 0, 0, 244, 242, 1, 0, 0, 0, 244, 245, 1, 0, 0, 0, 245,
|
||||||
|
247, 1, 0, 0, 0, 246, 244, 1, 0, 0, 0, 247, 258, 5, 34, 0, 0, 248, 253,
|
||||||
|
5, 39, 0, 0, 249, 252, 3, 53, 26, 0, 250, 252, 8, 8, 0, 0, 251, 249, 1,
|
||||||
|
0, 0, 0, 251, 250, 1, 0, 0, 0, 252, 255, 1, 0, 0, 0, 253, 251, 1, 0, 0,
|
||||||
|
0, 253, 254, 1, 0, 0, 0, 254, 256, 1, 0, 0, 0, 255, 253, 1, 0, 0, 0, 256,
|
||||||
|
258, 5, 39, 0, 0, 257, 239, 1, 0, 0, 0, 257, 248, 1, 0, 0, 0, 258, 56,
|
||||||
|
1, 0, 0, 0, 259, 263, 7, 5, 0, 0, 260, 262, 7, 6, 0, 0, 261, 260, 1, 0,
|
||||||
|
0, 0, 262, 265, 1, 0, 0, 0, 263, 261, 1, 0, 0, 0, 263, 264, 1, 0, 0, 0,
|
||||||
|
264, 58, 1, 0, 0, 0, 265, 263, 1, 0, 0, 0, 20, 0, 137, 148, 159, 167, 171,
|
||||||
|
179, 186, 196, 201, 209, 217, 222, 234, 242, 244, 251, 253, 257, 263, 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
|
||||||
|
WystLexerT__8 = 9
|
||||||
|
WystLexerT__9 = 10
|
||||||
|
WystLexerT__10 = 11
|
||||||
|
WystLexerT__11 = 12
|
||||||
|
WystLexerT__12 = 13
|
||||||
|
WystLexerT__13 = 14
|
||||||
|
WystLexerT__14 = 15
|
||||||
|
WystLexerT__15 = 16
|
||||||
|
WystLexerT__16 = 17
|
||||||
|
WystLexerT__17 = 18
|
||||||
|
WystLexerCOMMENT = 19
|
||||||
|
WystLexerMULTILINE_COMMENT = 20
|
||||||
|
WystLexerWS = 21
|
||||||
|
WystLexerNUMBER = 22
|
||||||
|
WystLexerHEX = 23
|
||||||
|
WystLexerIDENTIFIER = 24
|
||||||
|
WystLexerGOIDENTIFIER = 25
|
||||||
|
WystLexerMATH = 26
|
||||||
|
WystLexerSTRING = 27
|
||||||
|
WystLexerMODULE_NAME = 28
|
||||||
|
)
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
// 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)
|
||||||
|
|
||||||
|
// EnterEnum_curly is called when entering the enum_curly production.
|
||||||
|
EnterEnum_curly(c *Enum_curlyContext)
|
||||||
|
|
||||||
|
// EnterRound_call is called when entering the round_call production.
|
||||||
|
EnterRound_call(c *Round_callContext)
|
||||||
|
|
||||||
|
// EnterFn_call is called when entering the fn_call production.
|
||||||
|
EnterFn_call(c *Fn_callContext)
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
|
||||||
|
// EnterCall_tree is called when entering the call_tree production.
|
||||||
|
EnterCall_tree(c *Call_treeContext)
|
||||||
|
|
||||||
|
// EnterStruct_def is called when entering the struct_def production.
|
||||||
|
EnterStruct_def(c *Struct_defContext)
|
||||||
|
|
||||||
|
// EnterNamespace is called when entering the namespace production.
|
||||||
|
EnterNamespace(c *NamespaceContext)
|
||||||
|
|
||||||
|
// EnterImport_statement is called when entering the import_statement production.
|
||||||
|
EnterImport_statement(c *Import_statementContext)
|
||||||
|
|
||||||
|
// EnterUse_statement is called when entering the use_statement production.
|
||||||
|
EnterUse_statement(c *Use_statementContext)
|
||||||
|
|
||||||
|
// EnterGo_import is called when entering the go_import production.
|
||||||
|
EnterGo_import(c *Go_importContext)
|
||||||
|
|
||||||
|
// EnterMap is called when entering the map production.
|
||||||
|
EnterMap(c *MapContext)
|
||||||
|
|
||||||
|
// EnterGo_call is called when entering the go_call production.
|
||||||
|
EnterGo_call(c *Go_callContext)
|
||||||
|
|
||||||
|
// EnterIf_expr is called when entering the if_expr production.
|
||||||
|
EnterIf_expr(c *If_exprContext)
|
||||||
|
|
||||||
|
// EnterIf_statement is called when entering the if_statement production.
|
||||||
|
EnterIf_statement(c *If_statementContext)
|
||||||
|
|
||||||
|
// EnterElseif_statement is called when entering the elseif_statement production.
|
||||||
|
EnterElseif_statement(c *Elseif_statementContext)
|
||||||
|
|
||||||
|
// EnterElse_statement is called when entering the else_statement production.
|
||||||
|
EnterElse_statement(c *Else_statementContext)
|
||||||
|
|
||||||
|
// EnterIf_tree is called when entering the if_tree production.
|
||||||
|
EnterIf_tree(c *If_treeContext)
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
|
||||||
|
// ExitEnum_curly is called when exiting the enum_curly production.
|
||||||
|
ExitEnum_curly(c *Enum_curlyContext)
|
||||||
|
|
||||||
|
// ExitRound_call is called when exiting the round_call production.
|
||||||
|
ExitRound_call(c *Round_callContext)
|
||||||
|
|
||||||
|
// ExitFn_call is called when exiting the fn_call production.
|
||||||
|
ExitFn_call(c *Fn_callContext)
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
|
||||||
|
// ExitCall_tree is called when exiting the call_tree production.
|
||||||
|
ExitCall_tree(c *Call_treeContext)
|
||||||
|
|
||||||
|
// ExitStruct_def is called when exiting the struct_def production.
|
||||||
|
ExitStruct_def(c *Struct_defContext)
|
||||||
|
|
||||||
|
// ExitNamespace is called when exiting the namespace production.
|
||||||
|
ExitNamespace(c *NamespaceContext)
|
||||||
|
|
||||||
|
// ExitImport_statement is called when exiting the import_statement production.
|
||||||
|
ExitImport_statement(c *Import_statementContext)
|
||||||
|
|
||||||
|
// ExitUse_statement is called when exiting the use_statement production.
|
||||||
|
ExitUse_statement(c *Use_statementContext)
|
||||||
|
|
||||||
|
// ExitGo_import is called when exiting the go_import production.
|
||||||
|
ExitGo_import(c *Go_importContext)
|
||||||
|
|
||||||
|
// ExitMap is called when exiting the map production.
|
||||||
|
ExitMap(c *MapContext)
|
||||||
|
|
||||||
|
// ExitGo_call is called when exiting the go_call production.
|
||||||
|
ExitGo_call(c *Go_callContext)
|
||||||
|
|
||||||
|
// ExitIf_expr is called when exiting the if_expr production.
|
||||||
|
ExitIf_expr(c *If_exprContext)
|
||||||
|
|
||||||
|
// ExitIf_statement is called when exiting the if_statement production.
|
||||||
|
ExitIf_statement(c *If_statementContext)
|
||||||
|
|
||||||
|
// ExitElseif_statement is called when exiting the elseif_statement production.
|
||||||
|
ExitElseif_statement(c *Elseif_statementContext)
|
||||||
|
|
||||||
|
// ExitElse_statement is called when exiting the else_statement production.
|
||||||
|
ExitElse_statement(c *Else_statementContext)
|
||||||
|
|
||||||
|
// ExitIf_tree is called when exiting the if_tree production.
|
||||||
|
ExitIf_tree(c *If_treeContext)
|
||||||
|
|
||||||
|
// 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,90 +0,0 @@
|
|||||||
use std::str;
|
|
||||||
use std::{fs, path::Path, process::Command};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
transpiler::{State, Transpiler},
|
|
||||||
utils::{Problem, ProblemCap, ProblemType},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn transpile_file(input_file: String, output_file: String, is_main: bool) -> u8 {
|
|
||||||
let mut ecode: u8 = 0;
|
|
||||||
let mut trsp = Transpiler {
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
if let Ok(file_contents) = fs::read_to_string(input_file) {
|
|
||||||
let mut module_code = String::new();
|
|
||||||
let mut output_code = String::new();
|
|
||||||
match trsp.transpile_code(file_contents, 0) {
|
|
||||||
Ok(rcode) => output_code += rcode.as_str(),
|
|
||||||
Err(e) => {
|
|
||||||
ecode = 1;
|
|
||||||
println!("{e}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if is_main {
|
|
||||||
for module in trsp.clone().mod_manager.modules {
|
|
||||||
module_code += "mod ";
|
|
||||||
module_code += module.rs_mod.as_str();
|
|
||||||
module_code += ";\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output_code = format!(
|
|
||||||
"{module_code}\n{output_code}\nfn main() {}{}{}",
|
|
||||||
"{_0x",
|
|
||||||
hex::encode("main"),
|
|
||||||
"();}"
|
|
||||||
);
|
|
||||||
if let Ok(_) = fs::write(Path::new("build").join(output_file), output_code) {
|
|
||||||
trsp.problems.append(&mut trsp.mod_manager.write());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
trsp.problems.push(ProblemCap::Error(Problem {
|
|
||||||
problem_msg: "File not found".to_string(),
|
|
||||||
problem_type: ProblemType::FileNotFound,
|
|
||||||
state: State {
|
|
||||||
line: 0,
|
|
||||||
column: 0,
|
|
||||||
file: None,
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
for p in trsp.problems {
|
|
||||||
match p {
|
|
||||||
ProblemCap::Error(problem) => {
|
|
||||||
ecode = 1;
|
|
||||||
if problem.state.file == None {
|
|
||||||
println!(
|
|
||||||
"\x1b[31;1m{:?}\x1b[0;1m: {}",
|
|
||||||
problem.problem_type, problem.problem_msg,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
println!(
|
|
||||||
"\x1b[31;1mError\x1b[0;1m: {}\x1b[0m\n{}:{}: {:?}",
|
|
||||||
problem.problem_msg,
|
|
||||||
problem.state.line,
|
|
||||||
problem.state.column,
|
|
||||||
problem.problem_type,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ecode
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn compile_rust(exe_file: String) {
|
|
||||||
let output = Command::new("rustc")
|
|
||||||
.arg(Path::new("build").join("main.rs"))
|
|
||||||
.arg("-o")
|
|
||||||
.arg(exe_file.clone())
|
|
||||||
.output()
|
|
||||||
.expect("Error compiling rust: ");
|
|
||||||
if &output.stderr.len() == &0 {
|
|
||||||
println!("Compiled successfully: \x1b[34;4m{}", exe_file.clone());
|
|
||||||
} else {
|
|
||||||
println!(
|
|
||||||
"{}",
|
|
||||||
str::from_utf8(&output.stderr).expect("Error encoding stderr")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := &cli.App{
|
||||||
|
Name: "Wyst",
|
||||||
|
Version: "alpha_0.0.1",
|
||||||
|
Authors: []*cli.Author{
|
||||||
|
{Name: "Orus"},
|
||||||
|
},
|
||||||
|
Usage: "The wyst compiler",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "output",
|
||||||
|
Aliases: []string{"o"},
|
||||||
|
Usage: "Specifies the output binary file name",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
if c.NArg() < 1 {
|
||||||
|
return cli.Exit("Error: <file> argument is required.", 1)
|
||||||
|
}
|
||||||
|
file := c.Args().Get(0)
|
||||||
|
if FileExists(file) {
|
||||||
|
root := NewRoot(file)
|
||||||
|
WriteRoot(root)
|
||||||
|
cmd := exec.Command("go", "build", "-o", "../out", "./")
|
||||||
|
cmd.Dir = "./build"
|
||||||
|
|
||||||
|
output, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error:", err)
|
||||||
|
}
|
||||||
|
fmt.Println(string(output))
|
||||||
|
// os.RemoveAll(OUT_FOLDER)
|
||||||
|
} else {
|
||||||
|
return cli.Exit(fmt.Sprintf("Error: file '%s' not found.", file), 1)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := app.Run(os.Args)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
-88
@@ -1,88 +0,0 @@
|
|||||||
use std::str;
|
|
||||||
use std::thread::sleep;
|
|
||||||
use std::time::Duration;
|
|
||||||
use std::{fs, io::Read, process};
|
|
||||||
mod compiler;
|
|
||||||
mod transpiler;
|
|
||||||
mod utils;
|
|
||||||
|
|
||||||
use clap::{App, Arg};
|
|
||||||
use compiler::{compile_rust, transpile_file};
|
|
||||||
use utils::match_code;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let matches = App::new("Wyst")
|
|
||||||
.version("0.51")
|
|
||||||
.author("Orus")
|
|
||||||
.about("The wyst compiler")
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("file")
|
|
||||||
.required_unless_one(&["stdio", "hex", "logo"])
|
|
||||||
.help("Sets the input file to use"),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("output")
|
|
||||||
.short('o')
|
|
||||||
.long("output")
|
|
||||||
.takes_value(true)
|
|
||||||
.help("Specifies the output binary file name"),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("build")
|
|
||||||
.short('b')
|
|
||||||
.long("build")
|
|
||||||
.help("Puts the rust files in the build directory"),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("stdio")
|
|
||||||
.short('s')
|
|
||||||
.long("stdio")
|
|
||||||
.help("LSP Mode"),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("hex")
|
|
||||||
.short('h')
|
|
||||||
.long("hex")
|
|
||||||
.takes_value(true)
|
|
||||||
.help("Turn an identifier into hex"),
|
|
||||||
)
|
|
||||||
.arg(Arg::with_name("logo").long("logo").hide(true))
|
|
||||||
.get_matches();
|
|
||||||
if matches.is_present("logo") {
|
|
||||||
println!("{}", utils::LOGO);
|
|
||||||
let mut byte = [4; 4];
|
|
||||||
std::io::stdin().read_exact(&mut byte).unwrap();
|
|
||||||
let egg = str::from_utf8(&byte).unwrap().to_string();
|
|
||||||
let mut counter: u8 = 30;
|
|
||||||
if egg == "logo" {
|
|
||||||
loop {
|
|
||||||
if counter == 35 {
|
|
||||||
counter = 30;
|
|
||||||
}
|
|
||||||
println!("\x1B[2J\x1B[{}m{}", counter, utils::LOGO);
|
|
||||||
sleep(Duration::from_millis(400));
|
|
||||||
counter += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if matches.is_present("stdio") {
|
|
||||||
println!(
|
|
||||||
"{:?}",
|
|
||||||
match_code("void testme(int x) {}\ntest".to_string(), 1, 3).unwrap()
|
|
||||||
);
|
|
||||||
} else if matches.is_present("hex") {
|
|
||||||
let ident = matches.value_of("hex").unwrap().to_string();
|
|
||||||
println!("_0x{}", hex::encode(ident));
|
|
||||||
} else {
|
|
||||||
let file = matches.value_of("file").unwrap().to_string();
|
|
||||||
let output = matches.value_of("output").unwrap_or("out").to_string();
|
|
||||||
if let Ok(_) = fs::create_dir("build") {}
|
|
||||||
let ecode = transpile_file(file, "main.rs".to_string(), true);
|
|
||||||
if ecode == 0 {
|
|
||||||
compile_rust(output);
|
|
||||||
}
|
|
||||||
if !matches.is_present("build") {
|
|
||||||
fs::remove_dir_all("build").expect("Error removing build");
|
|
||||||
}
|
|
||||||
process::exit(ecode as i32);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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 == ";" || 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)
|
||||||
|
}
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type wmap [2]string
|
||||||
|
|
||||||
|
var wyst_map []wmap = []wmap{{"int", "int"}, {"void", "void"}, {"main", "main"}, {"string", "string"}, {"true", "true"}, {"false", "false"}}
|
||||||
|
|
||||||
|
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 += "I0x"
|
||||||
|
for _, c := range node.Text {
|
||||||
|
if c == ':' || c == '.' {
|
||||||
|
res += string(c)
|
||||||
|
} else {
|
||||||
|
res += fmt.Sprintf("%x", c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res = strings.ReplaceAll(res, "::", ".I0x")
|
||||||
|
case "HEX":
|
||||||
|
res += node.Text
|
||||||
|
case "MATH":
|
||||||
|
res += node.Text
|
||||||
|
case "STRING":
|
||||||
|
if strings.HasPrefix(node.Text, "'") {
|
||||||
|
res += "\"" + strings.ReplaceAll(strings.TrimSuffix(strings.TrimPrefix(node.Text, "'"), "'"), "\\'", "'") + "\""
|
||||||
|
} else {
|
||||||
|
res += node.Text
|
||||||
|
}
|
||||||
|
case "';'":
|
||||||
|
res += "\n "
|
||||||
|
case "','":
|
||||||
|
res += ", "
|
||||||
|
case "IDENT":
|
||||||
|
res += fmt.Sprintf("_%#x", node.Text)
|
||||||
|
case "GOIDENTIFIER":
|
||||||
|
res += strings.TrimPrefix(node.Text, "^")
|
||||||
|
default:
|
||||||
|
fmt.Printf("\x1b[33mDEV NOTICE:\x1b[0m Missing token case for '%s'\n", node.Rule)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Module) TranspileNode(node ASTNode) string {
|
||||||
|
res := ""
|
||||||
|
if node.Rule == strings.ToUpper(node.Rule) {
|
||||||
|
return TranspileToken(node)
|
||||||
|
}
|
||||||
|
switch node.Rule {
|
||||||
|
|
||||||
|
case "func_def":
|
||||||
|
return_type := m.TranspileNode(node.Inner[0])
|
||||||
|
if return_type == "void" {
|
||||||
|
return_type = ""
|
||||||
|
}
|
||||||
|
res += fmt.Sprintf("func %s%s %s %s", m.TranspileNode(node.Inner[1]), m.TranspileNode(node.Inner[2]), return_type, m.TranspileNode(node.Inner[3]))
|
||||||
|
case "expr":
|
||||||
|
res += m.TranspileNodes(node.Inner)
|
||||||
|
case "code_block":
|
||||||
|
res += fmt.Sprintf("{\n %s}", strings.TrimRight(m.TranspileNodes(node.Inner), " "))
|
||||||
|
case "var_def":
|
||||||
|
res += fmt.Sprintf("var %s %s", m.TranspileNode(node.Inner[1]), m.TranspileNode(node.Inner[0]))
|
||||||
|
case "round_def":
|
||||||
|
res += fmt.Sprintf("(%s)", strings.TrimRight(strings.ReplaceAll(m.TranspileNodes(node.Inner), "var ", ""), " "))
|
||||||
|
case "call_tree":
|
||||||
|
for i, c := range node.Inner {
|
||||||
|
res += m.TranspileNode(c)
|
||||||
|
if i+1 < len(node.Inner) {
|
||||||
|
res += "."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case "fn_call":
|
||||||
|
res += m.TranspileNode(node.Inner[0])
|
||||||
|
res += m.TranspileNode(node.Inner[1])
|
||||||
|
|
||||||
|
case "struct_def":
|
||||||
|
res += fmt.Sprintf("type %s struct %s\n", m.TranspileNode(node.Inner[0]), m.TranspileNode(node.Inner[1]))
|
||||||
|
|
||||||
|
case "enum_curly":
|
||||||
|
res += fmt.Sprintf("{\n %s}", strings.TrimRight(m.TranspileNodes(node.Inner), " "))
|
||||||
|
|
||||||
|
case "namespace":
|
||||||
|
namespace_name := "n" + m.TranspileNode(node.Inner[0])
|
||||||
|
res += fmt.Sprintf("type %s struct {\n ", namespace_name)
|
||||||
|
vals := ""
|
||||||
|
for _, c := range node.Inner {
|
||||||
|
if c.Rule == "var_def" {
|
||||||
|
res += strings.TrimPrefix(m.TranspileNode(c), "var ")
|
||||||
|
res += "\n "
|
||||||
|
} else if c.Rule == "var_def_set" {
|
||||||
|
res += strings.TrimPrefix(m.TranspileNode(c.Inner[0]), "var ")
|
||||||
|
res += "\n "
|
||||||
|
vals += fmt.Sprintf("%s: %s, ", m.TranspileNode(c.Inner[0].Inner[1]), m.TranspileNode(c.Inner[1]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res += "}\n"
|
||||||
|
for _, c := range node.Inner {
|
||||||
|
if c.Rule == "func_def" {
|
||||||
|
return_type := m.TranspileNode(c.Inner[0])
|
||||||
|
if return_type == "void" {
|
||||||
|
return_type = ""
|
||||||
|
}
|
||||||
|
res += fmt.Sprintf("func (%s) %s%s %s %s", namespace_name, m.TranspileNode(c.Inner[1]), m.TranspileNode(c.Inner[2]), return_type, m.TranspileNode(c.Inner[3]))
|
||||||
|
res += "\n "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res += fmt.Sprintf("var %s %s = %s{%s}", m.TranspileNode(node.Inner[0]), namespace_name, namespace_name, vals)
|
||||||
|
|
||||||
|
case "var_def_set":
|
||||||
|
res += fmt.Sprintf("%s = %s", m.TranspileNode(node.Inner[0]), m.TranspileNode(node.Inner[1]))
|
||||||
|
|
||||||
|
case "import_statement":
|
||||||
|
res += fmt.Sprintf("import . \"%s\"\n", m.ImportModule(node.Inner[0].Text))
|
||||||
|
|
||||||
|
case "use_statement":
|
||||||
|
ident := strings.Split(node.Inner[0].Text, "::")
|
||||||
|
ident2 := strings.Split(m.TranspileNode(node.Inner[0]), ".")
|
||||||
|
modname := m.ImportModule(ident[0])
|
||||||
|
md := strings.Split(modname, "/")
|
||||||
|
res += fmt.Sprintf("import %s \"%s\"\n", md[len(md)-1], modname)
|
||||||
|
if len(ident) > 1 {
|
||||||
|
res += fmt.Sprintf("var %s = %s\n", ident2[len(ident2)-1], m.TranspileNode(node.Inner[0]))
|
||||||
|
}
|
||||||
|
|
||||||
|
case "go_import":
|
||||||
|
res += "import " + m.TranspileNode(node.Inner[0]) + "\n"
|
||||||
|
|
||||||
|
case "map":
|
||||||
|
wyst_map = append(wyst_map, wmap{node.Inner[0].Text, node.Inner[2].Text})
|
||||||
|
|
||||||
|
case "go_call":
|
||||||
|
res += m.TranspileNode(node.Inner[0])
|
||||||
|
res += m.TranspileNode(node.Inner[1])
|
||||||
|
|
||||||
|
case "round_call":
|
||||||
|
res += "(" + m.TranspileNodes(node.Inner) + ")"
|
||||||
|
|
||||||
|
case "if_tree":
|
||||||
|
res += m.TranspileNodes(node.Inner)
|
||||||
|
|
||||||
|
case "if_statement":
|
||||||
|
res += "if " + m.TranspileNodes(node.Inner)
|
||||||
|
|
||||||
|
case "if_expr":
|
||||||
|
res += m.TranspileNodes(node.Inner)
|
||||||
|
|
||||||
|
case "else_statement":
|
||||||
|
res += "else "
|
||||||
|
res += m.TranspileNodes(node.Inner)
|
||||||
|
|
||||||
|
case "elseif_statement":
|
||||||
|
res += "else "
|
||||||
|
res += m.TranspileNodes(node.Inner)
|
||||||
|
|
||||||
|
default:
|
||||||
|
fmt.Printf("\x1b[33mDEV NOTICE:\x1b[0m Missing case for '%s'\n", node.Rule)
|
||||||
|
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Module) TranspileNodes(nodes []ASTNode) string {
|
||||||
|
res := ""
|
||||||
|
for i := 0; i < len(nodes); i++ {
|
||||||
|
res += m.TranspileNode(nodes[i])
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Module) Transpile(code string) string {
|
||||||
|
ast := Parse(code)
|
||||||
|
res := m.TranspileNodes(ast.Inner)
|
||||||
|
return res
|
||||||
|
}
|
||||||
@@ -1,436 +0,0 @@
|
|||||||
use crate::utils::{ModManager, ProblemCap};
|
|
||||||
use pest::iterators::{Pair, Pairs};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
// The Parser
|
|
||||||
use pest::{error::Error, Parser};
|
|
||||||
use pest_derive::Parser;
|
|
||||||
#[derive(Parser)]
|
|
||||||
#[grammar = "wyst.pest"]
|
|
||||||
pub struct WystParser;
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug, Clone)]
|
|
||||||
pub struct State {
|
|
||||||
pub line: u32,
|
|
||||||
pub column: u32,
|
|
||||||
pub file: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub struct Transpiler {
|
|
||||||
pub problems: Vec<ProblemCap>,
|
|
||||||
pub state: State,
|
|
||||||
pub inject: Inject,
|
|
||||||
pub mod_manager: ModManager,
|
|
||||||
}
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub struct Inject {
|
|
||||||
pub state: State,
|
|
||||||
pub inject: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Inject {
|
|
||||||
fn default() -> Self {
|
|
||||||
Inject {
|
|
||||||
inject: false,
|
|
||||||
state: State {
|
|
||||||
line: 0,
|
|
||||||
column: 0,
|
|
||||||
file: None,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Transpiler {
|
|
||||||
fn default() -> Self {
|
|
||||||
Transpiler {
|
|
||||||
inject: Inject::default(),
|
|
||||||
problems: Vec::new(),
|
|
||||||
mod_manager: ModManager::new(),
|
|
||||||
state: State {
|
|
||||||
line: 1,
|
|
||||||
column: 0,
|
|
||||||
file: None,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_indexable(pairs: Pairs<Rule>) -> Vec<Pair<Rule>> {
|
|
||||||
let mut arr: Vec<Pair<Rule>> = Vec::new();
|
|
||||||
for pair in pairs {
|
|
||||||
arr.push(pair)
|
|
||||||
}
|
|
||||||
arr
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Transpiler {
|
|
||||||
pub fn encode_ident(&mut self, ident: &str) -> String {
|
|
||||||
match WystParser::parse(Rule::def_identifier, ident) {
|
|
||||||
Ok(parsed) => {
|
|
||||||
let mut output = String::new();
|
|
||||||
for pair in parsed {
|
|
||||||
let tokens = to_indexable(pair.clone().into_inner());
|
|
||||||
for t in tokens {
|
|
||||||
match t.as_rule() {
|
|
||||||
Rule::identifier => {
|
|
||||||
let ident = t.as_str().trim();
|
|
||||||
let mut ident_rs = String::from("_0x");
|
|
||||||
let ident_chars: Vec<char> = ident.chars().collect();
|
|
||||||
for i in 0..ident_chars.len() {
|
|
||||||
let current = ident_chars[i];
|
|
||||||
if ident_chars.len() > i + 1 {
|
|
||||||
let next = ident_chars[i + 1];
|
|
||||||
if current == '.' {
|
|
||||||
ident_rs += "._0x";
|
|
||||||
} else if current == ':' && next == ':' {
|
|
||||||
ident_rs += "::_0x";
|
|
||||||
} else {
|
|
||||||
if current != ':' && current != '.' {
|
|
||||||
ident_rs +=
|
|
||||||
hex::encode(current.to_string()).as_str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if current == '.' {
|
|
||||||
ident_rs += "._0x";
|
|
||||||
} else {
|
|
||||||
ident_rs += hex::encode(current.to_string()).as_str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if self.mod_manager.macros.contains(&ident_rs) {
|
|
||||||
output += ident_rs.as_str();
|
|
||||||
output += "!";
|
|
||||||
} else {
|
|
||||||
output += match ident {
|
|
||||||
"void" => "()",
|
|
||||||
"int" => "i32",
|
|
||||||
"float" => "f64",
|
|
||||||
"Vec" => "Vec",
|
|
||||||
"bool" => "bool",
|
|
||||||
_ => {
|
|
||||||
if self.mod_manager.map.contains_key(ident) {
|
|
||||||
self.mod_manager.map.get(ident).unwrap()
|
|
||||||
} else {
|
|
||||||
ident_rs.as_str()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Rule::def_identifier => {
|
|
||||||
output += "<";
|
|
||||||
output += self.encode_ident(t.as_str()).as_str();
|
|
||||||
output += ">";
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output
|
|
||||||
}
|
|
||||||
Err(_) => String::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn transpile_pairs(&mut self, pairs: Pairs<Rule>) -> String {
|
|
||||||
let mut res = String::new();
|
|
||||||
for pair in pairs {
|
|
||||||
res += self.transpile(pair).as_str();
|
|
||||||
}
|
|
||||||
res
|
|
||||||
}
|
|
||||||
pub fn transpile_vec(&mut self, pairs: Vec<Pair<Rule>>) -> String {
|
|
||||||
let mut res = String::new();
|
|
||||||
for pair in pairs {
|
|
||||||
res += self.transpile(pair).as_str();
|
|
||||||
}
|
|
||||||
res
|
|
||||||
}
|
|
||||||
pub fn transpile(&mut self, pair: Pair<Rule>) -> String {
|
|
||||||
let mut res = String::new();
|
|
||||||
let tokens = to_indexable(pair.clone().into_inner());
|
|
||||||
match pair.as_rule() {
|
|
||||||
Rule::func_def => {
|
|
||||||
res += format!(
|
|
||||||
"pub fn {}({}) -> {} {}\n",
|
|
||||||
self.transpile(tokens[1].clone()),
|
|
||||||
self.transpile_pairs(tokens[2].clone().into_inner())
|
|
||||||
.as_str()
|
|
||||||
.replace("let mut", ""),
|
|
||||||
self.transpile(tokens[0].clone()),
|
|
||||||
self.transpile(tokens[3].clone())
|
|
||||||
)
|
|
||||||
.as_str();
|
|
||||||
}
|
|
||||||
Rule::ptr_fn_def => {
|
|
||||||
res += format!(
|
|
||||||
"pub fn {}({}) -> &mut {} {}\n",
|
|
||||||
self.transpile(tokens[1].clone()),
|
|
||||||
self.transpile_pairs(tokens[2].clone().into_inner())
|
|
||||||
.as_str()
|
|
||||||
.replace("let mut", ""),
|
|
||||||
self.transpile(tokens[0].clone()),
|
|
||||||
self.transpile(tokens[3].clone())
|
|
||||||
)
|
|
||||||
.as_str();
|
|
||||||
}
|
|
||||||
Rule::var_def_ptr => {
|
|
||||||
res += format!(
|
|
||||||
"let mut {}: &mut {}",
|
|
||||||
self.transpile(tokens[1].clone()),
|
|
||||||
self.transpile(tokens[0].clone())
|
|
||||||
)
|
|
||||||
.as_str();
|
|
||||||
}
|
|
||||||
Rule::var_def => {
|
|
||||||
if tokens.len() == 1 {
|
|
||||||
res += self.transpile(tokens[0].clone()).as_str();
|
|
||||||
} else {
|
|
||||||
res += format!(
|
|
||||||
"let mut {}: {}",
|
|
||||||
self.transpile(tokens[1].clone()),
|
|
||||||
self.transpile(tokens[0].clone())
|
|
||||||
)
|
|
||||||
.as_str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Rule::var_def_set => {
|
|
||||||
res += format!(
|
|
||||||
"{} = {}",
|
|
||||||
self.transpile(tokens[0].clone()),
|
|
||||||
self.transpile(tokens[1].clone()),
|
|
||||||
)
|
|
||||||
.as_str();
|
|
||||||
}
|
|
||||||
Rule::curly => {
|
|
||||||
res += "{";
|
|
||||||
res += &self.transpile_pairs(pair.clone().into_inner());
|
|
||||||
res += "}";
|
|
||||||
}
|
|
||||||
Rule::code_expr => {
|
|
||||||
res += &self.transpile_pairs(pair.clone().into_inner());
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::include_global => {
|
|
||||||
res += "#[allow(unused_imports)]\nuse ";
|
|
||||||
res += self
|
|
||||||
.mod_manager
|
|
||||||
.add(&mut self.clone(), tokens[0].as_str().to_string(), true)
|
|
||||||
.as_str();
|
|
||||||
res += "::*;\n";
|
|
||||||
}
|
|
||||||
Rule::include => {
|
|
||||||
res += "#[allow(unused_imports)]\nuse ";
|
|
||||||
res += self
|
|
||||||
.mod_manager
|
|
||||||
.add(&mut self.clone(), tokens[0].as_str().to_string(), false)
|
|
||||||
.as_str();
|
|
||||||
res += "::*;\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::identifier | Rule::def_identifier => {
|
|
||||||
res += self.encode_ident(pair.as_str().trim()).as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::call => {
|
|
||||||
res += " ";
|
|
||||||
res += self.transpile(tokens[0].clone()).as_str();
|
|
||||||
res += self.transpile(tokens[1].clone()).as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::round => {
|
|
||||||
res += "(";
|
|
||||||
res += self.transpile_pairs(pair.into_inner()).as_str();
|
|
||||||
res += ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::expr => {
|
|
||||||
res += self.transpile_pairs(pair.into_inner()).as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::term => {
|
|
||||||
res += self.transpile_pairs(pair.into_inner()).as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::struct_def => {
|
|
||||||
res += "struct ";
|
|
||||||
res += self.transpile(tokens[0].clone()).as_str();
|
|
||||||
res += "{";
|
|
||||||
res += self.transpile(tokens[1].clone()).as_str();
|
|
||||||
res += "}";
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::semicolon => {
|
|
||||||
res += ";\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::string => {
|
|
||||||
res += pair.as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::map => {
|
|
||||||
self.mod_manager.map.insert(
|
|
||||||
tokens[0].as_str().to_string(),
|
|
||||||
tokens[2].as_str().to_string(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::enum_def => {
|
|
||||||
res += format!(
|
|
||||||
"enum {} {}{}{}",
|
|
||||||
self.transpile(tokens[0].clone()),
|
|
||||||
"{",
|
|
||||||
self.transpile_pairs(tokens[1].clone().into_inner()),
|
|
||||||
"}\n"
|
|
||||||
)
|
|
||||||
.as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::ecall => {
|
|
||||||
res += self.transpile(tokens[0].clone()).as_str();
|
|
||||||
if tokens.len() > 1 {
|
|
||||||
let mut params = tokens.clone();
|
|
||||||
params.remove(0);
|
|
||||||
res += "(";
|
|
||||||
res += self.transpile_vec(params).as_str();
|
|
||||||
res += ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::comma => {
|
|
||||||
res += ",";
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::ptr_set => {
|
|
||||||
res += format!(
|
|
||||||
"*{} = {}",
|
|
||||||
self.transpile(tokens[0].clone()),
|
|
||||||
self.transpile(tokens[1].clone()),
|
|
||||||
)
|
|
||||||
.as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::int => {
|
|
||||||
res += " ";
|
|
||||||
res += pair.as_str();
|
|
||||||
res += " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::refrence => {
|
|
||||||
res += "&mut ";
|
|
||||||
res += self.transpile(tokens[0].clone()).as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::return_stm => {
|
|
||||||
res += "return ";
|
|
||||||
res += self.transpile(tokens[0].clone()).as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::if_stm => {
|
|
||||||
res += "if ";
|
|
||||||
res += self.transpile_pairs(pair.into_inner()).as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::else_if_stm => {
|
|
||||||
res += "else if ";
|
|
||||||
res += self.transpile_pairs(pair.into_inner()).as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::else_stm => {
|
|
||||||
res += "else ";
|
|
||||||
res += self.transpile_pairs(pair.into_inner()).as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::bool => {
|
|
||||||
res += pair.as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::operator => {
|
|
||||||
res += pair.as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::if_operator => {
|
|
||||||
res += pair.as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::if_expr => {
|
|
||||||
res += self.transpile_pairs(pair.into_inner()).as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::namespace_def => {
|
|
||||||
res += "mod ";
|
|
||||||
res += self.transpile_pairs(pair.into_inner()).as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::top_code => {
|
|
||||||
res += "{";
|
|
||||||
res += self.transpile_pairs(pair.into_inner()).as_str();
|
|
||||||
res += "}";
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::top_expr => {
|
|
||||||
res += self.transpile_pairs(pair.into_inner()).as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::impl_def => {
|
|
||||||
res += "impl ";
|
|
||||||
res += self.transpile_pairs(pair.into_inner()).as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::match_name => {
|
|
||||||
let to_match = tokens[0].clone().as_str();
|
|
||||||
let match_id = tokens[1].clone().as_str();
|
|
||||||
res += "\n";
|
|
||||||
res += self.encode_ident(to_match).as_str();
|
|
||||||
res += "<match:";
|
|
||||||
res += match_id;
|
|
||||||
res += ">";
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::operation => {
|
|
||||||
for i in 0..tokens.len() {
|
|
||||||
let token = tokens[i].clone();
|
|
||||||
if i % 2 == 0 {
|
|
||||||
res += self.transpile(token).as_str();
|
|
||||||
} else {
|
|
||||||
res += token.as_str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => {
|
|
||||||
println!("\x1b[33mNot Handled: {}\x1b[0m", pair);
|
|
||||||
res += " ";
|
|
||||||
res += pair.as_str();
|
|
||||||
res += " ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
res
|
|
||||||
}
|
|
||||||
pub fn transpile_code(&mut self, code: String, indent: usize) -> Result<String, Error<Rule>> {
|
|
||||||
let mut res = String::new();
|
|
||||||
match WystParser::parse(Rule::top_expr, &code) {
|
|
||||||
Ok(parsed) => {
|
|
||||||
for pair in parsed {
|
|
||||||
res += self.transpile_pairs(pair.into_inner()).as_str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
return Err(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if indent > 0 {
|
|
||||||
res += " ".repeat(indent * 2).as_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
if indent > 0 {
|
|
||||||
res += "\n";
|
|
||||||
res += " ".repeat((indent - 1) * 2).as_str();
|
|
||||||
}
|
|
||||||
Ok(res)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const OUT_FOLDER = "build/"
|
||||||
|
|
||||||
|
func FileExists(filename string) bool {
|
||||||
|
_, err := os.Stat(filename)
|
||||||
|
return err == nil || !os.IsNotExist(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Module struct {
|
||||||
|
Code string
|
||||||
|
Name string
|
||||||
|
Path string
|
||||||
|
Out string
|
||||||
|
Inner []Module
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeFile(file_name, file_content string) {
|
||||||
|
os.MkdirAll(path.Dir(file_name), os.ModePerm)
|
||||||
|
file, err := os.Create(file_name)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error creating file (%s): %v\n", file_name, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
_, err = file.WriteString(file_content)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error writing to file:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func readFile(file_name string) string {
|
||||||
|
out, _ := os.ReadFile(file_name)
|
||||||
|
return string(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRoot(file_path string) Module {
|
||||||
|
root := Module{}
|
||||||
|
|
||||||
|
root.Path = file_path
|
||||||
|
root.Out = OUT_FOLDER + "main.go"
|
||||||
|
root.Name = "root"
|
||||||
|
root.Code = root.Transpile(readFile(file_path))
|
||||||
|
|
||||||
|
return root
|
||||||
|
}
|
||||||
|
|
||||||
|
func (root *Module) ImportModule(modname string) string {
|
||||||
|
module := Module{Name: modname}
|
||||||
|
module.Path = path.Join(path.Dir(root.Path), module.Name+".wyst")
|
||||||
|
if !FileExists(module.Path) {
|
||||||
|
module.Path = path.Join(path.Dir(root.Path), module.Name, "mod.wyst")
|
||||||
|
}
|
||||||
|
|
||||||
|
if FileExists(module.Path) {
|
||||||
|
module.Out = fmt.Sprintf("%s/I%#x/%s.go", path.Dir(root.Out), module.Name, module.Name)
|
||||||
|
module.Code = "package " + fmt.Sprintf("_%#x", modname) + "\n" + module.Transpile(readFile(module.Path))
|
||||||
|
root.Inner = append(root.Inner, module)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s/I%#x", path.Dir(root.Out), module.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func WriteModules(root Module) {
|
||||||
|
for _, module := range root.Inner {
|
||||||
|
writeFile(module.Out, module.Code)
|
||||||
|
WriteModules(module)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WriteRoot(root Module) {
|
||||||
|
writeFile(OUT_FOLDER+"main.go", "package main\n"+root.Code)
|
||||||
|
writeFile(OUT_FOLDER+"go.mod", "module "+strings.ReplaceAll(OUT_FOLDER, "/", "")+"\n"+"go 1.22\ntoolchain go1.22.6")
|
||||||
|
WriteModules(root)
|
||||||
|
}
|
||||||
-273
@@ -1,273 +0,0 @@
|
|||||||
use crate::transpiler::{Rule, State, Transpiler, WystParser};
|
|
||||||
use dirs::home_dir;
|
|
||||||
use pest::Parser;
|
|
||||||
use rand::random;
|
|
||||||
use regex::Regex;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::fs;
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub enum ProblemType {
|
|
||||||
VariableNotFound,
|
|
||||||
FileNotFound,
|
|
||||||
HeaderSyntaxError,
|
|
||||||
SyntaxError,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub enum ProblemCap {
|
|
||||||
Error(Problem),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct Problem {
|
|
||||||
pub problem_type: ProblemType,
|
|
||||||
pub problem_msg: String,
|
|
||||||
pub state: State,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Module {
|
|
||||||
pub rs_mod: String,
|
|
||||||
pub file_path: String,
|
|
||||||
pub code: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct ModManager {
|
|
||||||
pub modules: Vec<Module>,
|
|
||||||
pub macros: Vec<String>,
|
|
||||||
pub map: HashMap<String, String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ModManager {
|
|
||||||
pub fn new() -> ModManager {
|
|
||||||
ModManager {
|
|
||||||
modules: Vec::new(),
|
|
||||||
macros: Vec::new(),
|
|
||||||
map: HashMap::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn check(&mut self, path: String) -> Option<Module> {
|
|
||||||
for module in self.modules.clone() {
|
|
||||||
if module.file_path == path {
|
|
||||||
return Some(module);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
pub fn add(&mut self, root: &mut Transpiler, file_path: String, global: bool) -> String {
|
|
||||||
let mut problems: Vec<ProblemCap> = Vec::new();
|
|
||||||
let mod_name = format!("mod_{}", self.modules.len());
|
|
||||||
let home_dirpb = home_dir().unwrap();
|
|
||||||
let home_dir = home_dirpb.to_str().unwrap();
|
|
||||||
let mut file_path = file_path;
|
|
||||||
if global {
|
|
||||||
let mut tmp = Path::new(home_dir)
|
|
||||||
.join("wyst")
|
|
||||||
.join("lib")
|
|
||||||
.join(file_path.clone())
|
|
||||||
.to_str()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
if !Path::new(&tmp).exists() {
|
|
||||||
tmp = Path::new("lib")
|
|
||||||
.join(file_path)
|
|
||||||
.to_str()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
}
|
|
||||||
file_path = tmp;
|
|
||||||
}
|
|
||||||
if let Some(modl) = self.check(file_path.clone()) {
|
|
||||||
return modl.rs_mod;
|
|
||||||
}
|
|
||||||
if let Ok(code) = fs::read_to_string(file_path.clone()) {
|
|
||||||
match file_path.rsplit_once('.').unwrap_or(("", "")).1 {
|
|
||||||
"rs" => match WystParser::parse(Rule::rust_code, &code) {
|
|
||||||
Ok(parsed) => {
|
|
||||||
self.modules.push(Module {
|
|
||||||
rs_mod: mod_name.clone(),
|
|
||||||
file_path: file_path.clone(),
|
|
||||||
code: code.clone(),
|
|
||||||
});
|
|
||||||
for pair in parsed {
|
|
||||||
for p in pair.into_inner() {
|
|
||||||
if p.as_rule() == Rule::rust_macro_lint {
|
|
||||||
self.macros.push(p.into_inner().as_str().to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(_) => {}
|
|
||||||
},
|
|
||||||
"h" => {
|
|
||||||
file_path = file_path.rsplit_once('.').unwrap_or(("", "")).0.to_string();
|
|
||||||
file_path += ".rs";
|
|
||||||
let parsed = WystParser::parse(Rule::header_expr, &code).unwrap();
|
|
||||||
for pair in parsed {
|
|
||||||
root.transpile_pairs(pair.into_inner());
|
|
||||||
}
|
|
||||||
self.map.extend(root.mod_manager.map.clone().into_iter());
|
|
||||||
if let Ok(code1) = fs::read_to_string(file_path.clone()) {
|
|
||||||
let parsed = WystParser::parse(Rule::rust_code, &code1).unwrap();
|
|
||||||
self.modules.push(Module {
|
|
||||||
rs_mod: mod_name.clone(),
|
|
||||||
file_path: file_path.clone(),
|
|
||||||
code: code1.clone(),
|
|
||||||
});
|
|
||||||
for pair in parsed {
|
|
||||||
for p in pair.into_inner() {
|
|
||||||
if p.as_rule() == Rule::rust_macro_lint {
|
|
||||||
self.macros.push(p.into_inner().as_str().to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
problems.push(ProblemCap::Error(Problem {
|
|
||||||
problem_msg: format!("Sub Header not found '{}'", file_path),
|
|
||||||
problem_type: ProblemType::FileNotFound,
|
|
||||||
state: State {
|
|
||||||
line: 0,
|
|
||||||
column: 0,
|
|
||||||
file: None,
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
problems.push(ProblemCap::Error(Problem {
|
|
||||||
problem_msg: format!("File not found '{}'", file_path),
|
|
||||||
problem_type: ProblemType::FileNotFound,
|
|
||||||
state: State {
|
|
||||||
line: 0,
|
|
||||||
column: 0,
|
|
||||||
file: None,
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
mod_name
|
|
||||||
}
|
|
||||||
pub fn write(&mut self) -> Vec<ProblemCap> {
|
|
||||||
let mut problems: Vec<ProblemCap> = Vec::new();
|
|
||||||
for module in self.modules.clone() {
|
|
||||||
let file_path = module.file_path;
|
|
||||||
match file_path.rsplit_once('.').unwrap_or(("", "")).1 {
|
|
||||||
"wst" => {
|
|
||||||
let mut trsp = Transpiler {
|
|
||||||
mod_manager: self.clone(),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
let rust_code = trsp.transpile_code(module.code, 0).expect("");
|
|
||||||
fs::write(
|
|
||||||
Path::new("build").join((module.rs_mod + ".rs").as_str()),
|
|
||||||
rust_code,
|
|
||||||
)
|
|
||||||
.expect("Error writing rust file: ");
|
|
||||||
problems.append(&mut trsp.problems);
|
|
||||||
self.modules = trsp.mod_manager.modules;
|
|
||||||
}
|
|
||||||
|
|
||||||
"rs" => fs::write(
|
|
||||||
Path::new("build").join((module.rs_mod + ".rs").as_str()),
|
|
||||||
&module.code,
|
|
||||||
)
|
|
||||||
.unwrap(),
|
|
||||||
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
problems
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub struct MatchError {
|
|
||||||
msg: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn match_code(code: String, line: usize, column: usize) -> Result<String, MatchError> {
|
|
||||||
let re_include = Regex::new(r#"\#\s*include\s*(<|\")([a-zA-Z0-9_.-]*)$"#).unwrap();
|
|
||||||
let re_ident = Regex::new(r#"(\:\:|[_a-zA-Z])(\:\:|[_a-zA-Z0-9])*$"#).unwrap();
|
|
||||||
let mut lines: Vec<&str> = code.split("\n").collect();
|
|
||||||
if lines.len() >= line {
|
|
||||||
let result = &lines[line][..column];
|
|
||||||
if let Some(caps) = re_include.captures(&result) {
|
|
||||||
let match_id: u16 = random();
|
|
||||||
return Ok(format!("<match_file:{}:_{}>", &caps[0], match_id));
|
|
||||||
} else if let Some(caps) = re_ident.captures(&result) {
|
|
||||||
let match_id: u16 = random();
|
|
||||||
let match_line = format!("<match:{}:_{}>", &caps[0], match_id);
|
|
||||||
lines[line] = match_line.as_str();
|
|
||||||
let mut trsp = Transpiler::default();
|
|
||||||
match trsp.transpile_code(lines.join("\n"), 0) {
|
|
||||||
Ok(rs_code) => {
|
|
||||||
return Ok(rs_code);
|
|
||||||
}
|
|
||||||
Err(_) => {
|
|
||||||
return Err(MatchError {
|
|
||||||
msg: "Syntax error".to_string(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(MatchError {
|
|
||||||
msg: "last resort empty".to_string(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const LOGO: &str = r#"
|
|
||||||
|
|
||||||
|
|
||||||
@@ @@@ @
|
|
||||||
@@@@ @@@@@ @@@@
|
|
||||||
@@@@ @@@@@@@@@@@@@@@@@@@ @@@@
|
|
||||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
|
||||||
@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@
|
|
||||||
@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@
|
|
||||||
@@@ @@@@@@@@@@@@@@@ @@@@@@@@@ @@@@@@@@@@@@@@@ @@@
|
|
||||||
@@@@@@@@@@@@@@@ @@@@@@ @@@@@@@@@@@@@@@
|
|
||||||
@@@@@@@@@@@@ @ @@@@@@@@@@@@
|
|
||||||
@@@@@@@@@@@@@@@ @@@@@@@@@@ @@
|
|
||||||
@@@@@@@@@@@@@ @@@@@@@@@@@@@
|
|
||||||
@@@@@@@@@@ @@@@@@@@@@
|
|
||||||
@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@
|
|
||||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@
|
|
||||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@
|
|
||||||
@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@
|
|
||||||
@@@@@ @@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@ @@@@@
|
|
||||||
@@@@@@@@@ @@@@@@@@@@@@@@ @@@@@@@@@@@@ @@@@@@@@@@@@ @@@@@@@@@
|
|
||||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@
|
|
||||||
@@@@@@@@@@@ @@@@@@@@@@@@@ @@@@@@@@@@@@@@ @@@@@@@@@@ @@@@@@@@@@@
|
|
||||||
@@@@@@@@ @@@@@@@@@@@@@ @@@@@@@@@@@@@@@@ @@@@@@@@@ @@@@@@@@
|
|
||||||
@@@@@@@@@@@ @@@@@@@@@@@@@ @@@@@@@@@@@@@@@@ @@@@@@@@@@ @@@@@@@@@@@
|
|
||||||
@@@@@@@@@@@ @@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@@@@@@@@ @@@@@@@@@@@
|
|
||||||
@@@@@@@@ @@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@
|
|
||||||
@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@
|
|
||||||
@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@
|
|
||||||
@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@
|
|
||||||
@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@@@@@@@
|
|
||||||
@@@@@@@@@ @@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@ @@@@@@@@@
|
|
||||||
@@@@@@@@@@@ @@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@ @@@@@@@@@@
|
|
||||||
@@@@@@@@@@@@@ @@@@@@@@@@@@@@ @@@@@@@@@@@@@@ @@@@@@@@@@@@@
|
|
||||||
@@@@@@@@@ @@@@@@@@@@@@@@ @@@@@@@@@@@@@@ @@@@@@@@@
|
|
||||||
@@@@@@@@@@ @ @@@@@@@@@@
|
|
||||||
@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@
|
|
||||||
@@@ @@@@@@@@@ @@@ @@@@ @@@@@@@@@ @@@
|
|
||||||
@@@@@@@@ @@@ @@@ @@@@@@@@
|
|
||||||
@@@@@@@@@ @@@@ @@@@ @@@@@@@@@
|
|
||||||
@@@ @@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@ @@@
|
|
||||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
|
||||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
|
||||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
|
||||||
@@@@ @@@@@@@@@@@@@@@@@@@ @@@@
|
|
||||||
@@@@ @@@@@ @@@@
|
|
||||||
@@ @@@ @@
|
|
||||||
|
|
||||||
|
|
||||||
"#;
|
|
||||||
-121
@@ -1,121 +0,0 @@
|
|||||||
WHITESPACE = _{ ("//" ~ (!"\n" ~ ANY)*) | ("/*" ~ (!"*/" ~ ANY)*) | " " | "\t" | "\n" }
|
|
||||||
|
|
||||||
// [chars]
|
|
||||||
comma = {","}
|
|
||||||
semicolon = {";"}
|
|
||||||
dot = {"."}
|
|
||||||
|
|
||||||
// [literals]
|
|
||||||
filepath = { ("/"|('a'..'z' | 'a'..'z' | '0'..'9' | "_" | "-" | "."))+ }
|
|
||||||
include = { "#" ~ "include" ~ "\"" ~ filepath ~ "\"" }
|
|
||||||
include_global = { "#" ~ "include" ~ "<" ~ filepath ~ ">" }
|
|
||||||
round = { "(" ~ ((expr ~ comma)* ~ expr?) ~ ")" }
|
|
||||||
curly = { "{" ~ (code_expr)* ~ "}" }
|
|
||||||
escape = { "\\" ~ ANY }
|
|
||||||
raw_string = { (!("\\" | "\"") ~ ANY)+ }
|
|
||||||
string = { "\"" ~ (raw_string | escape )* ~ "\"" }
|
|
||||||
char = { "'" ~ (escape | ANY) ~ "'" }
|
|
||||||
bool = @{"true" | "false"}
|
|
||||||
keyword = @{"struct"|"return"}
|
|
||||||
map = { "#" ~ "map" ~ identifier ~ comma ~ identifier }
|
|
||||||
match_name = { "<match:" ~ identifier ~ ":" ~ identifier ~ ">" }
|
|
||||||
|
|
||||||
// [numbers]
|
|
||||||
hex = @{ "0" ~ ("x"|"X") ~ ('0'..'9' | 'a'..'f' | 'A'..'F')*}
|
|
||||||
float = @{ ('0'..'9')* ~ "." ~ ('0'..'9')+ }
|
|
||||||
int = @{ '0'..'9'+ }
|
|
||||||
|
|
||||||
// [identifiers]
|
|
||||||
identifier = @{ !(hex|float|int) ~ ("." | "::" | "_" | 'a'..'z' | 'A'..'Z') ~ ( "." | "::" | "_" | 'a'..'z' | 'A'..'Z' | int )*}
|
|
||||||
def_identifier = {identifier ~ ("<" ~ ((def_identifier ~ comma)* ~ def_identifier?) ~ ">")?}
|
|
||||||
|
|
||||||
// [definitions]
|
|
||||||
round_def = { "(" ~ ((var_def ~ comma)* ~ var_def?) ~ ")" }
|
|
||||||
curly_def = { "{" ~ (var_def ~ semicolon)* ~ "}" }
|
|
||||||
var_def = { (def_identifier ~ identifier) | var_def_ptr }
|
|
||||||
var_def_ptr = { def_identifier ~ "*" ~ identifier }
|
|
||||||
var_def_set = { var_def ~ "=" ~ expr }
|
|
||||||
var_set = { def_identifier ~ "=" ~ expr }
|
|
||||||
func_def = { def_identifier ~ identifier ~ round_def ~ curly }
|
|
||||||
struct_def = { "struct" ~ identifier ~ curly_def }
|
|
||||||
ecall = { identifier ~ ( "(" ~ ((def_identifier ~ comma)* ~ def_identifier?) ~ ")" )? }
|
|
||||||
ecurly = { "{" ~ ((ecall ~ comma)* ~ ecall?) ~ "}" }
|
|
||||||
enum_def = { "enum" ~ identifier ~ ecurly }
|
|
||||||
top_code = {"{"~ top_expr ~"}"}
|
|
||||||
namespace_def = {"namespace" ~ identifier ~ top_code}
|
|
||||||
impl_def = {"impl" ~ identifier ~ top_code}
|
|
||||||
|
|
||||||
// [Ptr]
|
|
||||||
ptr_fn_def = { def_identifier ~ "*" ~ identifier ~ round_def ~ curly }
|
|
||||||
ptr_set = { "*" ~ identifier ~ "=" ~ expr }
|
|
||||||
refrence = { "&" ~ identifier }
|
|
||||||
|
|
||||||
// [Operators]
|
|
||||||
if_operator = {"&&"|"||"}
|
|
||||||
operator = {"=="|"+"|"-"|"!="|">"|"<"|">="|"<="}
|
|
||||||
if_expr = {expr ~ (if_operator ~ (("("~if_expr*~")")|expr))*}
|
|
||||||
operation = {(term ~ operator)+ ~ term}
|
|
||||||
|
|
||||||
// [Statement]
|
|
||||||
return_stm = { "return" ~ expr }
|
|
||||||
if_stm = { "if" ~ if_expr ~ curly }
|
|
||||||
else_if_stm = { "else" ~ "if" ~ if_expr ~ curly }
|
|
||||||
else_stm = { "else" ~ curly }
|
|
||||||
|
|
||||||
rust_macro_lint = { "macro_rules" ~ "!" ~ identifier }
|
|
||||||
rust_code = { (rust_macro_lint | ANY)* }
|
|
||||||
|
|
||||||
call = {identifier ~ round}
|
|
||||||
|
|
||||||
term = {
|
|
||||||
call |
|
|
||||||
round |
|
|
||||||
char |
|
|
||||||
hex |
|
|
||||||
float |
|
|
||||||
int |
|
|
||||||
bool |
|
|
||||||
identifier |
|
|
||||||
string |
|
|
||||||
refrence |
|
|
||||||
match_name
|
|
||||||
}
|
|
||||||
|
|
||||||
expr = {
|
|
||||||
operation |
|
|
||||||
(term ~ dot ~ identifier ~ round?) |
|
|
||||||
term
|
|
||||||
}
|
|
||||||
|
|
||||||
code_expr = {
|
|
||||||
((
|
|
||||||
return_stm |
|
|
||||||
var_def_set|
|
|
||||||
var_def |
|
|
||||||
var_set |
|
|
||||||
ptr_set |
|
|
||||||
expr
|
|
||||||
) ~ semicolon) |
|
|
||||||
if_stm |
|
|
||||||
else_if_stm |
|
|
||||||
else_stm
|
|
||||||
}
|
|
||||||
|
|
||||||
top_expr = {
|
|
||||||
(
|
|
||||||
func_def |
|
|
||||||
namespace_def |
|
|
||||||
include |
|
|
||||||
include_global |
|
|
||||||
ptr_fn_def |
|
|
||||||
struct_def |
|
|
||||||
enum_def |
|
|
||||||
map |
|
|
||||||
impl_def |
|
|
||||||
match_name
|
|
||||||
)*
|
|
||||||
}
|
|
||||||
|
|
||||||
header_expr = {
|
|
||||||
map*
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user