Skip to content

Commit

Permalink
Fix regex from as? to as\?; add one more test case for !==
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroql authored and alecthomas committed Aug 11, 2020
1 parent 8a54f9e commit aac3294
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
8 changes: 6 additions & 2 deletions lexers/k/kotlin.go
Expand Up @@ -26,7 +26,7 @@ var Kotlin = internal.Register(MustNewLexer(
{`\n`, Text, nil},
{`!==|!in|!is|===`, Operator, nil},
{`%=|&&|\*=|\+\+|\+=|--|-=|->|\.\.|\/=|::|<=|==|>=|!!|!=|\|\||\?[:.]`, Operator, nil},
{`[~!%^&*()+=|\[\]:;,.<>/?-]`, Punctuation, nil},
{`[~!%^&*()+=|\[\]:;,.<>\/?-]`, Punctuation, nil},
{`[{}]`, Punctuation, nil},
{`"""[^"]*"""`, LiteralString, nil},
{`"(\\\\|\\"|[^"\n])*["\n]`, LiteralString, nil},
Expand All @@ -37,7 +37,7 @@ var Kotlin = internal.Register(MustNewLexer(
{`(package|import)(\s+)`, ByGroups(Keyword, Text), Push("package")},
{`(val|var)(\s+)`, ByGroups(Keyword, Text), Push("property")},
{`(fun)(\s+)(<[^>]*>\s+)?`, ByGroups(Keyword, Text, Text), Push("function")},
{`(abstract|actual|annotation|as|as?|break|by|catch|class|companion|const|constructor|continue|crossinline|data|delegate|do|dynamic|else|enum|expect|external|false|field|file|final|finally|for|fun|get|if|import|in|infix|init|inline|inner|interface|internal|is|it|lateinit|noinline|null|object|open|operator|out|override|package|param|private|property|protected|public|receiver|reified|return|sealed|set|setparam|super|suspend|tailrec|this|throw|true|try|typealias|typeof|val|var|vararg|when|where|while)\b`, Keyword, nil},
{`(abstract|actual|annotation|as|as\?|break|by|catch|class|companion|const|constructor|continue|crossinline|data|delegate|do|dynamic|else|enum|expect|external|false|field|file|final|finally|for|fun|get|if|import|in|infix|init|inline|inner|interface|internal|is|it|lateinit|noinline|null|object|open|operator|out|override|package|param|private|property|protected|public|receiver|reified|return|sealed|set|setparam|super|suspend|tailrec|this|throw|true|try|typealias|typeof|val|var|vararg|when|where|while)\b`, Keyword, nil},
{"(@?[" + kotlinIdentifier + "]*`)", Name, nil},
},
"package": {
Expand All @@ -50,6 +50,10 @@ var Kotlin = internal.Register(MustNewLexer(
{"(@?[" + kotlinIdentifier + " ]*`)", NameProperty, Pop(1)},
},
"function": {

{`[~!%^&*()+=|\[\]:;,.<>\/?-]`, Punctuation, nil},
{`(abstract|actual|annotation|as|as\?|break|by|catch|class|companion|const|constructor|continue|crossinline|data|delegate|do|dynamic|else|enum|expect|external|false|field|file|final|finally|for|fun|get|if|import|in|infix|init|inline|inner|interface|internal|is|it|lateinit|noinline|null|object|open|operator|out|override|package|param|private|property|protected|public|receiver|reified|return|sealed|set|setparam|super|suspend|tailrec|this|throw|true|try|typealias|typeof|val|var|vararg|when|where|while)\b`, Keyword, nil},

{"(@?[" + kotlinIdentifier + " ]*`)", NameFunction, Pop(1)},
},
},
Expand Down
3 changes: 2 additions & 1 deletion lexers/testdata/kotlin.actual
Expand Up @@ -62,7 +62,8 @@ fun moreOperators(arg: Any?) {
in emptyList<Int>() -> { }
}

println(arg === Unit)
if(arg !== Boolean)
println(arg === Unit)
}

class X {
Expand Down
43 changes: 26 additions & 17 deletions lexers/testdata/kotlin.expected
Expand Up @@ -171,7 +171,7 @@
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"_"},
Expand All @@ -186,7 +186,7 @@
{"type":"Text","value":" "},
{"type":"NameFunction","value":"someOperators"},
{"type":"Punctuation","value":"("},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":" "},
{"type":"Name","value":"Int"},
Expand Down Expand Up @@ -220,7 +220,7 @@
{"type":"Name","value":"println"},
{"type":"Punctuation","value":"("},
{"type":"Text","value":" "},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"%"},
{"type":"Text","value":" "},
Expand All @@ -233,30 +233,30 @@
{"type":"Text","value":" "},
{"type":"Keyword","value":"in"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Operator","value":".."},
{"type":"Name","value":"b"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n \n "},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"%="},
{"type":"Text","value":" "},
{"type":"LiteralNumber","value":"2"},
{"type":"Text","value":"\n\t"},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"\u0026\u0026"},
{"type":"Text","value":" "},
{"type":"Name","value":"b"},
{"type":"Text","value":"\n\t"},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"*="},
{"type":"Text","value":" "},
{"type":"LiteralNumber","value":"2"},
{"type":"Text","value":"\n\t"},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Operator","value":"++"},
{"type":"Text","value":"\n\t"},
{"type":"Name","value":"b"},
Expand All @@ -266,17 +266,17 @@
{"type":"Name","value":"b"},
{"type":"Operator","value":"--"},
{"type":"Text","value":"\n\t"},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Operator","value":"-="},
{"type":"LiteralNumber","value":"1"},
{"type":"Text","value":"\n\t"},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"/="},
{"type":"Text","value":" "},
{"type":"LiteralNumber","value":"2"},
{"type":"Text","value":"\n\t"},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"\u003c="},
{"type":"Text","value":" "},
Expand All @@ -286,9 +286,9 @@
{"type":"Text","value":" "},
{"type":"Operator","value":"=="},
{"type":"Text","value":" "},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Text","value":"\n\t"},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"\u003e="},
{"type":"Text","value":" "},
Expand All @@ -297,23 +297,23 @@
{"type":"Name","value":"nullable"},
{"type":"Operator","value":"!!"},
{"type":"Text","value":"\n\t"},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"!="},
{"type":"Text","value":" "},
{"type":"Name","value":"b"},
{"type":"Text","value":"\n\t"},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"||"},
{"type":"Text","value":" "},
{"type":"Name","value":"b"},
{"type":"Text","value":"\n\t"},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Operator","value":"?."},
{"type":"Name","value":"foo"},
{"type":"Text","value":"\n\t"},
{"type":"Keyword","value":"a"},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"?:"},
{"type":"Text","value":" "},
Expand Down Expand Up @@ -395,6 +395,15 @@
{"type":"Text","value":"\n "},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n "},
{"type":"Keyword","value":"if"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"arg"},
{"type":"Text","value":" "},
{"type":"Operator","value":"!=="},
{"type":"Text","value":" "},
{"type":"Name","value":"Boolean"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n \t"},
{"type":"Name","value":"println"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"arg"},
Expand Down

0 comments on commit aac3294

Please sign in to comment.