@bis-toolkit/cppparser 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # @bis-toolkit/cppparser
2
+
3
+ Parser for Arma/DayZ `config.cpp` and RVMat files.
4
+
5
+ Part of the [BIS Toolkit TypeScript](../../README.md) monorepo.
6
+
7
+ ## Features
8
+ - Lex + parse Arma config syntax (variables, arrays, enums, classes, prototypes, deletes)
9
+ - Simple preprocessor supporting `#define`, `#ifdef`/`#ifndef`, `#include` (only for node.js)
10
+ - Produces a typed AST for further processing
11
+ - RVMat file parsing (material definitions)
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @bis-toolkit/cppparser
17
+ ```
18
+
19
+ From the monorepo root for development:
20
+
21
+ ```bash
22
+ npm install
23
+ npm run build
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ Parse an already-loaded string:
29
+
30
+ ```typescript
31
+ import { Parser } from '@bis-toolkit/cppparser';
32
+
33
+ const source = 'class MyClass { value = 42; };';
34
+ const ast = new Parser(source, 'inline').parse();
35
+ console.log(ast.statements.length);
36
+ ```
37
+
38
+ Preprocess and parse a `config.cpp` from disk:
39
+
40
+ ```typescript
41
+ import { Parser, Preprocessor } from '@bis-toolkit/cppparser';
42
+ import { join } from 'path';
43
+
44
+ const configPath = join(process.cwd(), 'config.cpp');
45
+ const pre = new Preprocessor();
46
+ const text = pre.preprocess(configPath);
47
+ const ast = new Parser(text, configPath).parse();
48
+ console.log(`Statements: ${ast.statements.length}`);
49
+ ```
50
+
51
+ ## License
52
+
53
+ GPLv3 © Alpine Labs - see [LICENSE](LICENSE).
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Simple RVMAT (material) file parser
3
+ * Extracts texture paths from Stage definitions
4
+ */
5
+ export interface RvmatStage {
6
+ name: string;
7
+ texture: string;
8
+ }
9
+ export interface RvmatData {
10
+ stages: RvmatStage[];
11
+ ambient?: number[];
12
+ diffuse?: number[];
13
+ forcedDiffuse?: number[];
14
+ emmisive?: number[];
15
+ specular?: number[];
16
+ specularPower?: number;
17
+ pixelShaderID?: string;
18
+ vertexShaderID?: string;
19
+ }
20
+ export declare class RvmatParser {
21
+ /**
22
+ * Parse RVMAT file content
23
+ */
24
+ static parse(content: string, filename?: string): RvmatData;
25
+ private static findVariable;
26
+ private static extractStages;
27
+ private static findClassProperty;
28
+ private static readNumberArray;
29
+ private static readNumber;
30
+ private static readString;
31
+ private static toNumber;
32
+ private static isVariable;
33
+ private static isSimpleVariable;
34
+ private static isClass;
35
+ /**
36
+ * Get all texture paths from parsed data
37
+ */
38
+ static getTexturePaths(data: RvmatData): string[];
39
+ /**
40
+ * Get main diffuse/color texture (typically Stage1)
41
+ */
42
+ static getMainTexture(data: RvmatData): string | undefined;
43
+ }
package/dist/ast.d.ts ADDED
@@ -0,0 +1,74 @@
1
+ export type CfgNodeType = 'document' | 'variable' | 'array' | 'array-extend' | 'array-shrink' | 'enum' | 'class' | 'prototype' | 'delete';
2
+ export type CfgType = string | number | boolean | null | CfgType[];
3
+ export interface CfgBaseType {
4
+ kind: CfgNodeType;
5
+ }
6
+ /**
7
+ * Represents the root document containing all CFG statements
8
+ */
9
+ export interface CfgDocument extends CfgBaseType {
10
+ kind: 'document';
11
+ statements: CfgBaseType[];
12
+ }
13
+ export interface CfgNamedType extends CfgBaseType {
14
+ name: string;
15
+ }
16
+ /**
17
+ * Represents a simple variable in Cfg ( myVar = 42; )
18
+ */
19
+ export interface CfgSimpleVariable extends CfgNamedType {
20
+ kind: 'variable';
21
+ value: CfgType;
22
+ }
23
+ /**
24
+ * Represents a named variable in Cfg ( myVar[] = {42, "string", true}; )
25
+ */
26
+ export interface CfgArrayVariable extends CfgNamedType {
27
+ kind: 'array';
28
+ values: CfgType[];
29
+ }
30
+ /**
31
+ * Represents a class definition in Cfg ( class MyClass : BaseClass { ... }; )
32
+ */
33
+ export interface CfgClass extends CfgNamedType {
34
+ kind: 'class';
35
+ baseClassName?: string;
36
+ properties: Map<string, CfgBaseType>;
37
+ }
38
+ /**
39
+ * Represents a prototype definition in Cfg ( class MyPrototype; or class MyPrototype : BaseClass; )
40
+ */
41
+ export interface CfgPrototype extends CfgNamedType {
42
+ kind: 'prototype';
43
+ baseClassName?: string;
44
+ }
45
+ /**
46
+ * Represents an array extension in Cfg ( myArray[] += {42, "string"}; )
47
+ */
48
+ export interface CfgArrayExtend extends CfgNamedType {
49
+ kind: 'array-extend';
50
+ values: CfgType[];
51
+ }
52
+ /**
53
+ * Represents an array shrink in Cfg ( myArray[] -= {42, "string"}; )
54
+ */
55
+ export interface CfgArrayShrink extends CfgNamedType {
56
+ kind: 'array-shrink';
57
+ values: CfgType[];
58
+ }
59
+ /**
60
+ * Represents a C-style enum in Cfg ( enum MyEnum { VAL1, VAL2 = 5, VAL3 }; )
61
+ */
62
+ export interface CfgEnum extends CfgBaseType {
63
+ kind: 'enum';
64
+ members: {
65
+ name: string;
66
+ value?: number;
67
+ }[];
68
+ }
69
+ /**
70
+ * Represents a delete operation in Cfg ( delete MyClass; )
71
+ */
72
+ export interface CfgDelete extends CfgNamedType {
73
+ kind: 'delete';
74
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * RAP/CPP parser utilities
3
+ */
4
+ export { type CfgType, type CfgBaseType, type CfgDocument, type CfgSimpleVariable, type CfgArrayVariable, type CfgArrayExtend, type CfgArrayShrink, type CfgEnum, type CfgClass, type CfgPrototype, type CfgDelete, type CfgNodeType, } from './ast';
5
+ export { lex, TokenKind, isCfgKeyword, isCfgPunctuation, CfgKeywords, CfgPunctuations, CfgOperators, type CfgToken, } from './lexer';
6
+ export { Parser } from './parser';
7
+ export { Preprocessor, type PreprocessorOptions } from './preprocessor';
8
+ export { type CfgPatch, type ScriptModule, type CfgMod, type CfgMods, type CfgPatches, type ProjectFile, } from './project';
9
+ export { RvmatParser, type RvmatData, type RvmatStage } from './RvmatParser';