Skip to content

Instantly share code, notes, and snippets.

@brianpos
Created August 21, 2025 21:30
Show Gist options
  • Select an option

  • Save brianpos/ae7c740778f4545e3d4f4f3b51e91b94 to your computer and use it in GitHub Desktop.

Select an option

Save brianpos/ae7c740778f4545e3d4f4f3b51e91b94 to your computer and use it in GitHub Desktop.
FHIRPath Parser Stress tester

This isn't a sensible fhirpath expression that does something useful, however it does check the edges of a fhirpath parser. I've tried to check every single parsing rule, not every function avaialable.

(
  (
    (( -5.25 * 2 div 3 mod 2 + +3 - 1).toString() & ' units' )      /* polarity + multiplicative + additive + concatenation */
    |
    ( {} | true | %resource | false | 'hello' | 42 | 123L | @2025-08-21
      | @2025-08-21T12:34:56.789Z | @T08:00:00 | 5 'mg' | 3 days )  /* union of (null, booleans, string, number, long, date, datetime, time, qty(STRING), qty(keyword-unit) */
      | %ext 
      |  %`string-ext` 
      |  %`string-ext`.length()                                     /* functionInvocation (no params) */
      | $this.id
      | $this.`some-weird`                                          /* delimited member identifier */
      | name.select(family & '-' & $index.toString())
      | name.aggregate($total + $this.children().count(), 0)
      | select( -(2025) as Patient | id as FHIR.id)                 /* polarity on parenthesized numeric literal + 'as' typeExpression */
        .as(Patient)                                                /* keyword used as identifier (function) */
        .contains('x')                                              /* keyword used as identifier (function with param) */
  )
  .trace('stuff')
  [ 
    (1 + 1)
  ]                              /* indexerExpression (additive inside) */
  is Patient                               /* 'is' typeExpression (simple typeSpecifier) */
  and ( (5 'mg' < 10 'mg') or (3 days >= 2 days) )          /* inequalityExpression + orExpression */
  and (42 = 42 and 42 != 43 and 'abc' ~ 'abc' and 'abc' !~ 'def')  /* equalityExpression variants */
  and ('a' in ('a' | 'b') and ('a' | 'b') contains 'a')     /* membershipExpression + unionExpression */
  and (id is FHIR.string)            /* qualifiedIdentifier typeSpecifier w/ dot + both 'is' and 'as' */
  xor (false implies true)                  /* xorExpression + impliesExpression */
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment