File: SemanticWalker.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (71 lines) | stat: -rw-r--r-- 4,085 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 This source file is part of the Swift.org open source project

 Copyright (c) 2021 Apple Inc. and the Swift project authors
 Licensed under Apache License v2.0 with Runtime Library Exception

 See https://swift.org/LICENSE.txt for license information
 See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

/// An interface for walking a ``Semantic`` tree without altering it.
public protocol SemanticWalker: SemanticVisitor where Result == Void {
    mutating func descendIntoChildren(of semantic: Semantic)
}

extension SemanticWalker {
    /// Walks the children of the given semantic node.
    public mutating func descendIntoChildren(of semantic: Semantic) {
        for child in semantic.children {
            visit(child)
        }
    }
    /// Visits a code block.
    mutating func visitCode(_ code: Code) { descendIntoChildren(of: code) }
    /// Visits a list of tutorial steps.
    mutating func visitSteps(_ steps: Steps) { descendIntoChildren(of: steps) }
    /// Visits a single step in a tutorial.
    mutating func visitStep(_ step: Step) { descendIntoChildren(of: step) }
    /// Visits a section of a tutorial.
    mutating func visitTutorialSection(_ tutorialSection: TutorialSection) { descendIntoChildren(of: tutorialSection) }
    /// Visits a tutorial.
    mutating func visitTutorial(_ tutorial: Tutorial) { descendIntoChildren(of: tutorial) }
    /// Visits an intro section in a tutorial.
    mutating func visitIntro(_ intro: Intro) { descendIntoChildren(of: intro) }
    /// Visits an Xcode requirement for a tutorial.
    mutating func visitXcodeRequirement(_ requirement: XcodeRequirement) { descendIntoChildren(of: requirement) }
    /// Visits a list of assessments.
    mutating func visitAssessments(_ assessments: Assessments) { descendIntoChildren(of: assessments) }
    /// Visits a multiple-choice question.
    mutating func visitMultipleChoice(_ multipleChoice: MultipleChoice) { descendIntoChildren(of: multipleChoice) }
    /// Visits an assessment justification.
    mutating func visitJustification(_ justification: Justification) { descendIntoChildren(of: justification) }
    /// Visits a single choice in a multiple-choice question.
    mutating func visitChoice(_ choice: Choice) { descendIntoChildren(of: choice) }
    /// Visits a node that contains markup.
    mutating func visitMarkupContainer(_ markupContainer: MarkupContainer) { descendIntoChildren(of: markupContainer) }
    /// Vists a section that contains a list of resources.
    mutating func visitResources(_ resources: Resources) { descendIntoChildren(of: resources) }
    /// Visits a resources section tile.
    mutating func visitTile(_ tile: Tile) { descendIntoChildren(of: tile) }
    /// Visits a comment node.
    mutating func visitComment(_ comment: Comment) { descendIntoChildren(of: comment) }
    /// Visits a tutorials technology.
    mutating func visitTechnology(_ technology: Technology) { descendIntoChildren(of: technology) }
    /// Visits an image node.
    mutating func visitImageMedia(_ imageMedia: ImageMedia) { descendIntoChildren(of: imageMedia) }
    /// Visits a video node.
    mutating func visitVideoMedia(_ videoMedia: VideoMedia) { descendIntoChildren(of: videoMedia) }
    /// Visits a media and content tuple.
    mutating func visitContentAndMedia(_ contentAndMedia: ContentAndMedia) { descendIntoChildren(of: contentAndMedia) }
    /// Visits a tutorials volume.
    mutating func visitVolume(_ volume: Volume) { descendIntoChildren(of: volume) }
    /// Visits a tutorials chapter.
    mutating func visitChapter(_ chapter: Chapter) { descendIntoChildren(of: chapter) }
    /// Visits a tutorial reference.
    mutating func visitTutorialReference(_ tutorialReference: TutorialReference) { descendIntoChildren(of: tutorialReference) }
    /// Visits a tutorial in article form.
    mutating func visitTutorialArticle(_ tutorialArticle: TutorialArticle) { descendIntoChildren(of: tutorialArticle) }
    /// Visits a content stack.
    mutating func visitStack(_ stack: Stack) { descendIntoChildren(of: stack) }
}