markupfsm.h.rl6 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. %%{
  2. machine ParseXml;
  3. action startText {
  4. l = p;
  5. }
  6. action endText {
  7. cb->DoText(TStringBuf(l + 1, p));
  8. }
  9. action startSTag {
  10. l = p;
  11. }
  12. action endSTag {
  13. cb->DoTagOpen(TStringBuf(l, p));
  14. }
  15. action startETag {
  16. l = p;
  17. }
  18. action endETag {
  19. cb->DoTagClose(TStringBuf(l, p));
  20. }
  21. action startKey {
  22. l = p;
  23. }
  24. action endKey {
  25. cb->DoAttrKey(TStringBuf(l, p));
  26. }
  27. action startValue {
  28. l = p;
  29. }
  30. action endValue {
  31. cb->DoAttrValue(TStringBuf(l, p));
  32. }
  33. spacesym = [ \r\n\t];
  34. gsym = (spacesym | '<' | '>' | '/');
  35. sym = any -- gsym;
  36. asym = sym -- ('=' | '"');
  37. tag = sym+;
  38. xattrkey = asym+;
  39. xattrval = asym*;
  40. xspace = spacesym*;
  41. mspace = spacesym+;
  42. attr = (xattrkey >startKey %endKey) '=' '"' (xattrval >startValue %endValue) '"';
  43. attrs = (mspace attr)*;
  44. text = ('>' (any -- '<')*) >startText %endText;
  45. stag = '<' xspace (tag >startSTag %endSTag) attrs xspace;
  46. etag = '<' xspace '/' xspace (tag >startETag %endETag) xspace;
  47. main := spacesym* ((stag | etag) text)*;
  48. }%%
  49. #if defined(MACHINE_DATA)
  50. #undef MACHINE_DATA
  51. %%{
  52. write data;
  53. }%%
  54. #endif
  55. #if defined(MACHINE_INIT)
  56. #undef MACHINE_INIT
  57. %%{
  58. write init;
  59. }%%
  60. #endif
  61. #if defined(MACHINE_EXEC)
  62. #undef MACHINE_EXEC
  63. %%{
  64. write exec;
  65. }%%
  66. #endif