Skip to content

Commit

Permalink
add docs and compilation one file
Browse files Browse the repository at this point in the history
  • Loading branch information
keyroll-99 committed Jun 8, 2024
1 parent 6ff760d commit b9cbdb8
Show file tree
Hide file tree
Showing 12 changed files with 411 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ The Repo will be renamed after 100 commits competition because I came up with th

Nope, maybe in the future

## Why this project's name is Fiona
Because Fiona it's the name of my dog, which one I adopted from dog shelter few days before I start this project

## OS Support

| OS | Fiona.Hosting | Fiona.Ui |
Expand Down
5 changes: 5 additions & 0 deletions docs/Blueprints.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Blueprints

This feature is under develop

This is how it's look now (at the end of the competition)
![FionaGui.png](assets/FionaGui.png)

I know it's not much, but working with new technology(blazor) defeated me
304 changes: 302 additions & 2 deletions docs/Fiona-language.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,304 @@
# Fiona language

Fina language is a special language to descripte your endpoint, usualy you will be modify this file by IDE, but If you want to you can modify it by yourself.
Fiona files will be compile to c# language
## About Fiona's language

Fina's language is a special language to describe your endpoint, usually you will be modified this file by IDE, but If
you want to you can modify it by yourself.
Fiona files will be compiled to c# language

## Why I created own script language?

for two reason

1. I wanted to learn how to make my own compiler, tokenizer etc.
2. Is much easier when I have my format to work with files than adapting to the existing one


## How I can use this language?
Unfortunately, there is currently no easy way to test this language. But if you want you can do it :)

