Quellcode durchsuchen

[highlightjs] Add virtual method keywords. (#1377)

This also tidies up the keyword detection for classes a bit so we won't
highlight bizarre things like `allyourbase class`, or `base classy` etc.
Chandler Carruth vor 3 Jahren
Ursprung
Commit
b4d4f5423d
2 geänderte Dateien mit 9 neuen und 5 gelöschten Zeilen
  1. 3 3
      highlighting/highlightjs_carbon_lang.js
  2. 6 2
      highlighting/highlightjs_example.html

+ 3 - 3
highlighting/highlightjs_carbon_lang.js

@@ -371,8 +371,8 @@ export default function (hljs) {
   };
   const FUNCTION = {
     scope: 'carbon-function',
-    begin: /fn/,
-    beginScope: 'keyword',
+    begin: [/(\b(virtual|abstract|impl)\b)?/, /\s*/, /\bfn\b/],
+    beginScope: { 1: 'keyword', 3: 'keyword' },
     end: /\s*[;{]/,
     returnEnd: true,
     contains: [FUNCTION_NAME_COMPONENT, RETURN_SPECIFIER],
@@ -406,7 +406,7 @@ export default function (hljs) {
     variants: [
       {
         scope: 'carbon-class',
-        begin: [/(base|abstract)?/, /\s*/, /class/],
+        begin: [/(\b(base|abstract)\b)?/, /\s*/, /\bclass\b/],
         beginScope: {
           1: 'keyword',
           3: 'keyword',

+ 6 - 2
highlighting/highlightjs_example.html

@@ -49,8 +49,12 @@ interface WidgetI {
 constraint WidgetC {
 }
 
+abstract class Abstract {
+  abstract fn DoSomething[me: Self]();
+}
+
 base class Widget {
-  fn Print[addr me: Self*](var i: i64, x: f32 = 4.2, _: bool);
+  virtual fn Print[addr me: Self*](var i: i64, x: f32 = 4.2, _: bool);
 }
 
 fn Widget.Print[addr me: Self*](var i: i64, x: f32, _: bool, 47) {
@@ -68,7 +72,7 @@ fn Widget.Print[addr me: Self*](var i: i64, x: f32, _: bool, 47) {
 }
 
 class FancyWidget(T:! Type) extends Widget {
-  fn Print[me: Self]();
+  impl fn Print[me: Self]();
 
   impl as Add(T) {
     fn Op[me: Self]();