html.l 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. (def html-parse-state 0)
  2. ; 0: in text
  3. ; 1: in tag
  4. ; 2: whitespace
  5. (def html-parse (fn raw (do
  6. (def i 0)
  7. (def j 0)
  8. (def k 0)
  9. (def l 0)
  10. (def rsz (usize raw))
  11. (def out (alloc-str rsz))
  12. (def html-tag (alloc-str 10))
  13. (while (lt i rsz) (do
  14. (def c (uget raw i))
  15. (if (= html-parse-state 0)
  16. (if (= c 60)
  17. (def html-parse-state 1)
  18. (if (or (= c 10) (= c 32))
  19. (do
  20. (uput out j c)
  21. (def j (+ j 1))
  22. (def l (+ l 1))
  23. (def html-parse-state 2)
  24. )
  25. (do
  26. (uput out j c)
  27. (def j (+ j 1))
  28. (def l (+ l 1))
  29. )))
  30. (if (= html-parse-state 1)
  31. (if (= c 62)
  32. (def html-parse-state 0)
  33. 0)
  34. (if (= html-parse-state 2)
  35. (if (not (or (= c 32) (= c 10)))
  36. (if (= c 60)
  37. (def html-parse-state 1)
  38. (do
  39. (def html-parse-state 0)
  40. (uput out j c)
  41. (def j (+ j 1))
  42. (def l (+ l 1))
  43. )) 0)
  44. 0)))
  45. (def i (+ i 1))
  46. (if (and (= c 32) (gt l 80)) (do
  47. (uput out j 10)
  48. (def j (+ j 1))
  49. (def l 0)
  50. ) 0)
  51. ))
  52. out
  53. )))