Mirror of espurna firmware for wireless switches and more
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.8 KiB

  1. /*
  2. Part of the IR MODULE
  3. For more info:
  4. - https://re2c.org/
  5. - https://re2c.org/manual/manual_c.html
  6. */
  7. #pragma once
  8. // TODO: some sanity checks for 'valid' ranges of the parsed values, when state machine reaches individual value decoders?
  9. ParseResult<Payload> parse(StringView view) {
  10. const char* YYCURSOR { view.begin() };
  11. const char* YYLIMIT { view.end() };
  12. const char* YYMARKER;
  13. const char *p0 = nullptr, *p1 = nullptr;
  14. const char *c0 = nullptr, *c1 = nullptr;
  15. const char *b0 = nullptr, *b1 = nullptr;
  16. const char *r0 = nullptr, *r1 = nullptr;
  17. const char *s0 = nullptr, *s1 = nullptr;
  18. const char *d0 = nullptr, *d1 = nullptr;
  19. ParseResult<Payload> out;
  20. /*!stags:re2c format = 'const char *@@{tag} { nullptr };\n'; */
  21. /*!re2c
  22. re2c:eof = 0;
  23. re2c:yyfill:enable = 0;
  24. re2c:flags:tags = 1;
  25. re2c:define:YYCTYPE = "char";
  26. re2c:define:YYFILL = "goto return_out;";
  27. dec = [0-9];
  28. val = [0-9A-Fa-f]{2,16};
  29. @p0 dec+ @p1 [:]
  30. @c0 val @c1 [:]
  31. @b0 dec+ @b1 { goto update_out; }
  32. @p0 dec+ @p1 [:]
  33. @c0 val @c1 [:]
  34. @b0 dec+ @b1 [:]
  35. @r0 dec+ @r1 { goto update_out; }
  36. @p0 dec+ @p1 [:]
  37. @c0 val @c1 [:]
  38. @b0 dec+ @b1 [:]
  39. @r0 dec+ @r1 [:]
  40. @s0 dec+ @s1 { goto update_out; }
  41. @p0 dec+ @p1 [:]
  42. @c0 val @c1 [:]
  43. @b0 dec+ @b1 [:]
  44. @r0 dec+ @r1 [:]
  45. @s0 dec+ @s1 [:]
  46. @d0 dec+ @d1 { goto update_out; }
  47. * { goto return_out; }
  48. $ { goto return_out; }
  49. */
  50. update_out:
  51. {
  52. if (!((c1 - c0) % 2)) {
  53. out = prepare(
  54. StringView{p0, p1},
  55. StringView{c0, c1},
  56. StringView{b0, b1},
  57. StringView{r0, r1},
  58. StringView{s0, s1},
  59. StringView{d0, d1});
  60. }
  61. }
  62. return_out:
  63. return out;
  64. }