XCTLNextthanStatement.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. }
  27. func evaluate(inContext context: XCTLRuntimeAbstractContext) throws -> XCTLRuntimeVariable {
  28. guard let listFrame = context.findListFrame() else {
  29. throw XCTLRuntimeError.invalidListFrame
  30. }
  31. guard let condFrame = context.findConditionFrame() else {
  32. throw XCTLRuntimeError.invalidConditionFrame
  33. }
  34. listFrame.breakListEvaluate = true
  35. condFrame.doNext = true
  36. return .void
  37. }
  38. }