Skip to content

Commit 11ef2f1

Browse files
authored
Merge pull request #18 from X-R-G-B/dev
Dev
2 parents a8c2613 + a306af4 commit 11ef2f1

88 files changed

Lines changed: 6096 additions & 86 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/documentation.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ jobs:
4848
if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main'
4949
run: mdbook build
5050

51+
- name: Copy OnlineRunner
52+
if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main'
53+
run: cp ./lvtext/webrunner/index.html ./book/OnlineVM.html
54+
5155
- name: Setup Pages
5256
if: github.ref == 'refs/heads/main'
5357
uses: actions/configure-pages@v3

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ $(TARGET):
1414
"$(MAKE)" -C "$(LVT_COMPILER)"
1515
"$(MAKE)" -C "$(LVT_RUNER)"
1616

17+
debug:
18+
"$(MAKE)" -C "$(LVT_COMPILER)" debug
19+
"$(MAKE)" -C "$(LVT_RUNER)" debug
20+
1721
clean:
1822
"$(MAKE)" -C "$(LVT_COMPILER)" clean
1923
"$(MAKE)" -C "$(LVT_RUNER)" clean

README.md

Lines changed: 16 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@
1313
// This is a comment
1414
```
1515

16+
- **Alias**
17+
18+
```
19+
alias A = Int;
20+
```
21+
1622
- **Variables Declaration**
1723

1824
```hs
1925
@Int a = 1;
20-
@String b = "hello";
26+
@StringView b = "hello";
2127
```
2228

2329
- **Variables Assignment**
@@ -79,21 +85,6 @@ fn add(a: Int, b: Int, c: Int) -> Int
7985
};
8086
```
8187

82-
- **Generic Functions**
83-
84-
```rust
85-
fn add[A](a: A, b: A) -> A
86-
{
87-
<- a + b;
88-
};
89-
```
90-
91-
- **Generic Functions Call**
92-
93-
```rust
94-
add[Int](1, 2);
95-
```
96-
9788
- **Conditions**
9889

9990
```c
@@ -123,70 +114,34 @@ while (i < 10)
123114
};
124115
```
125116

126-
- **Imports**
127-
128-
```c
129-
// Circular imports are not allowed
130-
import "path/to/file.lvt"
131-
```
132-
133117
- **Entrypoint**
134118

135119
```rust
136120
// If you don't have this function, the program will not be run
137-
fn start() -> Int
121+
export fn start() -> Int
138122
{
139123
<- 0;
140124
};
141125
```
142126

143127
- **Operators**
144128

