prism-elm.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. Prism.languages.elm = {
  2. 'comment': /--.*|\{-[\s\S]*?-\}/,
  3. 'char': {
  4. pattern: /'(?:[^\\'\r\n]|\\(?:[abfnrtv\\']|\d+|x[0-9a-fA-F]+|u\{[0-9a-fA-F]+\}))'/,
  5. greedy: true
  6. },
  7. 'string': [
  8. {
  9. // Multiline strings are wrapped in triple ". Quotes may appear unescaped.
  10. pattern: /"""[\s\S]*?"""/,
  11. greedy: true
  12. },
  13. {
  14. pattern: /"(?:[^\\"\r\n]|\\.)*"/,
  15. greedy: true
  16. }
  17. ],
  18. 'import-statement': {
  19. // The imported or hidden names are not included in this import
  20. // statement. This is because we want to highlight those exactly like
  21. // we do for the names in the program.
  22. pattern: /(^[\t ]*)import\s+[A-Z]\w*(?:\.[A-Z]\w*)*(?:\s+as\s+(?:[A-Z]\w*)(?:\.[A-Z]\w*)*)?(?:\s+exposing\s+)?/m,
  23. lookbehind: true,
  24. inside: {
  25. 'keyword': /\b(?:as|exposing|import)\b/
  26. }
  27. },
  28. 'keyword': /\b(?:alias|as|case|else|exposing|if|in|infixl|infixr|let|module|of|then|type)\b/,
  29. // These are builtin variables only. Constructors are highlighted later as a constant.
  30. 'builtin': /\b(?:abs|acos|always|asin|atan|atan2|ceiling|clamp|compare|cos|curry|degrees|e|flip|floor|fromPolar|identity|isInfinite|isNaN|logBase|max|min|negate|never|not|pi|radians|rem|round|sin|sqrt|tan|toFloat|toPolar|toString|truncate|turns|uncurry|xor)\b/,
  31. // decimal integers and floating point numbers | hexadecimal integers
  32. 'number': /\b(?:\d+(?:\.\d+)?(?:e[+-]?\d+)?|0x[0-9a-f]+)\b/i,
  33. // Most of this is needed because of the meaning of a single '.'.
  34. // If it stands alone freely, it is the function composition.
  35. // It may also be a separator between a module name and an identifier => no
  36. // operator. If it comes together with other special characters it is an
  37. // operator too.
  38. // Valid operator characters in 0.18: +-/*=.$<>:&|^?%#@~!
  39. // Ref: https://groups.google.com/forum/#!msg/elm-dev/0AHSnDdkSkQ/E0SVU70JEQAJ
  40. 'operator': /\s\.\s|[+\-/*=.$<>:&|^?%#@~!]{2,}|[+\-/*=$<>:&|^?%#@~!]/,
  41. // In Elm, nearly everything is a variable, do not highlight these.
  42. 'hvariable': /\b(?:[A-Z]\w*\.)*[a-z]\w*\b/,
  43. 'constant': /\b(?:[A-Z]\w*\.)*[A-Z]\w*\b/,
  44. 'punctuation': /[{}[\]|(),.:]/
  45. };