Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
xenxia committed May 5, 2023
1 parent 49768dc commit 26a815f
Showing 1 changed file with 98 additions and 46 deletions.
144 changes: 98 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ parser = TemplateStr(functionList: list, variableDict: dict)
<ul>
<li>
<details>
<summary><code>functionList</code>: is a list of Functions you want to pass to be called in your text</summary><br>
<summary><code>functionList</code>: is an list of functions passed to the constructor that can be called in the parsed text</summary><br>

```python
funcs: list = [meCustomFunc, otherCustomFunc]
Expand All @@ -38,22 +38,18 @@ funcs: list = [meCustomFunc, otherCustomFunc]
</li>
<li>
<details>
<summary><code>variableDict</code>: is a dictionary of the Variables you want to pass to be called in your text</summary><br>
<summary><code>variableDict</code>: is a dict of variables passed to the constructor that can be used in the parsed text</summary><br>

```python
varDict: dict = {
"Build": "Succes",
"var": "int",
"foo": "bar",
"str": "Jame",
"int": 32,
"float": 4.2,
"bool": True,
"lower": "azerty",
"upper": "AZERTY",
"swap": "AzErTy",
"list": ["test", 42],
"Dict": {"value": "Dict in Dict"},
"MasterDict": {"SecondDict": {"value": "Dict in Dict in Dict"}},
"Dict1": {"Dict2": {"value": "Dict in Dict in Dict"}},
}
```

Expand All @@ -71,7 +67,7 @@ parser.parse(text)
- `parseVariable(text: str) -> str` : parse Variable ; ${variableName}
- `parseFunction(text: str) -> str` : parse Function and Custom Function ; @{functionName}
- `parseCondition(text: str) -> str` : parse Condition ; #{value1 == value2; trueValue | falseValue}
- `parseSwitch(text: str) -> str` : parse Switch ; ?{var; value1:#0F0, value2:#00F, ..., _:#000}
- `parseSwitch(text: str) -> str` : parse Switch ; ?{var; value1::#0F0, value2::#00F, ..., _::#000}
- `hasOne(text: str) -> bool` : check if there are one syntaxe
- `hasVariable(text: str) -> bool` : check if there are any Variable
- `hasFunction(text: str) -> bool` : check if there are any Function
Expand All @@ -86,19 +82,23 @@ parser.parse(text)
<summary><strong>Variable</strong></summary>
</br>

The syntax of the Variables is like if :
The syntax of the Variables is like :
- `${variable}`
- `${Map.value}`
- `${MasterMap.SecondMap.value. ...}`
- `${list[0]}`
- `${variable[0]}`</br></br>

if the value does not exist then `None` is return
If the value does not exist an error is returned

<!-- V Be careful, it's not a "go" code, it's just to have some colour in the rendering -->
```go
//Example of parsing | is not code

name = "Jame"

"name is ${name}" => parse => "name is Jame"
"name is ${name}"
parse()
"name is Jame"
```

</details>
Expand All @@ -108,23 +108,34 @@ name = "Jame"
<summary><strong>Function</strong></summary>
</br>

The syntax of the Function is like if : `@{function; parameter}` or `@{function}`
The syntax of the Function is like :
- `@{function; parameter}`
- `@{function}`</br></br>

internal function list :
Here is a list of the basic functions available :

- `@{uppercase; variableName}`
- `@{uppercaseFirst; variableName}`
- `@{lowercase; variableName}`
- `@{swapcase; variableName}`
- `@{time}`
- `@{date}`
- `@{dateTime}`
- `@{time}` HH/mm/ss
- `@{date}` DD/MM/YYYY
- `@{dateTime}` DD/MM/YYYY HH/mm/ss</br></br>

<!-- V Be careful, it's not a "go" code, it's just to have some colour in the rendering -->
```go
//Example of parsing | is not code

name = "jame"

"name is @{uppercase; name}" => parse => "name is JAME"
"name is @{uppercase; name}"
parse()
"name is JAME"
//=================================

"what time is it ? it's @{time}"
parse()
"what time is it ? it's 15:30:29"
```

</details>
Expand All @@ -135,13 +146,25 @@ name = "jame"
<summary><strong>Custom Function</strong></summary>
</br>

The syntax of the Custom Function is like if : `@{customFunction; param1 param2 ...}` or `@{customFunction}`
The syntax of Custom function is the same as the basic functions, they can have 0,1 or more parameters :
- `@{customFunction; param1 param2 variableName ...}`
- `@{customFunction}`</br></br>

The developer who adds his own function will have to document it

`Syntaxe Typing` can be used at the parameter level of custom functions

For developers :
- Parameters to be passed in a `list/vec/array`
- The custom function must necessarily return a `str/string`
- The custom function must necessarily return a `str/string`</br></br>

```python
def YourFunction(array: list) -> str:

# Your code

return str
```

</details>
</li>
Expand All @@ -151,34 +174,38 @@ For developers :
<summary><strong>Condition</strong></summary>
</br>

The syntax of the Condition is like if :
- `#{value1 == value2; trueValue | falseValue}`

