Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into step-3rd-parser-lvt
Browse files Browse the repository at this point in the history
  • Loading branch information
Saverio976 committed Jan 6, 2024
2 parents 46a344a + 4e4f570 commit c592847
Show file tree
Hide file tree
Showing 15 changed files with 413 additions and 15 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,3 @@ struct Rect
@Rect r = {{1, 2}, {3, 4}};
r:size:x
```

- **Generic Structs**

```c
struct Rect[A]
{
attribute: A,
};
```
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ made in Haskell.
[README](README.md)
[Byte Code Spec](ByteCodeSpec.md)
[Byte Code Spec Ex](ByteCodeSpecEx.md)
[Syntax Highlighting Extension](SyntaxHighlighting.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.
11 changes: 10 additions & 1 deletion lvtc/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

module Main (main) where

import Expression (parseExpresion)
import Expression (parseExpresion, parseAllExpression)
import Parser (runParser)
import Alias (proceedAlias)
import ParseLvt (parseInstruction, parseInstructions)

test1 :: String
Expand All @@ -32,6 +33,13 @@ test5 = "@Int a = 4 + 5;\n"
test6 :: String
test6 = "@Int a = 3 + 4 * 2 / ( 1 - 5 );\n"

text :: String
text = aliasInt ++ aliasRetValue ++ funcMain
where
aliasInt = "alias int Int;\n"
aliasRetValue = "alias retValue 0;\n"
funcMain = "fn main () -> int \n{\n <- retValue;\n};\n"

main :: IO ()
main =
print (runParser parseInstruction test1)
Expand All @@ -40,3 +48,4 @@ main =
>> print (runParser parseExpresion test4)
>> print (runParser parseInstruction test5)
>> print (runParser parseInstruction test6)
>> print (runParser (proceedAlias <$> parseAllExpression) text)
1 change: 1 addition & 0 deletions lvtc/lvtc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ source-repository head

library
exposed-modules:
Alias
AST
Expression
Lib
Expand Down
80 changes: 80 additions & 0 deletions lvtc/src/Alias.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{-
-- EPITECH PROJECT, 2023
-- Leviator compiler
-- File description:
-- Alias
-}

module Alias (
proceedAlias,
) where

import Expression
import Parser
import ParseUtil
import Control.Applicative

data Alias = Alias String String

instance Show Alias.Alias where
show (Alias.Alias str1 str2) = "ALIAS `" ++ str1 ++ "`:`" ++ str2 ++ "`"

parseAliasKeyword :: Parser String
parseAliasKeyword = parseString "alias "

parseAliasName :: Parser String
parseAliasName = parseAllCharUntil " "

parseAliasValue :: Parser String
parseAliasValue = parseAllCharUntil ";\n"

parseAlias' :: Parser String
parseAlias' = (parseAliasKeyword *> parseAliasName <* many (parseChar ' '))

parseAlias :: Parser Alias.Alias
parseAlias = Parser f
where
f str = case runParser parseAlias' str of
Nothing -> Nothing
Just (key, xs) -> case runParser parseAliasValue xs of
Nothing -> Nothing
Just (value, ys) -> Just (Alias.Alias key value, ys)

replaceAliasInString :: Alias.Alias -> String -> String
replaceAliasInString _ [] = []
replaceAliasInString (Alias.Alias key value) (x:xs)
| take (length key) (x:xs) == key =
value ++ replaceAliasInString
(Alias.Alias key value)
(drop (length key) (x:xs))
| otherwise = x : replaceAliasInString (Alias.Alias key value) xs

replaceAlias :: Alias -> [Expression] -> [Expression]
replaceAlias _ [] = []
replaceAlias alias ((Expression.Alias _):xs) =
replaceAlias alias xs
replaceAlias (Alias.Alias key value) ((Expression.Function str):xs) =
(Expression.Function (replaceAliasInString (Alias.Alias key value) str))
: (replaceAlias (Alias.Alias key value) xs)
replaceAlias (Alias.Alias key value) ((Expression.Comment str):xs) =
(Expression.Comment (replaceAliasInString (Alias.Alias key value) str))
: (replaceAlias (Alias.Alias key value) xs)

replaceAllAlias :: [Alias] -> [Expression] -> [Expression]
replaceAllAlias [] exprs = exprs
replaceAllAlias _ [] = []
replaceAllAlias (x:xs) exprs = replaceAllAlias xs newExprs
where
newExprs = replaceAlias x exprs

getListAlias :: [Expression] -> [Alias]
getListAlias [] = []
getListAlias ((Expression.Alias str):xs) = case runParser parseAlias str of
Just (alias, _) -> alias : getListAlias xs
Nothing -> getListAlias xs
getListAlias (_:xs) = getListAlias xs

proceedAlias :: [Expression] -> [Expression]
proceedAlias exprs = replaceAllAlias lstAlias exprs
where
lstAlias = getListAlias exprs
38 changes: 33 additions & 5 deletions lvtc/test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Test.Tasty.HUnit

import Expression
import Parser
import Alias

import UTParseLvt
import UTShuntingYard
Expand All @@ -23,7 +24,8 @@ tests = testGroup "Leviator Tests - Compiler"
utParserExpression,
utParserExpressions,
utParserLvt,
utShuntingYard
utShuntingYard,
utAlias
]

testParserHelper :: String -> String -> Expression -> IO ()
Expand Down Expand Up @@ -66,7 +68,7 @@ utParserExpression = testGroup "Parse Expression"
testParserHelper
"alias abc def;\n"
""
(Alias "alias abc def;\n")
(Expression.Alias "alias abc def;\n")
, testCase "alias bad formated (no end `\\n`)" $
testParserHelperFail
"alias abc def;"
Expand Down Expand Up @@ -130,16 +132,42 @@ utParserExpressions = testGroup "Parse Expressions"
testParserHelpers
"alias abc def;\nalias def def;\n"
""
[Alias "alias abc def;\n", Alias "alias def def;\n"]
[Expression.Alias "alias abc def;\n", Expression.Alias "alias def def;\n"]
, testCase "alias multiline" $
testParserHelpers
"alias abc def\nefg hij;\n"
""
[Alias "alias abc def\nefg hij;\n"]
[Expression.Alias "alias abc def\nefg hij;\n"]
-- comment
, testCase "comment" $
testParserHelpers
"// this is a comment\nalias abc def;\n"
""
[Comment "// this is a comment\n", Alias "alias abc def;\n"]
[Comment "// this is a comment\n", Expression.Alias "alias abc def;\n"]
]

utAlias :: TestTree
utAlias = testGroup "Alias"
[
testCase "alias" $
assertEqual "alias"
[
Expression.Function "fn main() -> Int \n{\n <- 0;\n};"
]
(proceedAlias [
Expression.Alias "alias int Int;\n",
Expression.Alias "alias retValue 0;\n",
Expression.Function "fn main() -> int \n{\n <- retValue;\n};"
])
, testCase "nested alias" $
assertEqual "alias nested"
[
Expression.Function "fn main() -> Int \n{\n <- 0;\n};"
]
(proceedAlias [
Expression.Alias "alias int INT;\n",
Expression.Alias "alias retValue 0;\n",
Expression.Alias "alias INT Int;\n",
Expression.Function "fn main() -> int \n{\n <- retValue;\n};"
])
]
17 changes: 17 additions & 0 deletions lvtext/vscode/leviator-lang/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// A launch configuration that launches the extension inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
]
}
]
}
3 changes: 3 additions & 0 deletions lvtext/vscode/leviator-lang/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode/**
.vscode-test/**
.gitignore
13 changes: 13 additions & 0 deletions lvtext/vscode/leviator-lang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## About

Extension to enable syntax highlighting for [Leviator](https://github.com/X-R-G-B/Leviator) in [Visual Studio Code](https://code.visualstudio.com/).

## Installation

1. Find your vscode extension directory (default: `~/.vscode/extensions`)
2. Copy or move the "./lvtext/vscode/leviator-lang" directory into the vscode extension directory
3. Reload vscode

## Usage

Open a Leviator file (`.lvt`) and enjoy the syntax highlighting.
Binary file added lvtext/vscode/leviator-lang/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions lvtext/vscode/leviator-lang/language-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"comments": {
// symbol used for single line comment. Remove this entry if your language does not support line comments
"lineComment": "//"
},
// symbols used as brackets
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
// symbols that are auto closed when typing
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
],
// symbols that can be used to surround a selection
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}
41 changes: 41 additions & 0 deletions lvtext/vscode/leviator-lang/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "leviator-lang",
"displayName": "Leviator Lang",
"version": "0.0.1",
"description": "Syntax highlighting for leviator lang",
"author": {
"name": "GTX",
"url": "https://github.com/X-R-G-B"
},
"icon": "assets/icon.png",
"engines": {
"vscode": "^1.85.0"
},
"publisher": "X-L-R-G-B",
"categories": [
"Programming Languages"
],
"pricing": "Free",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/X-R-G-B/Leviator"
},
"bugs": {
"url": "https://github.com/X-R-G-B/Leviator/issues"
},
"homepage": "https://github.com/X-R-G-B/Leviator/blob/main/README.md",
"contributes": {
"languages": [{
"id": "leviator",
"aliases": ["Leviator", "leviator"],
"extensions": [".lvt"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "leviator",
"scopeName": "source.lvt",
"path": "./syntaxes/leviator.tmLanguage.json"
}]
}
}
Loading

0 comments on commit c592847

Please sign in to comment.