You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/tokens.rst
+9-4Lines changed: 9 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,20 +4,25 @@ Tokens are the meaningful parts of a template. A token can be required, meaning
4
4
5
5
If options are present, then one of them is the default one. Each option follows a {full_name:abbreviation} schema, so that names can be short but meaning can be recovered easily. The default option might be passed explicitly by the user by passing a *default* argument (it must match one of the options in the Token). If no default options is explicitly passed, the Token will sort options alphabetically and pick the first one. Please notice if you pass the *default* option explicitly, you can use the abbreviation or the full option name.
6
6
7
+
If fallback is defined, it will be used on required tokens if nothing is passed by the user.
8
+
7
9
.. code-block:: python
8
10
:linenos:
9
11
10
-
n.add_token('whatAffects')
12
+
n.add_token('whatLights')
13
+
n.add_token('shadowType', fallback='soft')
11
14
n.add_token_number('digits')
12
15
n.add_token('category', natural='nat',
13
16
practical='pra', dramatic='dra',
14
17
volumetric='vol', default='nat')
15
18
16
-
In line 1 we're creating a **Required Token**. This means that for solving the user must provide a value. This is a explicit solve.
19
+
In line 1 we're creating a **Required Token**. This means that in order to solve the user must provide a value, else an error will be raised. This is a explicit solve.
20
+
21
+
In line 2 we're creating a **Required Token** with a fallback. This means that if the user doesn't provide a value, the Token will solve to the fallback value. This is an implicit solve.
17
22
18
-
In line 2 we're creating a **Number Token**. This is a special Token really useful for working with version like or counting parts of a name. It's always required.
23
+
In line 3 we're creating a **Number Token**. This is a special Token really useful for working with version like or counting parts of a name. It's always required.
19
24
20
-
In line 3 we're creating an **Optional Token**, which means that for solving the user can pass one of the options in the Token or simply ignore passing a value and the Token will solve to it's default option. This is an implicit solve, which helps to greatly reduce the amount of info that needs to be passed to solve for certain cases.
25
+
In line 4 we're creating an **Optional Token**, which means that for solving the user can pass one of the options in the Token or simply ignore passing a value and the Token will solve to it's default option. This is an implicit solve, which helps to greatly reduce the amount of info that needs to be passed to solve for certain cases.
21
26
22
27
For more information on implicit and explicit solving please check :doc:`usage/solving`
Copy file name to clipboardExpand all lines: docs/source/usage/repositories.rst
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,18 +57,21 @@ When saving the session, all Tokens and Rules in memory will be saved to the rep
57
57
:linenos:
58
58
59
59
n.add_token('whatAffects')
60
+
n.add_token('shadowType', fallback='soft')
60
61
n.add_token_number('digits')
61
62
n.add_token(
62
63
'category',
63
64
natural='nat', practical='pra', dramatic='dra',
64
65
volumetric='vol', default='nat'
65
66
)
66
67
67
-
In line 1 we're creating a **Required Token**. This means that for solving the user has to provide a value. This is a explicit solve.
68
+
In line 1 we're creating a **Required Token**. This means that in order to solve the user must provide a value, else an error will be raised. This is a explicit solve.
68
69
69
-
In line 2 we're creating a **Number Token**. This is a special Token really useful for working with version like or counting parts of a name. It's always required.
70
+
In line 2 we're creating a **Required Token** with a fallback. This means that if the user doesn't provide a value, the Token will solve to the fallback value. This is an implicit solve.
70
71
71
-
In line 3 we're creating an **Optional Token**, which means that for solving the user can pass one of the options in the Token or simply ignore passing a value and the Token will solve to it's default option. This is an implicit solve, which helps to greatly reduce the amount of info that needs to be passed to solve for certain cases.
72
+
In line 3 we're creating a **Number Token**. This is a special Token really useful for working with version like or counting parts of a name. It's always required.
73
+
74
+
In line 4 we're creating an **Optional Token**, which means that for solving the user can pass one of the options in the Token or simply ignore passing a value and the Token will solve to it's default option. This is an implicit solve, which helps to greatly reduce the amount of info that needs to be passed to solve for certain cases.
72
75
73
76
For more information on implicit and explicit solving please check :doc:`solving`
@@ -45,6 +46,8 @@ It would not make any sense to make the user pass each and every Token all the t
45
46
46
47
That's why vfxnaming.solve() accepts both args and kwargs. Not only that, but if given Token is optional and you want to use it's default value, you don't need to pass it at all.
47
48
49
+
Even if you make a required tokken, you can still define a fallback value for it.
50
+
48
51
.. code-block:: python
49
52
50
53
n.solve(
@@ -57,9 +60,9 @@ That's why vfxnaming.solve() accepts both args and kwargs. Not only that, but if
57
60
Each of these calls to vfxnaming.solve() will produce the exact same result:
58
61
59
62
.. note::
60
-
natural_custom_chars_001_LGT
63
+
natural_custom_chars_soft_001_LGT
61
64
62
-
If you don't pass a required Token (either as an argument or keyword argument), such as 'whatAffects' in this example, you'll get a **TokenError**. You'll also get a **TokenError** if you try to parse a value that doesn't match any of the options in the Token.
65
+
If you don't pass a required Token (either as an argument or keyword argument), such as 'whatAffects' in this example, you'll get a **TokenError**, unless it has a fallback value defined. You'll also get a **TokenError** if you try to parse a value that doesn't match any of the options in the Token.
0 commit comments