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

Conversation

@petems
Copy link
Contributor

@petems petems commented Mar 12, 2016

No description provided.

expect(tokens[2]).toEqual value: '$foo', scopes: ['source.puppet', 'meta.definition.resource.puppet', 'entity.name.section.puppet']

it "tokenizes variable starting with underscore", ->
{tokens} = grammar.tokenizeLine('$foo')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You seem to have forgotten an underscore here... 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed and added a test for regular variables too! 👍

@petems petems force-pushed the fix_variables_starting_with_underscore branch from 3454c29 to b4e93ed Compare March 12, 2016 21:14
expect(tokens[0]).toEqual value: 'package', scopes: ['source.puppet', 'meta.definition.resource.puppet', 'storage.type.puppet']
expect(tokens[2]).toEqual value: '$foo', scopes: ['source.puppet', 'meta.definition.resource.puppet', 'entity.name.section.puppet']

it "tokenizes variablee", ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it "tokenizes regular variables", ->

@petems petems force-pushed the fix_variables_starting_with_underscore branch 2 times, most recently from 8c4fcaa to 51143b8 Compare March 12, 2016 21:32
{tokens} = grammar.tokenizeLine('$foo')
expect(tokens[0]).toEqual value: '$', scopes: ['source.puppet', 'variable.other.readwrite.global.puppet', 'punctuation.definition.variable.puppet']
expect(tokens[1]).toEqual value: 'foo', scopes: ['source.puppet', 'variable.other.readwrite.global.puppet']
{tokens} = grammar.tokenizeLine('$_foo')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny little nit: can there be a newline between lines 54 and 55?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 👍

@petems petems force-pushed the fix_variables_starting_with_underscore branch from 51143b8 to e51e8a7 Compare March 14, 2016 01:07
@winstliu
Copy link
Contributor

One more question: Does Puppet allow variables such as $_woo__?

@petems
Copy link
Contributor Author

petems commented Mar 14, 2016

@50Wliu Yep, that's valid

$_woo__='hello'
notice($_woo__)

Notice: Scope(Class[main]): hello

'1':
'name': 'punctuation.definition.variable.puppet'
'match': '(\\$)([a-zA-Zx7f-xff\\$]|::)([a-zA-Z0-9_x7f-xff\\$]|::)*\\b'
'match': '(\\$)([a-zA-Zx7f-xff\\$_]|::)([a-zA-Z0-9_x7f-xff\\$]|::)*\\b'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter capture should also include _ then

@petems petems force-pushed the fix_variables_starting_with_underscore branch from e51e8a7 to 457522d Compare March 14, 2016 16:27
@winstliu
Copy link
Contributor

Can variables not start with uppercase letters?

@petems
Copy link
Contributor Author

petems commented Mar 15, 2016

In Puppet 4, the official regex as given by the parser: Error: Illegal variable name, The given name 'Woo' does not conform to the naming rule /^((::)?[a-z]\w*)*((::)?[a-z_]\w*)$/ at /Users/petersouter/echo.pp:1:1

In older puppet its possible but linters will complain,

@petems petems force-pushed the fix_variables_starting_with_underscore branch from 457522d to 880801c Compare March 15, 2016 01:03
@winstliu
Copy link
Contributor

Wow, that's pretty awesome how it gives you the regex right in the error message. Just waiting on Travis now... ⌚ 😴

winstliu pushed a commit that referenced this pull request Mar 15, 2016
…core

Allows variables starting with underscores
@winstliu winstliu merged commit c2cf946 into atom:master Mar 15, 2016
@petems petems deleted the fix_variables_starting_with_underscore branch March 15, 2016 10:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants