summaryrefslogtreecommitdiffstats
path: root/assets/syntaxes/02_Extra/CSV.sublime-syntax
blob: 10e5c7cc4a619254fee66ac328be6055b85d2eb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
name: Comma Separated Values
file_extensions:
  - csv
  - tsv
scope: text.csv
variables:
  field_separator: (?:[,;\t])
  record_separator: (?:$\n?)
contexts:
  prototype:
    - match: (?={{record_separator}})
      pop: true
  fields:
    - match: ''
      push:
        - field_or_record_separator
        - field5
        - field_or_record_separator
        - field4
        - field_or_record_separator
        - field3
        - field_or_record_separator
        - field2
        - field_or_record_separator
        - field1
  main:
    - meta_include_prototype: false
    - match: '^'
      set: fields

  field_or_record_separator:
    - meta_include_prototype: false
    - match: '{{record_separator}}'
      scope: punctuation.terminator.record.csv
      pop: true
    - match: '{{field_separator}}'
      scope: punctuation.separator.sequence.csv
      pop: true

  field_contents:
    - match: '"'
      scope: punctuation.definition.string.begin.csv
      push: double_quoted_string

    - match: (?={{field_separator}}|{{record_separator}})
      pop: true

  double_quoted_string:
    - meta_include_prototype: false
    - meta_scope: string.quoted.double.csv
    - match: '""'
      scope: constant.character.escape.csv
    - match: '"'
      scope: punctuation.definition.string.end.csv
      pop: true

  field1:
    - match: ''
      set:
        - meta_content_scope: meta.field-1.csv support.type
        - include: field_contents
  field2:
    - match: ''
      set:
        - meta_content_scope: meta.field-2.csv support.function
        - include: field_contents
  field3:
    - match: ''
      set:
        - meta_content_scope: meta.field-3.csv variable.other
        - include: field_contents
  field4:
    - match: ''
      set:
        - meta_content_scope: meta.field-4.csv constant.numeric
        - include: field_contents
  field5:
    - match: ''
      set:
        - meta_content_scope: meta.field-5.csv keyword.operator
        - include: field_contents