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

rokucommunity / brighterscript / #13786

13 Mar 2024 03:54PM UTC coverage: 88.331% (+0.2%) from 88.178%
#13786

push

TwitchBronBron
0.65.26

6007 of 7278 branches covered (82.54%)

Branch coverage included in aggregate %.

8784 of 9467 relevant lines covered (92.79%)

1715.21 hits per line

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

94.44
/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[]) { }
2,028✔
27

28
    accept(visitor: Visitor) {
29
        return visitor.visitBrightScript(this);
1,988✔
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) { }
10✔
44

45
    accept(visitor: Visitor) {
46
        return visitor.visitDeclaration(this);
8✔
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,
19✔
75
        readonly thenChunks: Chunk[],
19✔
76
        readonly elseIfs: HashElseIfStatement[],
19✔
77
        readonly elseChunks?: Chunk[]
19✔
78
    ) { }
79

80
    accept(visitor: Visitor) {
81
        return visitor.visitIf(this);
16✔
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,
3✔
94
        readonly message: Token
3✔
95
    ) {
96
        this.range = util.createBoundingRange(this.hashError, this.message);
3✔
97
    }
98
    public readonly range: Range;
99

100
    accept(visitor: Visitor) {
101
        return visitor.visitError(this);
×
102
    }
103
}
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