Skip to content

Commit

Permalink
changes enum check to pass regex tests, more syntax tests
Browse files Browse the repository at this point in the history
  • Loading branch information
colinta committed Mar 18, 2016
1 parent 42a4fc0 commit 25567bf
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 121 deletions.
7 changes: 4 additions & 3 deletions Swift/Swift.sublime-syntax
Expand Up @@ -28,12 +28,13 @@ contexts:
1: punctuation.definition.preprocessor
2: meta.preprocessor.c
###################################################### ENUMS
- match: (?<=[^\)\w])\.([a-zA-Z]\w*)\(
- match: "(?:[^\\)\\w]|^)\\.([a-zA-Z]\\w*)(?=\\()"
captures:
1: constant.language.enum
push: enum
- match: (?<=[^\)\w])\.[a-zA-Z]\w*
scope: constant.language.enum
- match: "(?:[^\\)\\w]|^)\\.([a-zA-Z]\\w*)"
captures:
1: constant.language.enum
###################################################### CONSTANTS
- match: \btrue\b
scope: constant.language.true
Expand Down
250 changes: 132 additions & 118 deletions Swift/syntax_test.swift
@@ -1,200 +1,214 @@
/// SYNTAX TEST "Packages/Swift-for-f-ing-sublime/Swift.sublime-syntax"
// SYNTAX TEST "Packages/Swift-for-f-ing-sublime/Swift.sublime-syntax"

// comment
/// ^ comment.line
/// <- punctuation.definition.comment
// ^ comment.line
// <- punctuation.definition.comment

// MARK: testing!
/// ^ comment.line
/// ^ punctuation.definition.comment
/// ^ meta.toc-list
// ^ comment.line
// ^ punctuation.definition.comment
// ^ meta.toc-list


/* comment */
/// ^comment.block
// ^comment.block
/* 000 */
/// ^comment.block
/// ^ comment - constant
// ^comment.block
// ^ comment - constant
000 /* "string" */
/// <- -comment
/// ^comment.block
/// ^-string
// <- -comment
// ^comment.block
// ^-string

true
/// <- constant.language
/// <- constant.language.true
// <- constant.language
// <- constant.language.true
false
/// <- constant.language
/// <- constant.language.false
// <- constant.language
// <- constant.language.false
nil
/// <- constant.language
/// <- constant.language.nil
// <- constant.language
// <- constant.language.nil

1.1 100.001
/// <- constant.numeric
/// <- constant.numeric.float
/// ^ constant.numeric
/// ^ source.swift
// <- constant.numeric
// <- constant.numeric.float
// ^ constant.numeric
// ^ source.swift
100
/// <- constant.numeric
/// <- constant.numeric.decimal
// <- constant.numeric
// <- constant.numeric.decimal
1_000_000
/// ^ constant.numeric.decimal
// ^ constant.numeric.decimal
0xDEADBEEF
/// <- constant.numeric.hexadecimal
/// ^ constant.numeric.hexadecimal
// <- constant.numeric.hexadecimal
// ^ constant.numeric.hexadecimal
0xGGGGG
/// ^ -constant.numeric.hexadecimal
// ^ -constant.numeric.hexadecimal
0o12345670
/// <- constant.numeric.octal
/// ^ constant.numeric.octal
// <- constant.numeric.octal
// ^ constant.numeric.octal
0o8888
/// ^ -constant.numeric.octal
// ^ -constant.numeric.octal
0b01010110101
/// <- constant.numeric.binary
/// ^ constant.numeric.binary
// <- constant.numeric.binary
// ^ constant.numeric.binary
0b22222
/// ^ -constant.numeric.binary
// ^ -constant.numeric.binary

if { /**/ }
/// <- keyword.control
// <- keyword.control
where { /**/ }
/// <- keyword.control
// <- keyword.control

#if FOO
/// <- punctuation.definition.preprocessor
// <- punctuation.definition.preprocessor
#endif
/// ^ meta.preprocessor.c
// ^ meta.preprocessor.c

if a || b
/// <- keyword
/// ^ keyword.operator
// <- keyword
// ^ keyword.operator

public func foo
/// <- storage.modifier
/// ^ storage.type
/// ^ storage.type.function
/// ^ variable
/// ^ entity.name.function
// <- storage.modifier
// ^ storage.type
// ^ storage.type.function
// ^ variable
// ^ entity.name.function

self
/// <- keyword.variable
// <- keyword.variable
super
/// <- keyword.variable
// <- keyword.variable

