()
| 29 | import cppp from './cppp-mode.js'; |
| 30 | |
| 31 | function definition(): monaco.languages.IMonarchLanguage { |
| 32 | const cppfront = $.extend(true, {}, cppp); // deep copy |
| 33 | cppfront.tokenPostfix = '.herb'; |
| 34 | cppfront.defaultToken = 'invalid'; |
| 35 | |
| 36 | // # Cpp2 token CSS class legend. |
| 37 | // |
| 38 | // Declaration/use of an _identifier_. |
| 39 | // - 'identifier.definition' |
| 40 | // - 'identifier.use' |
| 41 | // - 'keyword.identifier.definition' |
| 42 | // - 'keyword.identifier.use' |
| 43 | // |
| 44 | // Identifier that is contextually a type. |
| 45 | // - 'type.contextual' |
| 46 | // - 'keyword.type.contextual' |
| 47 | // |
| 48 | // Grammar term. |
| 49 | // - 'keyword.contract-kind' |
| 50 | // - 'keyword.this-specifier' |
| 51 | // - 'keyword.parameter-direction' |
| 52 | |
| 53 | // Generic parsers. |
| 54 | |
| 55 | function parseCpp2Balanced(delimiters: string, delimiter: string, opener: RegExp, closer: RegExp) { |
| 56 | return (cppfront.tokenizer['parse_cpp2_balanced_' + delimiters] = [ |
| 57 | {include: '@whitespace'}, |
| 58 | [opener, 'delimiter.' + delimiter, '$S2.$S3.$S4'], |
| 59 | [closer, 'delimiter.' + delimiter, '@pop'], |
| 60 | [/./, 'invalid', '@pop'], |
| 61 | ]); |
| 62 | } |
| 63 | parseCpp2Balanced('angles', 'angle', /</, />/); |
| 64 | parseCpp2Balanced('parentheses', 'parenthesis', /\(/, /\)/); |
| 65 | parseCpp2Balanced('squares', 'square', /\[/, /\]/); |
| 66 | parseCpp2Balanced('curlies', 'curly', /{/, /}/); |
| 67 | cppfront.tokenizer.parse_cpp2_balanced_punctuators = [ |
| 68 | // `$S2` is the parser. |
| 69 | [/</, {token: '@rematch', switchTo: 'parse_cpp2_balanced_angles.$S2.$S3'}], |
| 70 | [/\(/, {token: '@rematch', switchTo: 'parse_cpp2_balanced_parentheses.$S2'}], |
| 71 | [/\[/, {token: '@rematch', switchTo: 'parse_cpp2_balanced_squares.$S2.$S3'}], |
| 72 | [/{/, {token: '@rematch', switchTo: 'parse_cpp2_balanced_curlies.$S2.$S3.$S4'}], |
| 73 | ]; |
| 74 | |
| 75 | // Until the single character `$S2`, parses `$S3`. |
| 76 | cppfront.tokenizer.parse_cpp2_until = [ |
| 77 | {include: '@whitespace'}, |
| 78 | [ |
| 79 | /(.).*/, |
| 80 | { |
| 81 | cases: { |
| 82 | '$1==$S2': {token: '@rematch', next: '@pop'}, |
| 83 | '@': {token: '@rematch', next: '$S3'}, |
| 84 | }, |
| 85 | }, |
| 86 | ], |
| 87 | ]; |
| 88 |
no test coverage detected