Skip to content

Commit

Permalink
Merge pull request #18 from X-R-G-B/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Saverio976 authored Jan 14, 2024
2 parents a8c2613 + a306af4 commit 11ef2f1
Show file tree
Hide file tree
Showing 88 changed files with 6,096 additions and 86 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ jobs:
if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main'
run: mdbook build

- name: Copy OnlineRunner
if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main'
run: cp ./lvtext/webrunner/index.html ./book/OnlineVM.html

- name: Setup Pages
if: github.ref == 'refs/heads/main'
uses: actions/configure-pages@v3
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ $(TARGET):
"$(MAKE)" -C "$(LVT_COMPILER)"
"$(MAKE)" -C "$(LVT_RUNER)"

debug:
"$(MAKE)" -C "$(LVT_COMPILER)" debug
"$(MAKE)" -C "$(LVT_RUNER)" debug

clean:
"$(MAKE)" -C "$(LVT_COMPILER)" clean
"$(MAKE)" -C "$(LVT_RUNER)" clean
Expand Down
77 changes: 16 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@
// This is a comment
```

- **Alias**

```
alias A = Int;
```

- **Variables Declaration**

```hs
@Int a = 1;
@String b = "hello";
@StringView b = "hello";
```

- **Variables Assignment**
Expand Down Expand Up @@ -79,21 +85,6 @@ fn add(a: Int, b: Int, c: Int) -> Int
};
```

- **Generic Functions**

```rust
fn add[A](a: A, b: A) -> A
{
<- a + b;
};
```

- **Generic Functions Call**

```rust
add[Int](1, 2);
```

- **Conditions**

```c
Expand Down Expand Up @@ -123,70 +114,34 @@ while (i < 10)
};
```

- **Imports**

```c
// Circular imports are not allowed
import "path/to/file.lvt"
```

- **Entrypoint**

```rust
// If you don't have this function, the program will not be run
fn start() -> Int
export fn start() -> Int
{
<- 0;
};
```

- **Operators**