145-
```
129+
```python
146130
a + b
147131
a - b
148132
a * b
149133
a / b
150134
a == b
151135
a != b
136+
a < b
137+
a <= b
138+
a > b
139+
a >= b
152140
```
153141

154-
- **Structs**
142+
- **Priority of Operators**
155143

156144
```c
157-
struct Point
158-
{
159-
x: Int,
160-
y: Int,
161-
};
162-
```
163-
164-
- **Structs Initialization**
165-
```
166-
@Point p = {1, 2};
167-
```
168-
169-
- **Structs Access**
170-
```
171-
p:x
172-
```
173-
174-
- **Nested Structs**
175-
```
176-
struct Rect
177-
{
178-
Point size;
179-
Point pos;
180-
};
181-
@Rect r = {{1, 2}, {3, 4}};
182-
r:size:x
183-
```
184-
185-
- **Generic Structs**
186-
187-
```c
188-
struct Rect[A]
189-
{
190-
attribute: A,
191-
};
145+
// realy peticuliar buut we use { for ( and } for )
146+
{a + B} * c
192147
```

docs/BNF.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Leviator BNF
2+
3+
```bnf
4+
<syntax> ::= <expression>*
5+
6+
<expression> ::= <alias> | <function> | <comment>
7+
8+
<alias> ::= "alias " <identifierAlias> " " <replacement> ";\n"
9+
<identifierAlias> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" |
10+
"J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" |
11+
"S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | "a" |
12+
"b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" |
13+
"k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" |
14+
"t" | "u" | "v" | "w" | "x" | "y" | "z" | "0" | "1" |
15+
"2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "_" |
16+
"." | "-" | ":" | "!" | "@" | "#" | "$" | "%" | "^" |
17+
"&" | "*" | "(" | ")" | "[" | "]" | "{" | "}" | "|" |
18+
"\\" | "+" | "=" | ";" | "<" | ">" | "?" | "/" | "`" |
19+
"~"
20+
<replacement> ::= <char2>
21+
22+
<comment> ::= "//" <char1>* "\n"
23+
24+
<function> ::= "fn " <identifier> "(" <parameterList>* ") -> " <type> "\n{\n" <instruction>* "}\n"
25+
<identifier> ::= <lowerLetter> <char2>
26+
<parameterList> ::= <parameter> ","
27+
<parameter> ::= <identifier> ": " <type>
28+
<type> ::= <upperLetter> <char2>
29+
<instruction> ::= <instructionIns> ";\n"
30+
<instructionIns> ::= <declaration> | <assignment> | <functionCall> | <return> | <condition>
31+
<declaration> ::= "@" <type> " " <identifier> " = " <value>
32+
<assignment> ::= <identifier> " = " <value>
33+
<functionCall> ::= <identifier> "(" <varParamList>* ")"
34+
<varParamList> ::= <value> ","
35+
<return> ::= "<- " <value>
36+
<value> ::= <functionCall> | <identifier> | <literal>
37+
<literal> ::= <digit> | <character> | <bool> | <stringview>
38+
<condition> ::= <conditionIf> | <conditionIfElse>
39+
<conditionIfElse> ::= <conditionIf> <conditionElse>
40+
<conditionIf> ::= "if (" <value> ")\n{\n" <instruction>* "}\n"
41+
<conditionElse> ::= "else\n{\n" <instruction>* "}\n"
42+
43+
<character> ::= "'" <char1> "'"
44+
<bool> ::= "True" | "False"
45+
<stringview> ::= "\"" <char1>* "\""
46+
47+
<char> ::= <lowerLetter> | <upperLetter> | <digit>
48+
<char1> ::= <char> | "" | " " | <specialAll>
49+
<char2> ::= <lowerLetter> | <upperLetter> | <digit> | <special>
50+
<lowerLetter> ::= "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" |
51+
"j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" |
52+
"s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
53+
<upperLetter> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" |
54+
"J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" |
55+
"S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"
56+
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
57+
<special> ::= "_"
58+
<specialAll> ::= <special> | "!" | "@" | "#" | "$" | "%" | "^" | "&" |
59+
"*" | "(" | ")" | "[" | "]" | "{" | "}" | "|" | "\\" |
60+
"+" | "=" | ";" | "<" | ">" | "?" | "/" | "`" | "~"
61+
```

docs/OnlineVM.md

Whitespace-only changes.

docs/SUMMARY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ made in Haskell.
66
[README](README.md)
77
[Byte Code Spec](ByteCodeSpec.md)
88
[Byte Code Spec Ex](ByteCodeSpecEx.md)
9+
[Syntax Highlighting Extension](SyntaxHighlighting.md)
10+
[BNF](BNF.md)
11+
[Online VM](OnlineVM.md)

docs/SyntaxHighlighting.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Leviator Lang Extension for Visual Studio Code
2+
3+
We are thrilled to introduce our Leviator lang extension, providing enhanced syntax highlighting for an optimized coding experience. While currently available exclusively for vscode, we have ambitious plans to extend support to JetBrains and Vim in the future.
4+
5+
### Installation
6+
7+
To install the Leviator Language extension for **Visual Studio Code**, follow the steps below:
8+
9+
1. Navigate to the "lvtext" directory in our [Leviator GitHub repository](https://github.com/X-R-G-B/Leviator/lvtext).
10+
2. Refer to the detailed installation instructions provided in the [README.md](https://github.com/X-R-G-B/Leviator/blob/lvtext/vscode/leviator-lang/README.md) file.

lvtc/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ all: $(TARGET)
2121
$(TARGET):
2222
stack build --copy-bins --local-bin-path .
2323

24+
debug:
25+
stack build --trace --copy-bins --local-bin-path .
26+
2427
clean:
2528
stack clean
2629

lvtc/app/Args.hs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{-
2+
-- EPITECH PROJECT, 2023
3+
-- Leviator compiler
4+
-- File description:
5+
-- Args
6+
-}
7+
8+
9+
module Args
10+
(
11+
Action(..),
12+
Args(..),
13+
parseArgs,
14+
printHelp
15+
) where
16+
17+
import System.Directory (getCurrentDirectory)
18+
19+
data Action = ShowHelp | ShowVersion | Run
20+
21+
data Args = Args {
22+
action :: Action,
23+
folderPath :: String,
24+
outFile :: String,
25+
verbose :: Bool
26+
}
27+
28+
parseArgs' :: [String] -> Args -> Either Args String
29+
parseArgs' [] args =
30+
Left args
31+
parseArgs' ("--help":xs) args =
32+
parseArgs' xs (args {action = ShowHelp})
33+
parseArgs' ("-h":xs) args =
34+
parseArgs' xs (args {action = ShowHelp})
35+
parseArgs' ("--version":xs) args =
36+
parseArgs' xs (args {action = ShowVersion})
37+
parseArgs' ("-v":xs) args =
38+
parseArgs' xs (args {action = ShowVersion})
39+
parseArgs' ("-o":x:xs) args =
40+
parseArgs' xs (args {outFile = x})
41+
parseArgs' ["-o"] _ =
42+
Right "Missing argument for -o"
43+
parseArgs' ("--verbose":xs) args =
44+
parseArgs' xs (args {verbose = True})
45+
parseArgs' (('-':xs):_) _ =
46+
Right ("Unknown option: " ++ xs)
47+
parseArgs' (x:xs) args =
48+
parseArgs' xs (args {action = Run, folderPath = x})
49+
50+
parseArgs :: [String] -> IO (Either Args String)
51+
parseArgs args =
52+
getCurrentDirectory >>= \path ->
53+
return (parseArgs' args (Args {
54+
action = Run, folderPath = path, outFile = "out.wasm", verbose = False
55+
}))
56+
57+
hLine1 :: String
58+
hLine1 = "Usage: lvtc [OPTION] [FOLDER]\n"
59+
hLine2 :: String
60+
hLine2 = "\n"
61+
hLine3 :: String
62+
hLine3 = "Compile Leviator source code to WebAssembly\n"
63+
hLine4 :: String
64+
hLine4 = ""
65+
hLine5 :: String
66+
hLine5 = "Options:\n"
67+
hLine6 :: String
68+
hLine6 = "\t-h, --help\n\t\tDisplay this help and exit\n"
69+
hLine7 :: String
70+
hLine7 = "\t-v, --version\n\t\tOutput version information and exit\n"
71+
hLine8 :: String
72+
hLine8 = "\t-o FILE\n\t\tWrite WebAssembly to FILE\n"
73+
hLine9 :: String
74+
hLine9 = part1 ++ part2
75+
where
76+
part1 = "\tFOLDER\n\t\tTake all Leviator"
77+
part2 = " source code recursively from FOLDER\n"
78+
hLine10 :: String
79+
hLine10 = "\t--verbose\n\t\tVerbose mode\n"
80+
81+
printHelp :: IO ()
82+
printHelp =
83+
putStr hLine1 >> putStr hLine2 >> putStr hLine3 >> putStr hLine4
84+
>> putStr hLine5 >> putStr hLine6 >> putStr hLine7 >> putStr hLine8
85+
>> putStr hLine9 >> putStr hLine10

lvtc/app/Main.hs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,20 @@
77

88
module Main (main) where
99

10-
import Lib
10+
import System.Environment (getArgs)
11+
12+
import Args (Args (..), parseArgs, Action (..), printHelp)
13+
import Run (run)
14+
import Version (printVersion)
15+
16+
dispatchArgs :: Args -> IO ()
17+
dispatchArgs (Args Run fPath oFile v) = run (Args Run fPath oFile v)
18+
dispatchArgs (Args ShowHelp _ _ _) = printHelp
19+
dispatchArgs (Args ShowVersion _ _ _) = printVersion
20+
21+
dispatchIfOk :: Either Args String -> IO ()
22+
dispatchIfOk (Left args) = dispatchArgs args
23+
dispatchIfOk (Right str) = print str
1124

1225
main :: IO ()
13-
main = someFunc
26+
main = getArgs >>= parseArgs >>= dispatchIfOk

0 commit comments

Comments
 (0)