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

Commit c2cf946

Browse files
WliuWliu
authored andcommitted
Merge pull request #34 from petems/fix_variables_starting_with_underscore
Allows variables starting with underscores
2 parents 4f5b7a1 + 880801c commit c2cf946

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

grammars/puppet.cson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@
410410
'captures':
411411
'1':
412412
'name': 'punctuation.definition.variable.puppet'
413-
'match': '(\\$)([a-zA-Zx7f-xff\\$]|::)([a-zA-Z0-9_x7f-xff\\$]|::)*\\b'
413+
'match': '(\\$)((::)?[a-z]\\w*)*((::)?[a-z_]\\w*)\\b'
414414
'name': 'variable.other.readwrite.global.puppet'
415415
}
416416
{

spec/puppet-spec.coffee

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,20 @@ describe "Puppet grammar", ->
5555
it "tokenizes require => variable as a parameter", ->
5656
{tokens} = grammar.tokenizeLine("require => Class['foo']")
5757
expect(tokens[0]).toEqual value: 'require ', scopes: ['source.puppet', 'constant.other.key.puppet']
58+
59+
it "tokenizes regular variables", ->
60+
{tokens} = grammar.tokenizeLine('$foo')
61+
expect(tokens[0]).toEqual value: '$', scopes: ['source.puppet', 'variable.other.readwrite.global.puppet', 'punctuation.definition.variable.puppet']
62+
expect(tokens[1]).toEqual value: 'foo', scopes: ['source.puppet', 'variable.other.readwrite.global.puppet']
63+
64+
{tokens} = grammar.tokenizeLine('$_foo')
65+
expect(tokens[0]).toEqual value: '$', scopes: ['source.puppet', 'variable.other.readwrite.global.puppet', 'punctuation.definition.variable.puppet']
66+
expect(tokens[1]).toEqual value: '_foo', scopes: ['source.puppet', 'variable.other.readwrite.global.puppet']
67+
68+
{tokens} = grammar.tokenizeLine('$_foo_')
69+
expect(tokens[0]).toEqual value: '$', scopes: ['source.puppet', 'variable.other.readwrite.global.puppet', 'punctuation.definition.variable.puppet']
70+
expect(tokens[1]).toEqual value: '_foo_', scopes: ['source.puppet', 'variable.other.readwrite.global.puppet']
71+
72+
{tokens} = grammar.tokenizeLine('$::foo')
73+
expect(tokens[0]).toEqual value: '$', scopes: ['source.puppet', 'variable.other.readwrite.global.puppet', 'punctuation.definition.variable.puppet']
74+
expect(tokens[1]).toEqual value: '::foo', scopes: ['source.puppet', 'variable.other.readwrite.global.puppet']

0 commit comments

Comments
 (0)