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

[WIP] Add support for object keys, labels #307

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

[WIP] Add support for object keys, labels #307

wants to merge 3 commits into from

Conversation

MaximSokolov
Copy link
Contributor

label:

switch (foo())
{
    case 'string':
    case a:
    case a + b:
    case foo(bar):
    case CON$TANT:
    case 123:
      foo(bar)
      break;
    default:
}

? a : b
? "abc" : "abc"
? (a.b(123)) : (b("c"))
? {key: value} : b
? this : null
? 'a'.b(':c(d)') :

obj = {
  key: value,
  $abc$: value,
  'key': 'value',
  KEY: VALUE
}

obj1 = {
  name: function (){},
  'name': function (){},
  "name": function(){}
}

obj2 = {
  null: 'abc',
  module: 'abc',
  this: 'abc',
  class: 'abc',
  NaN: 'abc'
}
atom-text-editor::shadow .source.js {
  .meta.object-key {
    // * {}

    .variable {}

    .constant.numeric {}

    .string {}

    .constant.other {}
  }

  .meta.function {
    .meta.object-key {
      .entity.name.function, .string {}
    }
  }
}

@50Wliu
Copy link
Contributor

50Wliu commented Jan 19, 2016

I mean, this does seem to clear up some of the regexes. The case/default stuff is definitely something that can be improved though, and may also allow us to match labels correctly. Can you try putting that in a separate repository (maybe 'include': '#switch-case'), and only call that when we hit a switch statement?

@MaximSokolov
Copy link
Contributor Author

Objects literals inside ternary expression fixed by using begin/end matching for curly brackets. Looking for the following word in key pattern allows to match labels properly. The case/default moved to a switch_statement repo.

@MaximSokolov MaximSokolov changed the title [WIP] Add support for object keys [WIP] Add support for object keys, labels Jan 21, 2016
@50Wliu
Copy link
Contributor

50Wliu commented Jan 21, 2016

@MaximSokolov So is this ready for review, or are there more edge cases that need to be addressed?

@MaximSokolov
Copy link
Contributor Author

It's ready for review. However PR brings highlighting changes, so I want to add before/after info and steps to change colors before merging

'begin': '''(?x)
(\\b([a-zA-Z_?.$][\\w?.$]*))
\\s*(:)\\s*
\\b(?:(async)(?:\\s+))?
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't this be (\\basync\\b)? instead?

{tokens} = grammar.tokenizeLine('default: ')
expect(tokens[0]).toEqual value: 'default', scopes: ['source.js', 'keyword.control.js']
it "tokenizes switch expression", ->
{tokens} = grammar.tokenizeLine('switch(1+1){}')
Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty useless switch 😆

@50Wliu
Copy link
Contributor

50Wliu commented Feb 5, 2016

This will also need to be rebased.

@doughsay
Copy link

I'd like to mention a special case, just to make sure it gets addressed with these changes when they're done: #334 (comment)

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.

None yet

3 participants