Color
/// <- support.class
// <- support.class
UIColor
/// <- support.class
// <- support.class

enum Foo { case Value }
/// <- keyword.entity
/// ^ support.class
/// ^ entity.name.type
// <- keyword.entity
// ^ support.class
// ^ entity.name.type
enum Foo : String { case Value }
/// <- keyword.entity
/// ^ support.class
/// ^ entity.name.type
/// ^ support.class
// <- keyword.entity
// ^ support.class
// ^ entity.name.type
// ^ support.class

enum Foo : String {
case Value
/// ^ keyword.control
// ^ keyword.control
}

if foo {}
/// <- keyword.control
// <- keyword.control
else {}
/// <- keyword.control
// <- keyword.control
for {}
/// <- keyword.control
// <- keyword.control
while true {}
/// <- keyword.control
/// ^ constant
// <- keyword.control
// ^ constant
switch foo { case .Bar: }
/// <- keyword.control
/// ^ keyword.control
// <- keyword.control
// ^ keyword.control
break
/// <- keyword.control
// <- keyword.control
return
/// <- keyword.control
// <- keyword.control
case 0..0
/// <- keyword.control
/// ^ constant.numeric
/// ^ keyword.operator
/// ^ constant.numeric
// <- keyword.control
// ^ constant.numeric
// ^ keyword.operator
// ^ constant.numeric
continue
/// <- keyword.control
// <- keyword.control
default
/// <- keyword.control
// <- keyword.control

enum Foo
/// <- keyword.entity
/// ^ support.class
// <- keyword.entity
// ^ support.class
enum Foo : Bar {}
/// <- keyword.entity
/// ^ support.class
/// ^ support.class
// <- keyword.entity
// ^ support.class
// ^ support.class
struct Foo
/// <- keyword.entity
/// ^ support.class
// <- keyword.entity
// ^ support.class
struct Foo : Bar
/// ^ invalid
/// ^ invalid
// ^ invalid
// ^ invalid
class Foo
/// <- keyword.entity
/// ^ support.class
// <- keyword.entity
// ^ support.class
class Foo : Bar {}
/// <- keyword.entity
/// ^ support.class
/// ^ support.class
// <- keyword.entity
// ^ support.class
// ^ support.class
protocol Foo
/// <- keyword.entity
/// ^ support.class
// <- keyword.entity
// ^ support.class
protocol Foo : Bar {}
/// <- keyword.entity
/// ^ support.class
/// ^ support.class
// <- keyword.entity
// ^ support.class
// ^ support.class
extension Foo
/// <- keyword.entity
/// ^ support.class
// <- keyword.entity
// ^ support.class
extension Foo : Bar
/// <- keyword.entity
/// ^ support.class
/// ^ keyword.operator
/// ^ support.class
// <- keyword.entity
// ^ support.class
// ^ keyword.operator
// ^ support.class

func foo()
/// ^ variable.function
// ^ variable.function
class func foo()
/// <- meta.function
/// <- storage.type.function
/// ^ storage.type.function
// <- meta.function
// <- storage.type.function
// ^ storage.type.function

func foo() { foo }
/// ^ variable.function
/// ^ meta.function
// ^ variable.function
// ^ meta.function


func foo(a, b: String) { foo }
/// ^ variable.function
/// ^ meta.function
/// ^ variable.parameter
// ^ variable.function
// ^ meta.function
// ^ variable.parameter

"foo"
/// <- string
/// <- string.quoted
// <- string
// <- string.quoted

"foo\"" foo
/// <- string
/// ^ constant.character.escape
/// ^ constant.character.escape
/// ^ string
/// ^ -string
// <- string
// ^ constant.character.escape
// ^ constant.character.escape
// ^ string
// ^ -string

"foo \(bar + (foo * bar))"
/// <- string
/// ^ punctuation.section
/// ^ punctuation.section
/// ^ -string
/// ^ -punctuation.section
// <- string
// ^ punctuation.section
// ^ punctuation.section
// ^ -string
// ^ -punctuation.section

a = (.Foo(.bahr))
// ^ constant.language.enum
// ^ constant.language.enum

.Foo+.Bar
// <- constant.language.enum
// ^ -constant.language.enum
// ^ constant.language.enum

a.Foo + a.bar()
// <- -constant.language.enum
//^ -constant.language.enum
// ^ -constant.language.enum

0 comments on commit 25567bf

Please sign in to comment.