Add M05_PreProcessor module to handle value mapping and condition simplification for "接头" category before parsing. Features: - Value mapping: azxs codes (A0/AT/AH→径向, B0/BT/BZ/BH→下轴向, Z0/ZT/ZZ/ZH→中轴向) and lcfw ranges (M01-M11→低压, M12-M16→高压) - OR condition merging: automatically removes duplicate OR segments - Smart parentheses handling: removes parentheses for single atoms, preserves them when needed for logical structure - Recursive nested expression processing - Graceful degradation when "对照表" worksheet is missing Integration: - Modified M01_Main to initialize preprocessor after M03_Logic - Preprocessing applied only for "接头" category - Updated M99_TestRunner with 8 comprehensive test cases - All tests passing (50 total: 42 core + 8 preprocessing) Documentation: - Added detailed flow documentation for Test_PP_06_FullIntegration with mermaid diagrams in docs/Test_PP_06_FullIntegration_流程详解.md - Updated CLAUDE.md with preprocessing module description and documentation guidelines (docs/ vs reference_docs/) Example transformation: Input: gclj=M16 AND (azxs=A0 OR azxs=AT) AND (lcfw=M01 OR lcfw=M15) Output: gclj=M16 AND azxs=径向 AND (lcfw=低压 OR lcfw=高压) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
8.2 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
AutoBOM is an Excel-based Bill of Materials (BOM) management system for pressure product manufacturing. It uses VBA macros to parse conditional logic rules and generate categorized BOM configurations from Excel spreadsheets.
Architecture
Core VBA Modules (VBA/Modules/)
The system follows a modular architecture with clear separation of concerns:
- M01_Main.bas - Entry point and orchestration. Run
RunBOMConversion()to execute the full workflow. - M02_DataIO.bas - Data input/output operations. Reads source data from "平台配置清单" worksheet and generates categorized output workbooks.
- M03_Logic.bas - Core recursive parser for conditional expressions. Handles logical operators (AND/OR), nested parentheses, and key=value/key!=val conditions. Implements Cartesian products for set operations.
- M04_Config.bas - Column mapping and header priorities. Defines source data columns (CODE, NAME, QTY, CONDITION, CATEGORY) and standard ordering for output.
- M05_PreProcessor.bas - Preprocessing module for condition transformation. Handles value mapping for "接头" category (e.g., azxs=A0→径向, lcfw=M01→低压), duplicate OR condition merging, and nested expression simplification. Uses mapping data from "对照表" worksheet.
- M99_TestRunner.bas - Unit testing framework. Run
RunAllTests()in VBA Immediate window to execute tests.
Class Module
- clsErrorLogger.cls - Error handling and logging. Tracks conflicts, parsing failures, and provides detailed context without stopping execution.
Data Flow
Excel "平台配置清单" → M01_Main → M02_DataIO.LoadSourceData() →
M05_PreProcessor.PreprocessCondition() → M03_Logic.ParseRule() →
Category Dictionary → M02_DataIO.CreateOutputWorkbook() →
New Excel Workbook + Error Report
Key Concepts
Preprocessing (M05_PreProcessor)
Before parsing conditions, the system applies preprocessing for "接头" (joint) category:
Value Mapping:
- azxs (安装形式): Maps codes to descriptive values
- A0, AT, AH → 径向
- B0, BT, BZ, BH → 下轴向
- Z0, ZT, ZZ, ZH → 中轴向
- lcfw (量程范围): Maps range codes to categories
- M01-M11 → 低压
- M12-M16 → 高压
OR Condition Merging:
- Duplicate OR conditions are automatically merged
- Example:
azxs=径向 OR azxs=径向→azxs=径向 - Different values preserve OR structure:
lcfw=低压 OR lcfw=高压
Parentheses Handling:
- Simplified single-value expressions:
(azxs=A0 OR azxs=AT)→azxs=径向 - Preserves parentheses when needed:
(lcfw=M01 OR lcfw=M15)→(lcfw=低压 OR lcfw=高压)
Mapping data is loaded from "对照表" worksheet (columns A:B for lcfw, D:E for azxs).
Conditional Logic Syntax
Conditions use a specific syntax for product selection:
- Atoms:
key=valueorkey!=value(e.g.,gclj=M20,jycz=1) - AND: Cartesian product of sets (e.g.,
gclj=M20 AND jycz=1) - OR: Union of sets (e.g.,
azxs=A0 OR azxs=AT) - Parentheses: Nested grouping (e.g.,
(azxs=A0 OR azxs=AT) AND jycz=1)
Example: gclj=M20 AND jycz=1 AND lcfw=M01 AND (azxs=A0 OR azxs=AT OR azxs=AH)
Column Mapping (M04_Config)
Source data must have columns in this order:
- Column C (3): CODE (代号)
- Column D (4): NAME (名称)
- Column E (5): QTY (数量)
- Column F (6): CONDITION (选择条件)
- Column H (8): CATEGORY (类别)
Data starts from row 4.
Category-Based Output
Results are automatically organized by category (部件, 接头, 弹性元件, etc.). Each category gets a separate worksheet in the output workbook with columns dynamically ordered based on detected configuration keys.
Development Commands
Running the BOM Converter
- Open
YTHN-100.xlsmin Excel - Ensure "平台配置清单" worksheet exists with proper data
- Run
M01_Main.RunBOMConversion()or execute from the Excel interface
Running Tests
In Excel VBA Immediate Window (Ctrl+G):
RunAllTests
This runs unit tests for:
- Simple atom parsing (
key=value) - AND operations with Cartesian products
- OR operations with union operations
- Nested parentheses handling
- Logic conflict detection
- Preprocessing tests (Test_PP_01 to Test_PP_08):
- azxs mapping load (12 values)
- lcfw mapping load (M01-M16)
- Value replacement
- OR condition merging
- Full integration with M03_Logic
- Non-"接头" category handling
- Unmapped value handling
Python Skills (Claude Code Integration)
The project includes custom skills in .claude/skills/:
-
excel-to-markdown: Convert Excel files to Markdown tables
python3 .claude/skills/excel-to-markdown/scripts/excel_to_markdown.py <file.xlsx> -
mermaid-diagrams: Generate architecture diagrams using Mermaid syntax
Configuration
Header Priority Ordering
Output columns are sorted according to priority defined in M04_Config.GetHeaderPriority():
- azxs (安装形式)
- bkxs (表壳形式)
- gclj (过程连接)
- jycz (介质材质)
- lcdw (量程单位)
- lcfw (量程范围)
- fjgn (非公/耐震)
- btcy (表头尺寸)
- bp (表盘)
- dskd (度视宽度)
- nqlc (耐震连接)
- bptx (表盘图形)
- jddj (精度等级)
- cpdm (产品代码)
- tsjz (特殊基准)
- tsyq (特殊要求)
- bpts (特殊表盘)
- kdxh (壳体型号)
Unknown keys are assigned priority 999 and appear last.
Git Workflow
Branches
- Main branch:
DEV_YTHN-100 - Current branch:
NEW_BOM
Claude Code Permissions
Configured in .claude/settings.local.json:
- Git operations: push, checkout, add
- Python execution
- Tree viewing and search utilities
NTFY Notifications
The repository uses NTFY for git push notifications. Repository name is extracted dynamically from github.repository in workflow files.
File Structure
AutoBOM/
├── VBA/
│ ├── Modules/ # Procedural modules (M01-M99)
│ └── ClassModules/ # OOP components (clsErrorLogger)
├── .claude/
│ └── skills/ # Claude Code integration skills
├── docs/ # Code-related documentation
│ └── Test_PP_06_FullIntegration_流程详解.md
├── reference_docs/ # Business-related documentation and examples
└── YTHN-100.xlsm/.xlsx # Main workbook files
Error Handling
The system uses clsErrorLogger for comprehensive error tracking:
- Errors are logged but do not stop processing
- Final error report is generated in the output workbook
- Context is preserved for debugging (row number, expression, details)
Important Notes
- Late Binding: VBA modules use late binding (CreateObject) to avoid external reference dependencies
- Operator Precedence: AND is processed before OR, parentheses override default precedence
- Recursive Parsing: Nested expressions are handled recursively in M03_Logic
- Dynamic Columns: Output workbooks detect and include only relevant configuration keys
Documentation Guidelines
Document Storage Policy
When creating documentation for this project, follow these guidelines:
Code-Related Documentation → Save in docs/ directory:
- Technical specifications
- Algorithm explanations
- Code flow diagrams
- Test documentation
- API/reference documentation for code modules
- Implementation guides
Examples:
docs/Test_PP_06_FullIntegration_流程详解.md✓docs/M03_Logic_Algorithm.md✓docs/API_Reference.md✓
Business-Related Documentation → Save in reference_docs/ directory:
- Business requirements
- User manuals
- Product specifications
- Industry standards
- Configuration examples
- Business process documentation
Examples:
reference_docs/BOM_Requirements.md✓reference_docs/Product_Catalog.xlsx✓reference_docs/User_Guide.pdf✓
Decision Tree:
Is it about code implementation or technical details?
├─ Yes → docs/
└─ No → Is it about business logic or user-facing content?
├─ Yes → reference_docs/
└─ No → Ask for clarification
Note: When in doubt, prefer docs/ for technical content and reference_docs/ for business content.