1. Download this repo
2. Run project FionaIDE
3. Create a new project
4. Create new file in the project
5. Open this file in your favorite IDE
6. Modify file
7. Close the file in your IDE (it's important, because it can block access to file)
8. Open this file in FionaIDE
9. Click the `Compile file` button

Don't worry in the future this will not be such hard


## Usings

In the file we can have only one using section. Each section begins with the keyword `using Begin;` and finish
with `usingEnd;`.

Example of use

```csharp
usingBegin;
using system; using system.collections;
using system.collections.generic;
usingEnd;
```

## Namespace

We can define namespace by using the keyword `namespace {value};`

```csharp
namespace: Token.Test;
```

## Class define

We can define a class by using the keyword `class {name};`. In the file we can have only one class

class can have 3 fields

1. route - one per class which define global route for class
2. inject - one per class which define what should be injected to controller
3. endpoint section - list of endpoints in the class

example of use:

```csharp
class IndexController;
route: /home;
inject:
- userService: IUserService
- logger: ILogger<TestController>;
endpoint:
...
```

## Route define

We can define a route by using the keyword `route: {name};`. In the file we can have only one class

example of use:

```csharp
route: /home;
```

## Inject define

Inject work with the array, so as argument we can pass few dependencies, each element in array is separated by `-`
symbol

example of use:

```csharp
inject:
- userService: IUserService
- logger: ILogger<TestController>;
```

## Endpoint define

We can define an endpoint by using the keyword `endpoint {name};`. each endpoint always finishes with `bodyEnd` keyword

endpoint can have 5 fields, the order doesn't matter except

1. route - one per endpoint which define endpoint route
2. methods - one per endpoint which methods type for endpoint, for example GET
3. return - one per endpoint which define what endpoint should return
4. input - a list of method arguments
5. bodyBegin / bodyEnd - define where is body of method

## Route Define in method

We can define a route by using the keyword `route: {name};`. In the file we can have only one per endpoint

example of use:

## Method define

Method define works with my first attempt to array, so it have different style. Currently, we have 5 types of method
available:

1. GET
2. POST
3. PUT
4. PATCH
5. DELETE

example of use:
```
method: [GET, POST];
```

## return
We can define a route by using the keyword `return: {type};`. In the file we can have only one per endpoint

example of use
```csharp
return: User;
```

## input define

input work with the array, so as argument we can pass few parameters to method, each element in array is separated by `-`
symbol

example of use
```csharp
input:
- [FromRoute] name: string
- [QueryParam] age: int
- [Body] user: User
- [Cookie] userId: long;
```

## Body
Body is the last section in the endpoint, `bodyEnd` tag finish endpoint define. The structure of method body is:
1. bodyBegin tag which start body section
2. body section, here you can write your c# code, which one will be in the body method
3. bodyEnd which finishes body end of course finish endpoint definition

example of use:

```csharp
inject:
- userService: IUserService
- logger: ILogger<TestController>;
```

example of use:

```csharp
endpoint: Index;
route: /{name};
method: [GET, POST];
return: User;
input:
- [FromRoute] name: string
- [QueryParam] age: int
- [Body] user: User
- [Cookie] userId: long;
// Testowy komentarz
// return: Home;
bodyBegin;
var x = 10;
var y = userService.GetAge();
if(x > y)
{
return user;
}
else
{
return null;
}
bodyEnd;
```

example of use:

```csharp
class IndexController;
route: /home;
inject:
- userService: IUserService
- logger: ILogger<TestController>;
endpoint:
...

## Example

code like this:

```

usingBegin;
using Fiona.Hosting.Controller.Attributes;
using Fiona.Hosting.Routing;
using Fiona.Hosting.Routing.Attributes;
usingEnd;

namespace: comitow.LoadTest;

class IndexController;
route: /index;
inject:

- userService: IUserService
- logger: ILogger<TestController>
;
endpoint: Index;
route: /{name};
method: [GET, POST];
return: User;
input:
- [FromRoute] name: string
- [QueryParam] age: int
- [Body] user: User
- [Cookie] userId: long;
bodyBegin;
bodyEnd;

endpoint: GetUsers;
route: /{name};
method: [GET, POST];
return: User;
input:
- [FromRoute] name: string
- [QueryParam] age: int
- [Body] user: User
- [Cookie] userId: long;
// Testowy komentarz
// return: Home;
bodyBegin;
var x = 10;
var y = userService.GetAge();
if(x > y)
{
return user;
}
else
{
return null;
}
bodyEnd;

```
will be generated:
```csharp
using Fiona.Hosting.Controller.Attributes;
using Fiona.Hosting.Routing;
using Fiona.Hosting.Routing.Attributes;
namespace comitow.LoadTest;
[Controller("/index")]
public class IndexController
{
private readonly IUserService userService;
private readonly ILogger<TestController> logger;
public aaabqeq(IUserService userService, ILogger<TestController> logger)
{
this.userService = userService;
this.logger = logger;
}
[Route(HttpMethodType.Get | HttpMethodType.Post, "/{name}", ["age"])]
public async Task<User> Index([FromRoute] string name, [QueryParam] int age, [Body] User user, [Cookie] long userId) {}
[Route(HttpMethodType.Get | HttpMethodType.Post, "/{name}", ["age"])]
public async Task<User> GetUsers([FromRoute] string name, [QueryParam] int age, [Body] User user, [Cookie] long userId)
{
var x = 10;
var y = userService.GetAge();
if (x > y)
{
return user;
}
else
{
return null;
}
}
}
```
5 changes: 3 additions & 2 deletions docs/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ Welcome to Fiona's documentation, the framework is currently under active develo
1. About
1. [About](About.md)
1. [Getting started](Getting-started.md)
1. [Configuration and AppSettings](Configuration-and-AppSettings)
1. [Configuration and AppSettings](Configuration-and-AppSettings.md)
1. [Controller](Controller.md)
1. [Routing](Routing.md)
1. [Middleware](Middleware.md)
1. [Cookie](Cookie.md)
1. [Logger](Logger.md)
1. [Dependency injection](Dependency-injection.md)
1. [Fiona language](Fiona-language.md)
1. [Blueprint](Blueprints.md.md)
1. [Blueprint](Blueprints.md)
1. [Fiona's language](Fiona-language.md)

Binary file added docs/assets/FionaGui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion ide/src/Fiona.IDE.Compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ private async Task ParseFileAsync(ProjectFile projectFile)
using StreamReader reader = new(file);
IReadOnlyCollection<IToken> tokens = await Tokenizer.Tokenizer.GetTokensAsync(reader);
ReadOnlyMemory<byte> parsedContent = (await parser.ParseAsync(tokens, projectFile));
await file.WriteAsync(parsedContent);

await using FileStream csFile = File.Open($"{projectFile.Path}.cs", FileMode.Create);
await csFile.WriteAsync(parsedContent);
}

}
Expand Down
3 changes: 3 additions & 0 deletions ide/src/Fiona.IDE.Compiler/ICompiler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Fiona.IDE.ProjectManager.Models;

namespace Fiona.IDE.Compiler
{
public interface ICompiler
{
public Task RunAsync();
public Task CompileFile(ProjectFile projectFile);
}
}
8 changes: 6 additions & 2 deletions ide/src/Fiona.IDE.Compiler/Parser/Models/Parameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ internal sealed class Parameter

private Parameter(string attribute, string type, string name)
{
_attribute = attribute;
_type = type;
_name = name;

Type = attribute switch
{
"[Body]" => ParameterType.Body,
Expand All @@ -26,6 +25,11 @@ private Parameter(string attribute, string type, string name)
"[Cookie]" => ParameterType.Cookie,
_ => throw new ValidationError("Invalid parameter attribute")
};
_attribute = attribute;
if (Type == ParameterType.Path)
{
_attribute = string.Empty;// path doesn't have own attribute
}
}

public string GenerateSourceCode()
Expand Down
Loading

0 comments on commit b9cbdb8

Please sign in to comment.