Sujet : Re: Static regex for embedded systems
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.arch.embeddedDate : 21. Jan 2025, 16:40:17
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vmof51$5g9v$1@dont-email.me>
References : 1
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 21/01/2025 15:31, pozz wrote:
Many times I need to parse/decode a text string that comes from an external system, over a serial bus, MQTT, and so on.
Many times this string has a fixed syntax/layout. In order to parse this string, I everytime create a custom parser that can be tedious, cumbersom and error prone.
For example, suppose you have to decode a string from a modem that uses AT commands. Many answers from the modem has the following schema:
\r\n+<prefix>: <field1>,<field2>\r\n
\r\nOK\r\n
The prefix is known, the number and type of fileds are known too. With regex, the parser would be simple.
There are plenty of libraries for run-time regular expressions - they have been in the C++ standard library since C++11 (IIRC). But run-time parsing of regex strings and matching for the input string will be very time and space costly in a small embedded system. You want compile-time regular expression handling.
This had been planned for inclusion in C++23 (and therefore part of the current GNU ARM Embedded toolchain, if that's what you are using), but it didn't make it. However, there are standalone compile-time regex libraries for C++ using templates and compile-time functions, which will in effect generate specialised parsers from the regex strings.