Skip to content

aphp/prism-lang-fml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

prism-lang-fml

A Prism.js language definition plugin for FHIR Mapping Language (FML)

License: MIT PRs Welcome Prism.js Compatible FHIR R5

πŸ“‹ Overview

This project provides a comprehensive language definition plugin for Prism.js, 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

npm install prism-lang-fml

Using CDN

<!-- Include Prism.js core -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/prism.min.js"></script>

<!-- Include the language definition -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/prism-lang-fml.min.js"></script>

Manual Installation

  1. Download the plugin files from the dist/ directory
  2. Include them in your HTML after Prism.js core

πŸ“– Usage

Basic Usage

<pre><code class="language-fml">
/// 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')
}
</code></pre>

<script>
  // Highlight all code blocks
  Prism.highlightAll();
</script>

Advanced Usage

// 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:
git clone https://github.com/yourusername/prism-lang-fml.git
cd prism-lang-fml
  1. Install dependencies:
npm install
  1. Start development:
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 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 first, then open a new issue if needed.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Prism.js team for the excellent syntax highlighter
  • HL7 FHIR community for the FHIR specification
  • FHIR Mapping Language specification authors
  • Contributors and maintainers
  • Healthcare interoperability community

πŸ“š Resources

FML Language Resources

Prism.js Resources

πŸ”— Links

πŸ“Š 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

About

A Prism.js language definition plugin for FHIR Mapping Language (FML)

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published