module example_metrics is
; <- keyword
;      ^ module.definition
;                      ^ keyword

  entity Ad is
  ; <- keyword
  ;      ^ type.definition
  ;         ^ keyword
    identity adId -> long
    ; <- keyword
    ;        ^ variable.field
    ;              operator
    ;                ^ type
  end
  ; <- keyword

  event Impression is
  ; <- keyword
  ;     ^ type.definition
  ;                ^ keyword
    source Ad
    ; <- keyword
    ;      ^ type
  end
  ; <- keyword

  metric group Impressions on Impression is
  ; <- keyword
  ;      ^ keyword
  ;            ^ type.definition
  ;                        ^ keyword
  ;                           ^ type
  ;                                      ^ keyword
    metric grossImpressions -> count := count(event)
    ; <- keyword
    ;      ^ function.definition
    ;                       ^ operator
    ;                          ^ type
    ;                                ^ operator
    ;                                   ^ function.call
    ;                                        ^ punctuation.bracket
    ;                                         ^ variable.builtin
    ;                                              ^ punctuation.bracket
    metric invalidImpressions -> count
    ; <- keyword
    ;      ^ function.definition
    ;                         ^ operator
    ;                            ^ type
    metric impressions -> count := grossImpressions - invalidImpressions
    ; <- keyword
    ;      ^ function.definition
    ;                  ^ operator
    ;                     ^ type
    ;                           ^ operator
    ;                              ^ variable
    ;                                               ^ operator
    ;                                                 ^ variable
  end
  ; <- keyword

  event Click is
  ; <- keyword
  ;     ^ type.definition
  ;           ^ keyword
    source Ad
    ; <- keyword
    ;      ^ type
  end
  ; <- keyword

  metric group Impressions on Impression is
  ; <- keyword
  ;      ^ keyword
  ;            ^ type.definition
  ;                        ^ keyword
  ;                           ^ type
  ;                                      ^ keyword
    metric grossClicks -> count := count(event)
    ; <- keyword
    ;      ^ function.definition
    ;                  ^ operator
    ;                     ^ type
    ;                           ^ operator
    ;                              ^ function.call
    ;                                   ^ punctuation.bracket
    ;                                    ^ variable.builtin
    ;                                         ^ punctuation.bracket
    metric invalidClicks -> count
    ; <- keyword
    ;      ^ function.definition
    ;                    ^ operator
    ;                       ^ type
    metric clicks -> count := grossClicks - invalidClicks
    ; <- keyword
    ;      ^ function.definition
    ;             ^ operator
    ;                ^ type
    ;                      ^ operator
    ;                         ^ variable
    ;                                     ^ operator
    ;                                       ^ variable
    metric ctr(impressions -> Impressions) -> percentageRate
    ; <- keyword
    ;      ^ function.definition
    ;         ^ punctuation.bracket
    ;          ^ variable.parameter
    ;                      ^ operator
    ;                         ^ type
    ;                                    ^ punctuation.bracket
    ;                                      ^ operator
    ;                                         ^ type
       := clicks / impressions.impressions
       ; <- operator
       ;  ^ variable
       ;         ^ operator
       ;           ^ variable
       ;                      ^ operator
       ;                       ^ function.call
  end
  ; <- keyword

end
; <- keyword
