Skip to content

Commit 26a815f

Browse files
author
xenxia
committed
Update README
1 parent 49768dc commit 26a815f

File tree

1 file changed

+98
-46
lines changed

1 file changed

+98
-46
lines changed

README.md

Lines changed: 98 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ parser = TemplateStr(functionList: list, variableDict: dict)
2828
<ul>
2929
<li>
3030
<details>
31-
<summary><code>functionList</code>: is a list of Functions you want to pass to be called in your text</summary><br>
31+
<summary><code>functionList</code>: is an list of functions passed to the constructor that can be called in the parsed text</summary><br>
3232

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

4343
```python
4444
varDict: dict = {
45-
"Build": "Succes",
46-
"var": "int",
45+
"foo": "bar",
4746
"str": "Jame",
4847
"int": 32,
4948
"float": 4.2,
5049
"bool": True,
51-
"lower": "azerty",
52-
"upper": "AZERTY",
53-
"swap": "AzErTy",
5450
"list": ["test", 42],
5551
"Dict": {"value": "Dict in Dict"},
56-
"MasterDict": {"SecondDict": {"value": "Dict in Dict in Dict"}},
52+
"Dict1": {"Dict2": {"value": "Dict in Dict in Dict"}},
5753
}
5854
```
5955

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

89-
The syntax of the Variables is like if :
85+
The syntax of the Variables is like :
9086
- `${variable}`
9187
- `${Map.value}`
9288
- `${MasterMap.SecondMap.value. ...}`
93-
- `${list[0]}`
89+
- `${variable[0]}`</br></br>
9490

95-
if the value does not exist then `None` is return
91+
If the value does not exist an error is returned
9692

9793
<!-- V Be careful, it's not a "go" code, it's just to have some colour in the rendering -->
9894
```go
95+
//Example of parsing | is not code
96+
9997
name = "Jame"
10098

101-
"name is ${name}" => parse => "name is Jame"
99+
"name is ${name}"
100+
parse()
101+
"name is Jame"
102102
```
103103

104104
</details>
@@ -108,23 +108,34 @@ name = "Jame"
108108
<summary><strong>Function</strong></summary>
109109
</br>
110110

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

113-
internal function list :
115+
Here is a list of the basic functions available :
114116

115117
- `@{uppercase; variableName}`
116118
- `@{uppercaseFirst; variableName}`
117119
- `@{lowercase; variableName}`
118120
- `@{swapcase; variableName}`
119-
- `@{time}`
120-
- `@{date}`
121-
- `@{dateTime}`
121+
- `@{time}` HH/mm/ss
122+
- `@{date}` DD/MM/YYYY
123+
- `@{dateTime}` DD/MM/YYYY HH/mm/ss</br></br>
122124

123125
<!-- V Be careful, it's not a "go" code, it's just to have some colour in the rendering -->
124126
```go
127+
//Example of parsing | is not code
128+
125129
name = "jame"
126130

127-
"name is @{uppercase; name}" => parse => "name is JAME"
131+
"name is @{uppercase; name}"
132+
parse()
133+
"name is JAME"
134+
//=================================
135+
136+
"what time is it ? it's @{time}"
137+
parse()
138+
"what time is it ? it's 15:30:29"
128139
```
129140

130141
</details>
@@ -135,13 +146,25 @@ name = "jame"
135146
<summary><strong>Custom Function</strong></summary>
136147
</br>
137148

138-
The syntax of the Custom Function is like if : `@{customFunction; param1 param2 ...}` or `@{customFunction}`
149+
The syntax of Custom function is the same as the basic functions, they can have 0,1 or more parameters :
150+
- `@{customFunction; param1 param2 variableName ...}`
151+
- `@{customFunction}`</br></br>
152+
153+
The developer who adds his own function will have to document it
139154

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

142157
For developers :
143158
- Parameters to be passed in a `list/vec/array`
144-
- The custom function must necessarily return a `str/string`
159+
- The custom function must necessarily return a `str/string`</br></br>
160+
161+
```python
162+
def YourFunction(array: list) -> str:
163+
164+
# Your code
165+
166+
return str
167+
```
145168

146169
</details>
147170
</li>
@@ -151,34 +174,38 @@ For developers :
151174
<summary><strong>Condition</strong></summary>
152175
</br>
153176

154-
The syntax of the Condition is like if :
155-
- `#{value1 == value2; trueValue | falseValue}`
156-
177+
The syntax of the Condition is like :
178+
- `#{value1 == value2; trueValue | falseValue}`</br></br>
179+
157180
comparator:
158181
- `==`
159182
- `!=`
160183
- `<=` *
161184
- `<` *
162185
- `>=` *
163186
- `>` *
164-
187+
</br></br>
165188
<details>
166-
<summary>* for this comparator the type <code>string</code> and <code>bool</code> are modified :</summary>
189+
<summary>* <i>for this comparator the type <code>string</code> and <code>bool</code> are modified</i> :</summary>
167190

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

171-
</details></br>
194+
</details>
172195

173196
`value1` is compared with `value2`
174197

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

177200
<!-- V Be careful, it's not a "go" code, it's just to have some colour in the rendering -->
178201
```go
202+
//Example of parsing | is not code
203+
179204
name = "Jame"
180205

181-
"Jame is equal to James ? #{name == 'James'; Yes | No}" => parse => "Jame is equal to James ? No"
206+
"Jame is equal to James ? #{name == 'James'; Yes | No}"
207+
parse()
208+
"Jame is equal to James ? No"
182209
```
183210

184211
</details>
@@ -189,28 +216,37 @@ name = "Jame"
189216
<summary><strong>Switch</strong></summary>
190217
</br>
191218

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

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

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

202-
syntaxe for specify type `variableName` :
203-
- `str`
204-
- `int`
205-
- `float`
230+
syntax to specify the type of `variableName` :
231+
- `str/variableName`
232+
- `int/variableName`
233+
- `float/variableName`</br></br>
206234

207235
<!-- V Be careful, it's not a "go" code, it's just to have some colour in the rendering -->
208236
```go
237+
//Example of parsing | is not code
238+
209239
name = "Jame"
210240
yearsOld = 36
211241

212-
"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"
213-
"who at 36 years old ? ?{int/yearsOld; 42::Jame !, 36::William !, _::I don't know}" => parse => "who at 42 years old ? William !"
242+
"how old is Jame ? ?{name; Jame::42 years old, William::36 years old, _::I don't know}"
243+
parse()
244+
"how old is Jame ? 42 years old"
245+
//=================================
246+
247+
"who at 36 years old ? ?{int/yearsOld; 42::Jame !, 36::William !, _::I don't know}"
248+
parse()
249+
"who at 42 years old ? William !"
214250
```
215251

216252
</details>
@@ -219,14 +255,30 @@ yearsOld = 36
219255

220256
### Syntaxe Typing :
221257

222-
| Format | Type | Note | Return |
223-
|------------------------------|---------|-------------------------------------------------------------------------|------------------------|
224-
| variableName | `*` | Is the key of the value in the dictionary pass to the constructor | value of `variableName`|
225-
| b/True | `bool` | Type the string True as `bool` | True |
226-
| i/123 | `int` | Type the string 123 as type `int` | 123 |
227-
| f/123.4 | `float` | Type the string 123.4 as type `float` | 123.4 |
228-
| "text" or 'text' or \`text\` | `str` | It just takes what's in quote, not to be interpreted as a variable name | text |
229-
| ("test", i/56) | `list` | Use typing for typed otherwise text will be used as variable name | ("test", 56) |
258+
| Format | Type | Return | Note |
259+
|------------------------------|---------|------------------------|-------------------------------------------------------------------------|
260+
| variableName | `*` | value of `variableName`| Is the key of the value in the dictionary pass to the constructor |
261+
| b/True | `bool` | True | Type the string True as `bool` |
262+
| i/123 | `int` | 123 | Type the string 123 as type `int` |
263+
| f/123.4 | `float` | 123.4 | Type the string 123.4 as type `float` |
264+
| "text" or 'text' or \`text\` | `str` | text | It just takes what's in quote, not to be interpreted as a variable name |
265+
| ("test", i/56) | `list` | [test 56] | Use typing for typed otherwise text will be used as variable name |
266+
267+
```diff
268+
269+
This function takes as parameters a Bool, Int and String
270+
+ @{MyCustomFunction; b/True i/15 "foo"}
271+
- @{MyCustomFunction; True 15 foo}
272+
273+
274+
+ #{"test" == "test"; Yes | No}
275+
+ #{"56" == i/56; Yes | No}
276+
- #{foo == 56; Yes | No}
277+
278+
```
279+
280+
### More
281+
If you want another example you can look in the test file (`test_TemplateStr.py`)
230282

231283
### TODO
232284

0 commit comments

Comments
 (0)