1/** 2 * @license 3 * Copyright (C) 2017 Michał Bączkowski 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18/** 19 * @fileoverview 20 * Registers a language handler for Kotlin. 21 * 22 * Limitations: 23 * - doesn't support string interpolation ("$var") 24 * - doesn't support labels if there is no space between the keyword (break@loop, loop@for) 25 * 26 * @author mibac138@gmail.com 27 */ 28 29PR['registerLangHandler']( 30 PR['createSimpleLexer']( 31 [ 32 [PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'], 33 [PR['PR_PUNCTUATION'], /^[.!%&()*+,\-;<=>?\[\\\]^{|}:]+/, null, '.!%&()*+,-;<=>?[\\]^{|}:'] 34 ], 35 [ 36 // keywords 37 [PR['PR_KEYWORD'], 38 /^\b(package|public|protected|private|open|abstract|constructor|final|override|import|for|while|as|typealias|get|set|((data|enum|annotation|sealed) )?class|this|super|val|var|fun|is|in|throw|return|break|continue|(companion )?object|if|try|else|do|when|init|interface|typeof)\b/], 39 [PR['PR_LITERAL'], /^(?:true|false|null)\b/], 40 // number literals 41 [PR['PR_LITERAL'], /^(0[xX][0-9a-fA-F_]+L?|0[bB][0-1]+L?|[0-9_.]+([eE]-?[0-9]+)?[fFL]?)/], 42 [PR['PR_TYPE'], /^(\b[A-Z]+[a-z][a-zA-Z0-9_$@]*|`.*`)/, null], 43 //double slash comments 44 [PR['PR_COMMENT'], /^\/\/.*/], 45 //slash star comments and documentation 46 [PR['PR_COMMENT'], /^\/\*[\s\S]*?(?:\*\/|$)/], 47 // char 48 [PR['PR_STRING'], /'.'/], 49 // string 50 [PR['PR_STRING'], /^"([^"\\]|\\[\s\S])*"/], 51 // multiline string 52 [PR['PR_STRING'], /^"{3}[\s\S]*?[^\\]"{3}/], 53 // annotation (and label) 54 [PR['PR_LITERAL'], /^@([a-zA-Z0-9_$@]*|`.*`)/], 55 // label definition 56 [PR['PR_LITERAL'], /^[a-zA-Z0-9_]+@/] 57 ]), 58 ['kotlin']); 59