• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rokucommunity / brighterscript / #13787

31 Jan 2024 09:27PM UTC coverage: 88.178% (-0.2%) from 88.331%
#13787

push

TwitchBronBron
0.65.21

5869 of 7140 branches covered (82.2%)

Branch coverage included in aggregate %.

8698 of 9380 relevant lines covered (92.73%)

1683.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/src/preprocessor/Chunk.ts
1
import type { Token } from '../lexer/Token';
2
import type { Range } from 'vscode-languageserver';
3
import util from '../util';
1✔
4

5
/**
6
 * A set of operations that must be implemented to properly handle conditional compilation chunks.
7
 *
8
 */
9
export interface Visitor {
10
    visitBrightScript(chunk: BrightScriptChunk): Token[];
11
    visitDeclaration(chunk: DeclarationChunk): Token[];
12
    visitIf(chunk: HashIfStatement): Token[];
13
    visitError(chunk: ErrorChunk): never;
14
}
15

16
/**
17
 * The base construct of the conditional-compilation preprocessor. Represents one of many things,
18
 * but typically has a one-to-many relationship with tokens in the input BrightScript files.
19
 */
20
export interface Chunk {
21
    accept(visitor: Visitor): Token[];
22
}
23

24
/** A series of BrightScript tokens that will be parsed and interpreted directly. */
25
export class BrightScriptChunk implements Chunk {
1✔
26
    constructor(readonly tokens: Token[]) { }
1,988✔
27

28
    accept(visitor: Visitor) {
29
        return visitor.visitBrightScript(this);
1,954✔
30
    }
31
}
32

33
/**
34
 * A conditional compilation directive that declares a constant value that's in-scope only during
35
 * preprocessing.
36
 *
37
 * Typically takes the form of:
38
 *
39
 * @example
40
 * #const foo = true
41
 */
42
export class DeclarationChunk implements Chunk {
1✔
43
    constructor(readonly name: Token, readonly value: Token) { }
8✔
44

45
    accept(visitor: Visitor) {
46
        return visitor.visitDeclaration(this);
6✔
47
    }
48
}
49

50
/**
51
 * The combination of a conditional compilation value (or identifier) and the chunk to include if
52
 * `condition` evaluates to `true`.
53
 */
54
export interface HashElseIfStatement {
55
    condition: Token;
56
    thenChunks: Chunk[];
57
}
58

59
/**
60
 * A directive that adds the "conditional" to "conditional compilation". Typically takes the form
61
 * of:
62
 *
63
 * @example
64
 * #if foo
65
 *     someBrightScriptGoesHere()
66
 * #else if bar
67
 *     compileSomeOtherCode()
68
 * #else
69
 *     otherwise("compile this!")
70
 * #end if
71
 */
72
export class HashIfStatement implements Chunk {
1✔
73
    constructor(
74
        readonly condition: Token,
17✔
75
        readonly thenChunks: Chunk[],
17✔
76
        readonly elseIfs: HashElseIfStatement[],
17✔
77
        readonly elseChunks?: Chunk[]
17✔
78
    ) { }
79

80
    accept(visitor: Visitor) {
81
        return visitor.visitIf(this);
14✔
82
    }
83
}
84

85
/**
86
 * A forced BrightScript compilation error with a message attached.  Typically takes the form of:
87
 *
88
 * @example
89
 * #error Some message describing the error goes here.
90
 */
91
export class ErrorChunk implements Chunk {
1✔
92
    constructor(
93
        readonly hashError: Token,
1✔
94
        readonly message: Token
1✔
95
    ) {
96
        this.range = util.createRangeFromPositions(
1✔
97
            this.hashError.range.start,
98
            (this.message ?? this.hashError).range.end
3!
99
        );
100
    }
101
    public readonly range: Range;
102

103
    accept(visitor: Visitor) {
104
        return visitor.visitError(this);
×
105
    }
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc