Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Add basic support for heredocs #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions grammars/puppet.cson
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,39 @@
'include': '#variable'
}
]
'plain-heredoc':
'begin': '(@\\(([^ ()/:\\n\\r]+)(/[nrts$uL]*)?\\))'
'beginCaptures':
'1':
'name': 'punctuation.definition.string.begin.puppet'
'end': '^((\\s*\\|\\s*)?(\\s*-\\s*)?(\\2)$)'
'endCaptures':
'1':
'name': 'punctuation.definition.string.end.puppet'
'name': 'string.quoted.single.puppet'
'patterns': [
{
'include': '#escaped_char'
}
]
'double-quoted-heredoc':
'begin': '(@\\("([^ ()/:\\n\\r]+)"(/[nrts$uL]*)?\\))'
'beginCaptures':
'1':
'name': 'punctuation.definition.string.begin.puppet'
'end': '^((\\s*\\|\\s*)?(\\s*-\\s*)?(\\2)$)'
'endCaptures':
'1':
'name': 'punctuation.definition.string.end.puppet'
'name': 'string.quoted.double.puppet'
'patterns': [
{
'include': '#escaped_char'
}
{
'include': '#variable'
}
]
'escaped_char':
'match': '\\\\.'
'name': 'constant.character.escape.puppet'
Expand Down Expand Up @@ -427,6 +460,12 @@
]
'strings':
'patterns': [
{
'include': '#double-quoted-heredoc'
}
{
'include': '#plain-heredoc'
}
{
'include': '#double-quoted-string'
}
Expand Down
9 changes: 9 additions & 0 deletions spec/puppet-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,12 @@ describe "Puppet grammar", ->

{tokens} = grammar.tokenizeLine("package {'foo':}")
expect(tokens[0]).toEqual value: 'package', scopes: ['source.puppet', 'meta.definition.resource.puppet', 'storage.type.puppet']

describe "heredocs", ->
it "tokenizes plain heredocs as single-quoted strings", ->
{tokens} = grammar.tokenizeLine("@(HEREDOC)")
expect(tokens[0]).toEqual value: '@(HEREDOC)', scopes: ['source.puppet', 'string.quoted.single.puppet', 'punctuation.definition.string.begin.puppet']

it "tokenizes double-quoted heredocs as double-quoted strings", ->
{tokens} = grammar.tokenizeLine('@("HEREDOC")')
expect(tokens[0]).toEqual value: '@("HEREDOC")', scopes: ['source.puppet', 'string.quoted.double.puppet', 'punctuation.definition.string.begin.puppet']