The syntax of the Condition is like :
- `#{value1 == value2; trueValue | falseValue}`</br></br>
comparator:
- `==`
- `!=`
- `<=` *
- `<` *
- `>=` *
- `>` *

</br></br>
<details>
<summary>* for this comparator the type <code>string</code> and <code>bool</code> are modified :</summary>
<summary>* <i>for this comparator the type <code>string</code> and <code>bool</code> are modified</i> :</summary>

- `string` it's the number of characters that is compared ('text' = 4)
- `bool` it's the value in int that is compared (True = 1)

</details></br>
</details>

`value1` is compared with `value2`

`Syntaxe Typing` can be used at `value1` and `value2` level

<!-- V Be careful, it's not a "go" code, it's just to have some colour in the rendering -->
```go
//Example of parsing | is not code

name = "Jame"

"Jame is equal to James ? #{name == 'James'; Yes | No}" => parse => "Jame is equal to James ? No"
"Jame is equal to James ? #{name == 'James'; Yes | No}"
parse()
"Jame is equal to James ? No"
```

</details>
Expand All @@ -189,28 +216,37 @@ name = "Jame"
<summary><strong>Switch</strong></summary>
</br>

The syntax of the Switch is like if :
The syntax of the Switch is like :
- `?{variableName; value1::#0F0, value2::#00F, ..., _::#000}`
- `?{type/variableName; value1::#0F0, value2::#00F, ..., _::#000}`
- `?{type/variableName; value1::#0F0, value2::#00F, ..., _::#000}`</br></br>

The value of `variableName` is compared with all the `values*`,
if a `values*` is equal to the value of `variableName` then the value after the ":" will be returned
if a `values*` is equal to the value of `variableName` then the value after the `::` will be returned.</br>
If no `values*` matches, the value after `_::` is returned

you can specify the type of `variableName`, but don't use `Syntaxe Typing`.
you can specify the type of `variableName`, but don't use `Syntaxe Typing`.</br>
If the type is specified then all `values*` will be typed with the same type.

syntaxe for specify type `variableName` :
- `str`
- `int`
- `float`
syntax to specify the type of `variableName` :
- `str/variableName`
- `int/variableName`
- `float/variableName`</br></br>

<!-- V Be careful, it's not a "go" code, it's just to have some colour in the rendering -->
```go
//Example of parsing | is not code

name = "Jame"
yearsOld = 36

"how old is Jame ? ?{name; Jame::42 years old, William::36 years old, _::I don't know}" => parse => "how old is Jame ? 42 years old"
"who at 36 years old ? ?{int/yearsOld; 42::Jame !, 36::William !, _::I don't know}" => parse => "who at 42 years old ? William !"
"how old is Jame ? ?{name; Jame::42 years old, William::36 years old, _::I don't know}"
parse()
"how old is Jame ? 42 years old"
//=================================

"who at 36 years old ? ?{int/yearsOld; 42::Jame !, 36::William !, _::I don't know}"
parse()
"who at 42 years old ? William !"
```

</details>
Expand All @@ -219,14 +255,30 @@ yearsOld = 36

### Syntaxe Typing :

| Format | Type | Note | Return |
|------------------------------|---------|-------------------------------------------------------------------------|------------------------|
| variableName | `*` | Is the key of the value in the dictionary pass to the constructor | value of `variableName`|
| b/True | `bool` | Type the string True as `bool` | True |
| i/123 | `int` | Type the string 123 as type `int` | 123 |
| f/123.4 | `float` | Type the string 123.4 as type `float` | 123.4 |
| "text" or 'text' or \`text\` | `str` | It just takes what's in quote, not to be interpreted as a variable name | text |
| ("test", i/56) | `list` | Use typing for typed otherwise text will be used as variable name | ("test", 56) |
| Format | Type | Return | Note |
|------------------------------|---------|------------------------|-------------------------------------------------------------------------|
| variableName | `*` | value of `variableName`| Is the key of the value in the dictionary pass to the constructor |
| b/True | `bool` | True | Type the string True as `bool` |
| i/123 | `int` | 123 | Type the string 123 as type `int` |
| f/123.4 | `float` | 123.4 | Type the string 123.4 as type `float` |
| "text" or 'text' or \`text\` | `str` | text | It just takes what's in quote, not to be interpreted as a variable name |
| ("test", i/56) | `list` | [test 56] | Use typing for typed otherwise text will be used as variable name |

```diff

This function takes as parameters a Bool, Int and String
+ @{MyCustomFunction; b/True i/15 "foo"}
- @{MyCustomFunction; True 15 foo}


+ #{"test" == "test"; Yes | No}
+ #{"56" == i/56; Yes | No}
- #{foo == 56; Yes | No}

```

### More
If you want another example you can look in the test file (`test_TemplateStr.py`)

### TODO

Expand Down

0 comments on commit 26a815f

Please sign in to comment.