%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: Calcpad
scope: source.calcpad

file_extensions:
- cpd

contexts:
  main:
    - match: '[\^/÷\\%*\-+∠]'
      scope: keyword.operator.arithmetic.calcpad
    - match: '[≡≠<>≤≥]'
      scope: keyword.operator.comparison.calcpad
    - match: '[∧∨⊕]'
      scope: keyword.operator.logical.calcpad
    - match: '[=←]'
      scope: keyword.operator.assignment.calcpad
    - match: '[;&@:|]'
      scope: punctuation.separator.calcpad
    - match: '[\[\{()\}\[]'
      scope: punctuation.section.brackets.calcpad
    - match: '[a-zA-Z]+[a-zA-Z0-9_]*\$'
      scope: meta.string.calcpad
    - match: '\b(sign|abs|mod|gcd|lcm|sin|cos|tan|csc|sec|cot|sinh|cosh|tanh|csch|sech|coth|asin|acos|atan|acsc|asec|acot|asinh|acosh|atanh|acsch|asech|acoth|ln|log|log_2|exp|sqr|sqrt|cbrt|round|floor|ceiling|trunc|re|im|phase|conj|random|root|atan2|min|max|sum|sumsq|srss|average|product|mean|switch|take|line|spline|not|and|or|xor|timer|vector|len|size|fill|range|join|resize|first|last|slice|sort|rsort|order|revorder|reverse|extract|search|count|find|find_eq|find_ne|find_lt|find_gt|find_le|find_ge|lookup|Lokup_eq|Lookup_ne|Lookup_lt|Lookup_gt|Lookup_le|Lookup_ge|norm|norm_1|norm_2|norm_e|norm_i|norm_p|unit|dot|cross|matrix|identity|diagonal|column|utriang|ltriang|symmetric|vec2diag|dig2vec|vec2col|vec2row|join_cols|join_rows|augment|stack|mfill|fill_row|fill_col|mresize|copy|add|n_rows|n_cols|row|col|extract_rows|extract_cols|submatrix|mnorm|mnorm_2|mnorm_e|mnorm_1|mnor_i|cond|cond_1|cond_2|cond_e|cond_i|det|rank|transp|trace|inverse|adj|cofactor|eigenvals|eigenvecs|eigen|lu|qr|svd|cholesky|lsolve|clsolve|slsolve|msolve|cmsolve|smsolve|hprod|fprod|kprod|sort_cols|rsort_cols|sor_rows|rsort_rows|order_cols|revorder_cols|order_rows|revorder_rows|mcount|mfind|mfind_eq|mfind_ne|mfind_lt|mfind_le|mfind_gt|mfind_ge|msearch|hlookup|hlookup_eq|hlookup_ne|hlookup_lt|hlookup_le|hlookup_gt|hlookup_ge|vlookup|vlookup_eq|vlookup_ne|vlookup_lt|vlookup_le|vlookup_gt|vlookup_ge|getunits|setunits|clrunits|hp|ishp|vector_hp|range_hp|matrix_hp|identity_hp|diagonal_hp|column_hp|utriang_hp|ltriang_hp|symmetric_hp|matmul)\b'
      scope: support.function.calcpad
    - match: '#'
      scope: punctuation.definition.keyword.calcpad
      pop: true
      set:
      - match: '\b([Rr]epeat|[Ll]oop|[Bb]reak|[Cc]ontinue|[Ss]how|[Hh]ide|[Pp]re|[Pp]ost|[Vv]al|[Ee]qu|[Nn]oc|[Nn]osub|[Nn]ovar|[Vv]arsub|[Rr]ad|[Dd]eg|[Gg]ra|[Ii]f|[Ee]lse|[Ee]lse [Ii]f|[Ee]nd [Ii]f|[Ff]or|[Ww]hile|[Ii]nclude|[Ll]ocal|[Gg]lobal|[Dd]ef|[Ee]nd [Dd]ef|[Pp]ause|[Ii]nput|[Ss]plit|[Ww]rap|[Pp]hasor|[Cc]omplex|[Cc]onst|[Aa]ppend|[Rr]ead|[Ww]rite|[Rr]ound|[Mm]d|[Mm]d [Oo]n|[Mm]d [Oo]ff)\b'
        scope: keyword.control.calcpad
      - match: '[^a-zA-Z]'
        pop: true
    - match: '\$'
      scope: punctuation.definition.method.calcpad
      push:
      - match: '\b([Rr]oot|[Ff]ind|[Ii]nf|[Ss]up|[Aa]rea|[Ii]ntegral|[Ss]lope|[Dd]erivative|[Ss]um|[Pp]roduct|[Rr]epeat|[Mm]ap|[Pp]lot|[Bb]lock|[Ii]nline|[Ww]hile)\b'
        scope: support.method.calcpad
      - match: '\{'
        scope: punctuation.section.brackets.calcpad
        pop: true
      - match: '[^a-zA-Z]'
        pop: true
    - match: '\b[a-zA-Zα-ωΑ-Ω°øØ∡]+[a-zA-Zα-ωΑ-Ω°øØ∡0-9_,′″‴⁗⁰¹²³⁴⁵⁶⁷⁸⁹ⁿ⁺⁻]*\b'
      scope: variable.function.calcpad variable.other.calcpad
    - match: '\b([0-9]*\.?[0-9]+)'
      scope: constant.numeric.calcpad
      pop: true
      set:
      - match: '[A-Za-z°]+'
        scope: entity.name.constant.calcpad
        pop: true
      - match: '\b'
        pop: true
    - match: \"
      scope: punctuation.definition.string.begin.calcpad
      push: double_quoted_string
    - match: \'
      scope: punctuation.definition.string.begin.calcpad
      push: single_quoted_string

  double_quoted_string:
    - meta_scope: string.quoted.double.calcpad
    - match: \\.
      scope: constant.character.escape.calcpad
    - match: '["\r\n]'
      scope: punctuation.definition.string.end.calcpad
      pop: true

  single_quoted_string:
    - meta_scope: string.quoted.single.calcpad
    - match: \\.
      scope: constant.character.escape.calcpad
    - match: "['\r\n]"
      scope: punctuation.definition.string.end.calcpad
      pop: true