```
```python
a + b
a - b
a * b
a / b
a == b
a != b
a < b
a <= b
a > b
a >= b
```

- **Structs**
- **Priority of Operators**

```c
struct Point
{
x: Int,
y: Int,
};
```

- **Structs Initialization**
```
@Point p = {1, 2};
```

- **Structs Access**
```
p:x
```

- **Nested Structs**
```
struct Rect
{
Point size;
Point pos;
};
@Rect r = {{1, 2}, {3, 4}};
r:size:x
```

- **Generic Structs**

```c
struct Rect[A]
{
attribute: A,
};
// realy peticuliar buut we use { for ( and } for )
{a + B} * c
```
61 changes: 61 additions & 0 deletions docs/BNF.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Leviator BNF

```bnf
<syntax> ::= <expression>*
<expression> ::= <alias> | <function> | <comment>
<alias> ::= "alias " <identifierAlias> " " <replacement> ";\n"
<identifierAlias> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" |
"J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" |
"S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | "a" |
"b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" |
"k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" |
"t" | "u" | "v" | "w" | "x" | "y" | "z" | "0" | "1" |
"2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "_" |
"." | "-" | ":" | "!" | "@" | "#" | "$" | "%" | "^" |
"&" | "*" | "(" | ")" | "[" | "]" | "{" | "}" | "|" |
"\\" | "+" | "=" | ";" | "<" | ">" | "?" | "/" | "`" |
"~"
<replacement> ::= <char2>
<comment> ::= "//" <char1>* "\n"
<function> ::= "fn " <identifier> "(" <parameterList>* ") -> " <type> "\n{\n" <instruction>* "}\n"
<identifier> ::= <lowerLetter> <char2>
<parameterList> ::= <parameter> ","
<parameter> ::= <identifier> ": " <type>
<type> ::= <upperLetter> <char2>
<instruction> ::= <instructionIns> ";\n"
<instructionIns> ::= <declaration> | <assignment> | <functionCall> | <return> | <condition>
<declaration> ::= "@" <type> " " <identifier> " = " <value>
<assignment> ::= <identifier> " = " <value>
<functionCall> ::= <identifier> "(" <varParamList>* ")"
<varParamList> ::= <value> ","
<return> ::= "<- " <value>
<value> ::= <functionCall> | <identifier> | <literal>
<literal> ::= <digit> | <character> | <bool> | <stringview>
<condition> ::= <conditionIf> | <conditionIfElse>
<conditionIfElse> ::= <conditionIf> <conditionElse>
<conditionIf> ::= "if (" <value> ")\n{\n" <instruction>* "}\n"
<conditionElse> ::= "else\n{\n" <instruction>* "}\n"
<character> ::= "'" <char1> "'"
<bool> ::= "True" | "False"
<stringview> ::= "\"" <char1>* "\""
<char> ::= <lowerLetter> | <upperLetter> | <digit>
<char1> ::= <char> | "" | " " | <specialAll>
<char2> ::= <lowerLetter> | <upperLetter> | <digit> | <special>
<lowerLetter> ::= "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" |
"j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" |
"s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
<upperLetter> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" |
"J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" |
"S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
<special> ::= "_"
<specialAll> ::= <special> | "!" | "@" | "#" | "$" | "%" | "^" | "&" |
"*" | "(" | ")" | "[" | "]" | "{" | "}" | "|" | "\\" |
"+" | "=" | ";" | "<" | ">" | "?" | "/" | "`" | "~"
```
Empty file added docs/OnlineVM.md
Empty file.
3 changes: 3 additions & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ made in Haskell.
[README](README.md)
[Byte Code Spec](ByteCodeSpec.md)
[Byte Code Spec Ex](ByteCodeSpecEx.md)
[Syntax Highlighting Extension](SyntaxHighlighting.md)
[BNF](BNF.md)
[Online VM](OnlineVM.md)
10 changes: 10 additions & 0 deletions docs/SyntaxHighlighting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Leviator Lang Extension for Visual Studio Code

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.

### Installation

To install the Leviator Language extension for **Visual Studio Code**, follow the steps below:

1. Navigate to the "lvtext" directory in our [Leviator GitHub repository](https://github.com/X-R-G-B/Leviator/lvtext).
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.
3 changes: 3 additions & 0 deletions lvtc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ all: $(TARGET)
$(TARGET):
stack build --copy-bins --local-bin-path .

debug:
stack build --trace --copy-bins --local-bin-path .

clean:
stack clean

Expand Down
85 changes: 85 additions & 0 deletions lvtc/app/Args.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{-
-- EPITECH PROJECT, 2023
-- Leviator compiler
-- File description:
-- Args
-}


module Args
(
Action(..),
Args(..),
parseArgs,
printHelp
) where

import System.Directory (getCurrentDirectory)

data Action = ShowHelp | ShowVersion | Run

data Args = Args {
action :: Action,
folderPath :: String,
outFile :: String,
verbose :: Bool
}

parseArgs' :: [String] -> Args -> Either Args String
parseArgs' [] args =
Left args
parseArgs' ("--help":xs) args =
parseArgs' xs (args {action = ShowHelp})
parseArgs' ("-h":xs) args =
parseArgs' xs (args {action = ShowHelp})
parseArgs' ("--version":xs) args =
parseArgs' xs (args {action = ShowVersion})
parseArgs' ("-v":xs) args =
parseArgs' xs (args {action = ShowVersion})
parseArgs' ("-o":x:xs) args =
parseArgs' xs (args {outFile = x})
parseArgs' ["-o"] _ =
Right "Missing argument for -o"
parseArgs' ("--verbose":xs) args =
parseArgs' xs (args {verbose = True})
parseArgs' (('-':xs):_) _ =
Right ("Unknown option: " ++ xs)
parseArgs' (x:xs) args =
parseArgs' xs (args {action = Run, folderPath = x})

parseArgs :: [String] -> IO (Either Args String)
parseArgs args =
getCurrentDirectory >>= \path ->
return (parseArgs' args (Args {
action = Run, folderPath = path, outFile = "out.wasm", verbose = False
}))

hLine1 :: String
hLine1 = "Usage: lvtc [OPTION] [FOLDER]\n"
hLine2 :: String
hLine2 = "\n"
hLine3 :: String
hLine3 = "Compile Leviator source code to WebAssembly\n"
hLine4 :: String
hLine4 = ""
hLine5 :: String
hLine5 = "Options:\n"
hLine6 :: String
hLine6 = "\t-h, --help\n\t\tDisplay this help and exit\n"
hLine7 :: String
hLine7 = "\t-v, --version\n\t\tOutput version information and exit\n"
hLine8 :: String
hLine8 = "\t-o FILE\n\t\tWrite WebAssembly to FILE\n"
hLine9 :: String
hLine9 = part1 ++ part2
where
part1 = "\tFOLDER\n\t\tTake all Leviator"
part2 = " source code recursively from FOLDER\n"
hLine10 :: String
hLine10 = "\t--verbose\n\t\tVerbose mode\n"

printHelp :: IO ()
printHelp =
putStr hLine1 >> putStr hLine2 >> putStr hLine3 >> putStr hLine4
>> putStr hLine5 >> putStr hLine6 >> putStr hLine7 >> putStr hLine8
>> putStr hLine9 >> putStr hLine10
17 changes: 15 additions & 2 deletions lvtc/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@

module Main (main) where

import Lib
import System.Environment (getArgs)

import Args (Args (..), parseArgs, Action (..), printHelp)
import Run (run)
import Version (printVersion)

dispatchArgs :: Args -> IO ()
dispatchArgs (Args Run fPath oFile v) = run (Args Run fPath oFile v)
dispatchArgs (Args ShowHelp _ _ _) = printHelp
dispatchArgs (Args ShowVersion _ _ _) = printVersion

dispatchIfOk :: Either Args String -> IO ()
dispatchIfOk (Left args) = dispatchArgs args
dispatchIfOk (Right str) = print str

main :: IO ()
main = someFunc
main = getArgs >>= parseArgs >>= dispatchIfOk
Loading

0 comments on commit 11ef2f1

Please sign in to comment.