A comprehensive syntax parser and checker for 4D documentation, written in TypeScript.
- Parse 4D syntax strings with multiple variants
- Tokenizer-based architecture for robust parsing
- Multi-level warning system (structural vs type issues)
- CLI support with configurable warning levels
- Validate parameter types and names
- Check for type mismatches and extra parameters
- Support for optional parameters and spread syntax
- Enhanced type validation with forward-slash and comma-separated types
- Full TypeScript support with type definitions
The parser uses a modern 4-step architecture:
- Preprocessing: Remove markdown formatting (
**bold**→bold) - Tokenization: Convert text into structured tokens
- Malformation Checking: Detect structural issues (missing braces, parentheses)
- Parameter Checking: Validate parameter types and detect type-related issues
- Level 1: High priority structural issues (missing parentheses, unmatched braces)
- Level 2: Type-related issues (missing types, empty types after colons)
syntax-checker/
├── src/ # TypeScript source files
│ ├── parser.ts # Main parser orchestrator
│ ├── tokenizer.ts # Tokenization logic
│ ├── malformation-checker.ts # Structural validation
│ ├── parameter-checker.ts # Parameter type validation
│ ├── checker.ts # SyntaxChecker class implementation
│ └── types.d.ts # Type definitions
├── tests/ # Test files
│ ├── parser.test.ts
│ ├── checker.test.ts
│ └── stress/
│ └── stress.test.ts
├── out/ # Compiled JavaScript output (generated)
├── index.ts # Main library entry point
├── check.ts # CLI script
├── tsconfig.json # TypeScript configuration
└── .gitignore # Git ignore file
npm run build # Compile TypeScript to JavaScript
npm run build:watch # Watch mode for developmentnpm test # Run all tests
npm run test:watch # Watch mode for tests
npm run test:coverage # Run tests with coveragenpm install @4d-docs/syntax-checker# Check syntax with default settings (Level 1 warnings only)
syntax-checker
# Check with all warnings (Level 1 + Level 2)
syntax-checker --warning-level 2
# Check specific documentation folder
syntax-checker ./docs --warning-level 2
# Short form
syntax-checker -w 2--warning-level, -w <1|2>: Set warning level (default: 1)1: Show only high priority warnings (structural issues)2: Show all warnings (structural + type issues)
--help, -h: Show help message
import { Parser, SyntaxChecker, WarningLevel } from '@4d-docs/syntax-checker';
// Parse syntax string
const parser = new Parser();
const variants = parser.parseSyntax('**VP SET TIME VALUE** ( *rangeObj* : Object ; *timeValue* : Text { ; *formatPattern* : Text } )');
// Check syntax with specific warning level
const checker = new SyntaxChecker(WarningLevel.LEVEL_2);
await checker.run();// Use just the parser
import { Parser } from '@4d-docs/syntax-checker/parser';
const parser = new Parser();
const variants = parser.parseSyntax(syntaxString);
// Use just the checker
import { SyntaxChecker } from '@4d-docs/syntax-checker/checker';
const checker = new SyntaxChecker();
checker.checkCommand(name, command);syntax-checker/
├── src/ # Source code
│ ├── checker.js # Main SyntaxChecker class
│ └── parser.js # Parser class for syntax parsing
├── index.js # Main entry point and exports
├── package.json # Package configuration
├── vitest.config.js # Vitest test configuration
├── syntax-checker.test.js # Main test suite
├── stress.test.js # Stress and performance tests
├── test.js # Legacy manual test runner
└── README.md # This file
// Legacy compatibility functions
import { parseSyntax, parseParameters } from '@4d-docs/syntax-checker';
const variants = parseSyntax(syntaxString);
const params = parseParameters(paramString);Handles syntax parsing operations:
parseSyntax(syntax)- Parse syntax string into variantsparseParameters(paramString)- Parse parameter string
Handles syntax validation:
checkCommand(name, command)- Validate command syntaxrun()- Run full syntax check- Various validation helper methods
See the individual class files for detailed API documentation.
MIT