prc_comment.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // package prc_comment -- процесс комментария
  2. package prc_comment
  3. import (
  4. "fmt"
  5. "log"
  6. "plt/lev2/vm/pos"
  7. "plt/lev2/vm/state_vm"
  8. "strings"
  9. )
  10. // PrcComment -- процесс комментария
  11. type PrcComment struct {
  12. strOut string
  13. }
  14. // NewPrcComment -- возвроащает новый процесс комментария
  15. func NewPrcComment() *PrcComment {
  16. log.Println("NewPrcComment()")
  17. sf := &PrcComment{}
  18. sf.parse()
  19. return sf
  20. }
  21. // Парсит инструкции в попытке извлечь комментарий
  22. func (sf *PrcComment) parse() {
  23. vmState := state_vm.VM_State
  24. posCur := pos.PosCur
  25. posCur.IncX()
  26. vmState.RuneInc()
  27. beginPosY := posCur.GetY()
  28. begPosX := posCur.GetX()
  29. out := ""
  30. for vmState.StrCur() != ")" {
  31. if vmState.StrCur() == "\n" {
  32. posCur.NextLine()
  33. }
  34. out += vmState.StrNext()
  35. posCur.IncX()
  36. }
  37. vmState.RuneInc()
  38. out = strings.ReplaceAll(out, "\n\n", "\n")
  39. sf.strOut = fmt.Sprintf("%v:%v\t#(%v)", beginPosY, begPosX, out)
  40. }
  41. // Run -- запускает процесс (комментарий)
  42. func (sf *PrcComment) Run() {
  43. fmt.Printf("%v\n", sf.strOut)
  44. }