https://github.com/aphp/prism-lang-fml
A Prism.js language definition plugin for FHIR Mapping Language (FML)
https://github.com/aphp/prism-lang-fml
Last synced: 9 months ago
JSON representation
A Prism.js language definition plugin for FHIR Mapping Language (FML)
- Host: GitHub
- URL: https://github.com/aphp/prism-lang-fml
- Owner: aphp
- License: mit
- Created: 2025-09-21T18:31:22.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-09-21T19:19:43.000Z (10 months ago)
- Last Synced: 2025-09-21T21:19:39.838Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 48.8 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# prism-lang-fml
A Prism.js language definition plugin for FHIR Mapping Language (FML)
[](https://opensource.org/licenses/MIT)
[](CONTRIBUTING.md)
[](https://prismjs.com)
[](https://hl7.org/fhir/R5/)
## ๐ Overview
This project provides a comprehensive language definition plugin for [Prism.js](https://prismjs.com), enabling syntax highlighting for **FHIR Mapping Language (FML)** files. FML is a domain-specific language for transforming data between different FHIR resource formats, essential for healthcare interoperability.
## ๐ Features
- **Complete FML syntax support** - All keywords, operators, and constructs
- **Comprehensive token highlighting** - Metadata comments, transformation arrows, functions
- **FHIR-aware patterns** - URLs, paths, ConceptMaps, structure definitions
- **Performance optimized** - Regex patterns designed to avoid backtracking
- **Compatible with Prism.js 1.15+** - Works with all modern Prism.js versions
- **Extensive test coverage** - 50+ test cases covering all FML features
- **Visual testing** - Interactive demo for real-time syntax verification
## ๐ Project Structure
```
prism-lang-fml/
โโโ src/
โ โโโ prism-lang-fml.js # Main language definition
โ โโโ prism-lang-fml.css # Optional fml styling
โโโ test/
โ โโโ fixtures/ # Test code samples
โ โโโ prism-lang-fml.test.js # Unit tests
โ โโโ visual.html # Visual testing page
โโโ examples/
โ โโโ demo.html # Usage examples
โโโ dist/ # Built/minified files
โ โโโ prism-lang-fml.min.js
โ โโโ prism-lang-fml.min.css
โโโ docs/
โ โโโ LANGUAGE_SPEC.md # Language specification
โโโ .github/
โ โโโ workflows/ # CI/CD pipelines
โ โโโ ISSUE_TEMPLATE/
โ โโโ PULL_REQUEST_TEMPLATE.md
โโโ CONTRIBUTING.md # Contribution guidelines
โโโ CLAUDE.md # Claude Code assistant guide
โโโ LICENSE # MIT License
โโโ package.json
โโโ .gitignore
โโโ .eslintrc.json
โโโ README.md # This file
```
## ๐ง Installation
### Using npm
```bash
npm install prism-lang-fml
```
### Using CDN
```html
```
### Manual Installation
1. Download the plugin files from the `dist/` directory
2. Include them in your HTML after Prism.js core
## ๐ Usage
### Basic Usage
```html
/// url = 'http://example.org/fhir/StructureMap/PatientTransform'
/// name = 'PatientTransformation'
map "PatientTransform" = "Transform"
uses "http://hl7.org/fhir/StructureDefinition/Patient" alias Patient as source
uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias Bundle as target
group TransformPatient(source src : Patient, target tgt : Bundle) {
src.id as id -> tgt.id = id "copyId"
src.name as n where n.use = 'official' -> tgt.displayName = n
src.gender as g -> tgt.genderCode = translate(g, '#GenderMap', 'code')
}
// Highlight all code blocks
Prism.highlightAll();
```
### Advanced Usage
```javascript
// Programmatic highlighting
const fmlCode = `
src.identifier as id where id.system = 'http://example.org/mrn' then {
id -> tgt.identifier = create('Identifier') as newId then {
id.value as v -> newId.value = v "setValue"
id -> newId.system = 'http://newexample.org/mrn' "setSystem"
}
}
`;
const html = Prism.highlight(fmlCode, Prism.languages.fml, 'fml');
```
### Supported Token Types
The plugin recognizes and highlights the following FML constructs:
| Token Type | Description | Example |
| ------------------------ | ----------------------------- | --------------------------------- |
| `metadata-comment` | Metadata declarations | `/// url = 'http://example.org'` |
| `structure-keyword` | Structure definition keywords | `map`, `uses`, `group`, `imports` |
| `mode-keyword` | Parameter mode keywords | `source`, `target`, `queried` |
| `transformation-keyword` | Transformation operations | `for`, `where`, `check`, `then` |
| `function` | Built-in functions | `create()`, `translate()`, `cc()` |
| `transformation-arrow` | Transformation operator | `->` |
| `rule-label` | Named rule labels | `"copyId" :` |
| `variable-binding` | Variable binding keyword | `as` |
| `url` | HTTP/HTTPS URLs | `http://hl7.org/fhir/Patient` |
| `path` | Path expressions | `src.patient.name.family` |
| `operator` | Logical/comparison operators | `=`, `!=`, `and`, `or` |
| `string` | String literals | `'Patient'`, `"Bundle"` |
| `number` | Numeric literals | `42`, `3.14` |
| `boolean` | Boolean values | `true`, `false` |
## ๐งช Development
### Prerequisites
- Node.js >= 16.0.0
- npm >= 7.0.0
- Git
### Setup
1. Clone the repository:
```bash
git clone https://github.com/yourusername/prism-lang-fml.git
cd prism-lang-fml
```
2. Install dependencies:
```bash
npm install
```
3. Start development:
```bash
npm run dev
```
### Available Scripts
- `npm run dev` - Start development mode with watch
- `npm run build` - Build production files
- `npm test` - Run tests
- `npm run lint` - Lint code
- `npm run format` - Format code with Prettier
- `npm run test:visual` - Open visual test page
## ๐ค Contributing
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details on:
- Code of Conduct
- Development workflow
- Submitting pull requests
- Reporting issues
## ๐ Issues
Found a bug or have a feature request? Please check [existing issues](https://github.com/yourusername/prism-lang-fml/issues) first, then [open a new issue](https://github.com/yourusername/prism-lang-fml/issues/new/choose) if needed.
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## ๐ Acknowledgments
- [Prism.js](https://prismjs.com) team for the excellent syntax highlighter
- [HL7 FHIR](https://hl7.org/fhir/) community for the FHIR specification
- [FHIR Mapping Language](https://build.fhir.org/mapping-language.html) specification authors
- Contributors and maintainers
- Healthcare interoperability community
## ๐ Resources
### FML Language Resources
- [FHIR Mapping Language Specification](https://build.fhir.org/mapping-language.html)
- [FHIR Mapping Language Grammar](https://build.fhir.org/mapping.g4)
- [FHIR Mapping Tutorial](https://build.fhir.org/mapping-tutorial.html)
- [StructureMap Resource](https://build.fhir.org/structuremap.html)
- [FHIRPath Specification](http://hl7.org/fhirpath/)
### Prism.js Resources
- [Prism.js Documentation](https://prismjs.com/docs/)
- [Creating a Prism.js Language Definition](https://prismjs.com/extending.html#language-definitions)
- [Language Definition Examples](https://github.com/PrismJS/prism/tree/master/components)
## ๐ Links
- [npm Package](https://www.npmjs.com/package/prism-lang-fml)
- [GitHub Repository](https://github.com/yourusername/prism-lang-fml)
- [Issue Tracker](https://github.com/yourusername/prism-lang-fml/issues)
- [Discussions](https://github.com/yourusername/prism-lang-fml/discussions)
### ๐ Implementation Status
- โ
**Language Definition**: Complete FML syntax support with 15+ token types
- โ
**Testing**: 50+ comprehensive test cases covering all FML features
- โ
**Documentation**: Complete language specification and usage examples
- โ
**Performance**: Optimized regex patterns, no catastrophic backtracking
- โ
**Visual Testing**: Interactive demo with theme switching and real-time testing
- โ
**Build System**: Production-ready build pipeline with minification
### ๐ฏ Supported FML Features
- **Structure Definitions**: `map`, `uses`, `group`, `imports`, `extends`, `alias`, `conceptmap`
- **Mode Keywords**: `source`, `target`, `queried`, `produced`
- **Transformations**: `for`, `where`, `check`, `then`, `first`, `last`, `only_one`
- **Functions**: All 17+ built-in functions (`create`, `translate`, `cc`, `qty`, etc.)
- **Special Syntax**: Transformation arrows (`->`), rule labels, variable binding (`as`)
- **Data Types**: URLs, paths, strings, numbers, booleans
- **ConceptMaps**: Full prefix and mapping syntax support
Ready for FHIR developers building healthcare interoperability solutions! ๐ฅ
---
**Status**: โ
**Ready for Production** - Complete FML syntax highlighting implementation
partially developped with Claude Code