dockerfile.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import type { languages } from '../fillers/monaco-editor-core';
  6. export const conf: languages.LanguageConfiguration = {
  7. brackets: [
  8. ['{', '}'],
  9. ['[', ']'],
  10. ['(', ')']
  11. ],
  12. autoClosingPairs: [
  13. { open: '{', close: '}' },
  14. { open: '[', close: ']' },
  15. { open: '(', close: ')' },
  16. { open: '"', close: '"' },
  17. { open: "'", close: "'" }
  18. ],
  19. surroundingPairs: [
  20. { open: '{', close: '}' },
  21. { open: '[', close: ']' },
  22. { open: '(', close: ')' },
  23. { open: '"', close: '"' },
  24. { open: "'", close: "'" }
  25. ]
  26. };
  27. export const language = <languages.IMonarchLanguage>{
  28. defaultToken: '',
  29. tokenPostfix: '.dockerfile',
  30. variable: /\${?[\w]+}?/,
  31. tokenizer: {
  32. root: [
  33. { include: '@whitespace' },
  34. { include: '@comment' },
  35. [/(ONBUILD)(\s+)/, ['keyword', '']],
  36. [/(ENV)(\s+)([\w]+)/, ['keyword', '', { token: 'variable', next: '@arguments' }]],
  37. [
  38. /(FROM|MAINTAINER|RUN|EXPOSE|ENV|ADD|ARG|VOLUME|LABEL|USER|WORKDIR|COPY|CMD|STOPSIGNAL|SHELL|HEALTHCHECK|ENTRYPOINT)/,
  39. { token: 'keyword', next: '@arguments' }
  40. ]
  41. ],
  42. arguments: [
  43. { include: '@whitespace' },
  44. { include: '@strings' },
  45. [
  46. /(@variable)/,
  47. {
  48. cases: {
  49. '@eos': { token: 'variable', next: '@popall' },
  50. '@default': 'variable'
  51. }
  52. }
  53. ],
  54. [
  55. /\\/,
  56. {
  57. cases: {
  58. '@eos': '',
  59. '@default': ''
  60. }
  61. }
  62. ],
  63. [
  64. /./,
  65. {
  66. cases: {
  67. '@eos': { token: '', next: '@popall' },
  68. '@default': ''
  69. }
  70. }
  71. ]
  72. ],
  73. // Deal with white space, including comments
  74. whitespace: [
  75. [
  76. /\s+/,
  77. {
  78. cases: {
  79. '@eos': { token: '', next: '@popall' },
  80. '@default': ''
  81. }
  82. }
  83. ]
  84. ],
  85. comment: [[/(^#.*$)/, 'comment', '@popall']],
  86. // Recognize strings, including those broken across lines with \ (but not without)
  87. strings: [
  88. [/\\'$/, '', '@popall'], // \' leaves @arguments at eol
  89. [/\\'/, ''], // \' is not a string
  90. [/'$/, 'string', '@popall'],
  91. [/'/, 'string', '@stringBody'],
  92. [/"$/, 'string', '@popall'],
  93. [/"/, 'string', '@dblStringBody']
  94. ],
  95. stringBody: [
  96. [
  97. /[^\\\$']/,
  98. {
  99. cases: {
  100. '@eos': { token: 'string', next: '@popall' },
  101. '@default': 'string'
  102. }
  103. }
  104. ],
  105. [/\\./, 'string.escape'],
  106. [/'$/, 'string', '@popall'],
  107. [/'/, 'string', '@pop'],
  108. [/(@variable)/, 'variable'],
  109. [/\\$/, 'string'],
  110. [/$/, 'string', '@popall']
  111. ],
  112. dblStringBody: [
  113. [
  114. /[^\\\$"]/,
  115. {
  116. cases: {
  117. '@eos': { token: 'string', next: '@popall' },
  118. '@default': 'string'
  119. }
  120. }
  121. ],
  122. [/\\./, 'string.escape'],
  123. [/"$/, 'string', '@popall'],
  124. [/"/, 'string', '@pop'],
  125. [/(@variable)/, 'variable'],
  126. [/\\$/, 'string'],
  127. [/$/, 'string', '@popall']
  128. ]
  129. }
  130. };