All files / transpiler/data CNextMarkerDetector.ts

100% Statements 4/4
100% Branches 2/2
100% Functions 2/2
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                        13x           7x                   25x 25x          
/**
 * Detects C-Next generation markers in header files.
 *
 * Used by the C/C++ entry point feature to discover which headers
 * were generated from .cnx source files.
 */
class CNextMarkerDetector {
  /**
   * Regex to extract source path from generation marker.
   * Matches: "Generated by C-Next Transpiler from: <path>"
   */
  private static readonly SOURCE_PATH_REGEX =
    /Generated by C-Next Transpiler from:\s*(\S+)/;
 
  /**
   * Check if content contains any C-Next generation marker.
   */
  static isCNextGenerated(content: string): boolean {
    return content.includes("Generated by C-Next Transpiler");
  }
 
  /**
   * Extract the source .cnx path from a C-Next generation marker.
   *
   * @param content - File content (typically first 500 chars is sufficient)
   * @returns The source path (e.g., "led.cnx") or null if no marker found
   */
  static extractSourcePath(content: string): string | null {
    const match = this.SOURCE_PATH_REGEX.exec(content);
    return match ? match[1] : null;
  }
}
 
export default CNextMarkerDetector;