diff options
| author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-10-25 02:39:11 +0100 |
|---|---|---|
| committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-10-25 11:38:05 +0100 |
| commit | e0bf13622b0922252439e3fa8b43df9877678d75 (patch) | |
| tree | 629c040970a3c6869a10bf3c74a853e5eed2d908 /src/parser.h | |
| parent | c4146a9e57a897c5393e1c4999110fd95208f43f (diff) | |
numbers are separate parser states and there are syntactic octal and hexadecimal constants nowHEADmaster-fmsbw-cimaster
* Instead of every digit being a stack-modifying standalone
command, there is a single continuous parser state (teco_state_number)
now - even though it has certain unique characteristics.
They are consequently documented in the ARITHMETICS AND
EXPRESSIONS chapter of sciteco(7).
* A number will therefore be rubbed out entirely by CTRL+W,
including a possible @-modifier.
* (!) Spaces within constants are no longer ignored, but will push
separate numbers to the stack instead (`1 2 3` pushes 3 numbers).
The significance of the `,` operator is thus further reduced.
* (!) You can no longer "append" to numbers on the stack as in
`Qa001` - this was never actually used and caused more confusion.
* (!) Digits outside the current radix are no longer accepted.
E.g. digit 2 after `2^R`. This feature was also never used.
* (!) Octal constants are supported with leading zeros as in C.
This works regardless of the current radix set via `8^R` or `^O`.
It remains to see whether this is actually useful or is rather
annoying (since every constant beginning with 0 is automatically
octal, you cannot left-pad arbitrary numbers with 0).
* Hexadecimal constants are supported by at-modifying them as in
`@0ff`. They must still begin with a digit 0-9 and since A-F are
valid SciTECO commands, you may need additional spaces to separate
hexadecimal constants from regular commands as in `@0ff D`.
During syntax highlighting the number style is extended back to the
at-sign.
Note: Hexadecimal constants couldn't have been realized via
`16^R` (or some shortcut) since that depends on runtime state, but
we must know during parsing whether symbols A-F are part of the
number of regular SciTECO commands.
* The new hexadecimal constants are used in the color schemes now.
Thanks to them, we no longer need workarounds like the "color.rgb"
macro.
* Since numbers don't have a dedicated terminator character, but any
letter may terminate it, the number state must behave similar to a
start state. Consequently, hexadecimal constants will currently be
auto-case-folded if you enabled this feature.
I recommend not to write hex constants in upper-case, though.
Perhaps this should be worked around with a custom process_edit_cmd()
callback.
* Test suite updated
Diffstat (limited to 'src/parser.h')
| -rw-r--r-- | src/parser.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/parser.h b/src/parser.h index 0c389cc..dc43b1c 100644 --- a/src/parser.h +++ b/src/parser.h @@ -433,6 +433,19 @@ void teco_machine_stringbuilding_escape(teco_machine_stringbuilding_t *ctx, cons void teco_machine_stringbuilding_clear(teco_machine_stringbuilding_t *ctx); /** + * Persistent state for teco_state_number_input(). + */ +typedef struct { + /** + * Syntactially determined radix (0, 8 or 16). + * In case of 0, "^R" determines the radix (10 by default). + */ + guint radix; + /** accumulator for parsing numbers */ + teco_int_t value; +} teco_machine_number_t; + +/** * Peristent state for teco_state_expectstring_input(). * * This is part of the main machine instead of being a global variable, @@ -523,6 +536,7 @@ struct teco_machine_main_t { * but it's hard to prevent memory leaks if putting them into * a common union. */ + teco_machine_number_t number; teco_machine_expectstring_t expectstring; /** * State machine for parsing Q-reg specifications. |
