XCTLNextthanStatement.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // XCTLNextthanStatement.swift
  3. // notebook
  4. //
  5. // Created by 邢铖 on 2023/5/25.
  6. //
  7. import Foundation
  8. internal class XCTLNextthanStatement: XCTLStatement {
  9. var type: XCTLStatementType { .typeNextthan }
  10. var holdingObject: XCTLRuntimeVariable { .void }
  11. weak var parent: XCTLStatement?
  12. weak var parentCond: XCTLConditionParentStatement?
  13. func matchSelfStatement(lex: XCTLLexer) throws -> XCTLStatement? {
  14. if try lex.next().type == .typeNextthan {
  15. return XCTLNextthanStatement()
  16. }
  17. return nil
  18. }
  19. func parseStatement(fromLexerToSelf lex: XCTLLexer, fromParent: XCTLStatement?) throws {
  20. self.parent = fromParent
  21. self.parentCond = (self.parent as? XCTLListStatementProtocol)?.conditionParent
  22. if self.parent == nil || self.parentCond == nil {
  23. throw XCTLCompileTimeError.unexpectParentStatementType(expect: "codeList & cond", butGot: "\(fromParent?.type.rawValue ?? "none")")
  24. }
  25. try lex.next()
  26. lex.lastStatement = self
  27. }
  28. func evaluate(inContext context: XCTLRuntimeAbstractContext) throws -> XCTLRuntimeVariable {
  29. guard let listFrame = context.findListFrame() else {
  30. throw XCTLRuntimeError.invalidListFrame
  31. }
  32. guard let condFrame = context.findConditionFrame() else {
  33. throw XCTLRuntimeError.invalidConditionFrame
  34. }
  35. listFrame.breakListEvaluate = true
  36. listFrame.breakToParagraph = false
  37. condFrame.doNext = true
  38. return .void
  39. }
  40. }