Commit Graph

20 Commits

Author SHA1 Message Date
Vojtech Bubnik
c2baa9ad4f PlaceholderParser: Throw if valid or invalid UTF-8 sequence
is encountered inside a code block.
2023-04-06 13:30:29 +02:00
Vojtech Bubnik
030cfaf4b3 Fix of SPE-1630 crash when referencing an invalid variable name
using the old placeholder parser syntax.
Also implemented unescaping of \r\n\"\\ in string syntax.
2023-04-06 10:40:20 +02:00
Vojtech Bubnik
f591c2503a PlaceholderParser: changed the syntax of if inside a {} block to
{if condition then block elsif}
The "then" keyword is now mandatory.
On the other hand, "then" keyword must NOT be used using old syntax:
{if condition}...{endif}
2023-03-27 15:36:14 +02:00
Vojtech Bubnik
a53070f5e6 PlaceholderParser: Simpler if / elsif / else / endif syntax.
{if cond1}{expr1}{elsif cond2}{expr2}{else}{expr3}{endif}
could be written as
{if cond1;expr1;elsif cond2;expr2;else;expr3;endif}
the first semicolon after else is not manadtory, thus the following is valid
{if cond1;expr1;elsif cond2;expr2;else expr3;endif}
each expression could be also empty or contain multiple expressions:
{if cond1;elsif cond2;else endif}
2023-03-24 16:35:53 +01:00
Vojtech Bubnik
5b115b7972 PlaceholderParser: Implemented skipping of inactive if / else / endif
and ternary operator branches, thus missing variables or addressing
outside of the variable range in an inactive branch will not trigger
an error.
2023-03-24 13:55:58 +01:00
Vojtech Bubnik
9cb50e6586 PlaceholderParser: added size() and empty() functions over vector variables. 2023-03-23 17:51:37 +01:00
Vojtech Bubnik
929a0eba2c PlaceholderParser: replaced the new "array" operator with "repeat",
simplified the parser a bit more.
2023-03-23 17:08:56 +01:00
Vojtech Bubnik
c28585ab7f WIP PlaceholderParser: Support for local and global variables.
Implements #4048 #7196

Syntax:

(global|local) variable_name =
	(scalar_expression|vector_variable|array_expr|initializer_list)

array_expr := array(repeat, value)
initializer_list := (value, value, value, ...)

The type of the newly created variable is defined by the type
of the right hand side intitializer.

Newly declared variable must not override an existing variable.
Variable may be assigned with global|local expression, but its type
must not be changed.

Newly the assignment operator also accepts the same right hand expressions
as the global|local variable definition.
2023-03-22 17:46:57 +01:00
Vojtech Bubnik
963ca415d4 PlaceholderParser: new interpolate_table() "function"
interpolate_table(x, (x0, y0), (x1, y1), (x2, y2), ...)
interpolates a table at position x.
2023-03-22 17:46:57 +01:00
Vojtech Bubnik
7afabcde95 PlaceholderParser: Implemented one_of() matching function:
1st parameter is the text to match against,
the rest of the parameters are pattern to be matched:
either strings, then the match is exact,
or regex enclosed in //
or regex string starting with ~

For example
one_of("a", "a", "b")
	finds a in "a", "b"
one_of("abc", /.*a.*/)
	matches "abc" using regular expression /.*a.*/
2023-03-20 15:55:18 +01:00
Vojtech Bubnik
b9d8fe7118 WIP: PlaceholderParser support for writable output variables. 2023-03-20 07:48:38 +01:00
PavelMikus
5b0c270b30 Merge remote-tracking branch 'origin/master' into pm_anchor_bridges_on_sparse_infill 2023-03-01 16:45:26 +01:00
Vojtech Bubnik
55533397f9 PlaceholderPareser: new is_null() function to test whether a variable
has a "nil" value or not.
Implements SPE-1539
2023-02-28 18:30:04 +01:00
Vojtech Bubnik
1a5533d571 PlaceholderParser:
1) Implemented access to coEnum values, they are returned as strings.
2) Fixed some possible memory leaks.
3) Fixed some possible union type punning issues.
2023-01-04 13:38:18 +01:00
Vojtech Bubnik
3216448bbc PlaceholderParser: implemented round(), digits() and zdigits() macros.
round() rounds to an integer.
This is a popular request, for example #3472

digits(value, num_digits, num_decimals) rounds to num_digits and
	num_decimals, left filled with spaces.
digits(value, num_digits) the same as digits(value, num_digits, 0)
    Neither decimal separator nor any decimals after decimal separator
    are emitted.
zdigits(...) is the same as digits(...) only left filled with zeros.
If the result does not fit num_digits, the result is never trimmed.
2021-10-29 13:36:26 +02:00
Vojtech Bubnik
0f3cabb5d9 Support for forward compatibility of configurations, user and system
config bundles, project files (3MFs, AMFs). When loading these files,
the caller may decide whether to substitute some of the configuration
values the current PrusaSlicer version does not understand with
some reasonable default value, and whether to report it. If substitution
is disabled, an exception is being thrown as before this commit.
If substitution is enabled, list of substitutions is returned by the
API to be presented to the user. This allows us to introduce for example
new firmware flavor key in PrusaSlicer 2.4 while letting PrusaSlicer
2.3.2 to fall back to some default and to report it to the user.

When slicing from command line, substutions are performed by default
and reported into the console, however substitutions may be either
disabled or made silent with the new "config-compatibility" command
line option.

Substitute enums and bools only.  Allow booleans to be parsed as
    true: "1", "enabled", "on" case insensitive
    false: "0", "disabled", "off" case insensitive
This will allow us in the future for example to switch the draft_shield
boolean to an enum with the following values: "disabled" / "enabled" / "limited".

Added "enum_bitmask.hpp" - support for type safe sets of options.
See for example PresetBundle::load_configbundle(...
LoadConfigBundleAttributes flags) for an example of intended usage.

WIP: GUI for reporting the list of config substitutions needs to be
implemented by @YuSanka.
2021-06-27 16:57:05 +02:00
Vojtech Bubnik
542d95a593 Fixing unit tests 2021-04-21 15:31:06 +02:00
bubnikv
059bdb4711 Implemented handling of complex ConfigOptionFloatOrPercent chains
by the PlaceholderParser.

Namely, all the options with the "ratio_over" reference are now handled
correctly by the PlaceholderParser with the exception
of the "first_layer_extrusion_width", which overrides speed of extrusions
by their respective extrusion type.

Also the various extrusion widths (extrusion_width, first_layer_extrusion_width,
external_perimeter_extrusion_width etc.) produce the same numbers
as if ran through the back-end, with the assumption of not overriding
layer height by the variable layer height editing tool or layer height
modifiers.
2020-02-04 15:27:38 +01:00
bubnikv
094cef26d4 Fix of the new PlaceholderParser int() conversion.
Fixes https://github.com/prusa3d/PrusaSlicer/pull/3271
Also some old errors (typos, UBs) were fixed.
2020-01-21 17:12:06 +01:00
bubnikv
05ea01bdcc Ported PlaceholderParser unit tests to C++. 2020-01-21 12:10:09 +01:00