org_lexer.l 972 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Org Mode file lexer -*-c-*- */
  2. %{
  3. /* Org Mode lexer */
  4. #include <stdio.h>
  5. #include "org_parser.h"
  6. int yywrap();
  7. /* extern int yylex (void); */
  8. extern void yyerror (char const *);
  9. %}
  10. %option header-file="org_lexer.h"
  11. /* %option reentrant */
  12. /* %option bison-bridge */
  13. /* %option bison-locations */
  14. /* %option yylineno */
  15. /* %option warn nodefault */
  16. /* %option noyywrap */
  17. /* %option bison-bridge */
  18. %x finish_line
  19. %%
  20. "\n\n\n" { /* New element detection */
  21. return NEW_ELEMENT;
  22. }
  23. "\n" {
  24. //printf ("single newline\n");
  25. return NEW_LINE;
  26. }
  27. ^[*]+" " { /* Heading Recognition */
  28. BEGIN(finish_line);
  29. return HEADING;
  30. }
  31. ^"- " {/* Plain List */
  32. BEGIN(finish_line);
  33. return LIST;
  34. }
  35. ^[0-9]+[).]?" " {/* Numbered List */
  36. BEGIN(finish_line);
  37. return NUMBERED_LIST;
  38. }
  39. ^. {/* Start of a plain line */
  40. BEGIN(finish_line);
  41. yymore();
  42. }
  43. <finish_line>.* {
  44. BEGIN(INITIAL);
  45. return TEXT;
  46. }
  47. %%
  48. int
  49. yywrap (void)
  50. {
  51. printf ("End of File \n");
  52. return 1;
  53. }