Link Search Menu Expand Document

Languages-beta : OC-L-06-Patterns.cbs | PRETTY | PDF

Outline

Language "OCaml Light"

6 Patterns

Syntax
  P : pattern 
  ::= value-name 
    |  '_'
    | constant
    | pattern 'as' value-name
    | '(' pattern ')'
    | '(' pattern ':' typexpr ')'
    | pattern '|' pattern
    | constr pattern
    | pattern comma-pattern+
    | '{' field '=' pattern semic-field-pattern* ';'? '}'
    | '[' pattern semic-pattern* ';'? ']'
    | pattern '::' pattern

  CP : comma-pattern ::= ',' pattern
  
  SP : semic-pattern ::= ';' pattern
  
  SFP : semic-field-pattern ::= ';' field '=' pattern
Rule
  [[ '(' P ')' ]] : pattern = [[ P ]]
Rule
  [[ '(' P ':' T ')' ]] : pattern = [[ P ]]
Rule
  [[ '{' F '=' P SFP* ';' '}' ]] : pattern = [[ '{' F '=' P SFP* '}' ]]
Rule
  [[ '[' P SP* ';' ']' ]] : pattern = [[ '[' P SP* ']' ]]

Pattern evaluation

Pattern sequence evaluation

Semantics
  evaluate-comma-pattern-sequence[[ _:(pattern comma-pattern*) ]] : 
                                                   (=>patterns)+
Rule
  evaluate-comma-pattern-sequence[[ P1 ',' P2 CP* ]] =
    evaluate-pattern[[ P1 ]], evaluate-comma-pattern-sequence[[ P2 CP* ]]
Rule
  evaluate-comma-pattern-sequence[[ P ]] = evaluate-pattern[[ P ]]
Semantics
  evaluate-semic-pattern-sequence[[ _:(pattern semic-pattern*) ]] :
                                                    (=>patterns)+
Rule
  evaluate-semic-pattern-sequence[[ P1 ';' P2 SP* ]] =
    evaluate-pattern[[ P1 ]], evaluate-semic-pattern-sequence[[ P2 SP* ]]
Rule
  evaluate-semic-pattern-sequence[[ P ]] = evaluate-pattern[[ P ]]
Semantics
  evaluate-field-pattern-sequence[[ _:(field '=' pattern semic-field-pattern*) ]] : 
                                          =>(maps(ids,patterns))+
Rule
  evaluate-field-pattern-sequence[[ F1 '=' P1 ';' F2 '=' P2 SFP* ]] =
    ( { field-name[[ F1 ]] |-> evaluate-pattern[[ P1 ]] },
      evaluate-field-pattern-sequence[[ F2 '=' P2 SFP* ]] )
Rule
  evaluate-field-pattern-sequence[[ F '=' P ]] =
    { field-name[[ F ]] |-> evaluate-pattern[[ P ]] }