diff --git a/doc/KerboscriptLexer.py b/doc/KerboscriptLexer.py index 09db02720..61c69cd33 100644 --- a/doc/KerboscriptLexer.py +++ b/doc/KerboscriptLexer.py @@ -45,6 +45,7 @@ class KerboscriptLexer(RegexLexer): # stuck doing that forever. # (r'//[^\r\n]*[\r\n]', Comment.Single), + (r'/\*[^*]*\*+(?:[^/*][^*]*\*+)*/', Comment.MULTILINE), (r'"[^"]*"', String), (r'[\t\s\r\n]+', Text), #whitespace (r'[*/+|?<>=#^\-]', Operator), diff --git a/doc/source/language/syntax.rst b/doc/source/language/syntax.rst index b4d6c00e0..d5bec0efe 100644 --- a/doc/source/language/syntax.rst +++ b/doc/source/language/syntax.rst @@ -70,6 +70,8 @@ operator symbols: * ``//`` -> Comment indicator - starts a comment that runs until the end of the line. + * ``/* */`` -> Block comment delimiters - Everything between the + delimiters is a comment. * ``( )`` -> Used either to group expressions to change the order of operations (in the usual fashion), or to mark the parameters of a function being called, like ``min(a, b)``. @@ -97,6 +99,15 @@ operator symbols: set x to 1. // this is a comment. +*Block comments* consist of everything between "/\*" and "\*/". They can be multiple lines long:: + + /* this is a single line block comment. */ + + /* + this is a + multiline block comment. + */ + .. highlight:: none **Identifiers**: Identifiers consist of: a string of (letter, digit, or diff --git a/src/kOS.Safe/Compilation/KS/Scanner.cs b/src/kOS.Safe/Compilation/KS/Scanner.cs index 56b83520a..042153ac4 100644 --- a/src/kOS.Safe/Compilation/KS/Scanner.cs +++ b/src/kOS.Safe/Compilation/KS/Scanner.cs @@ -39,6 +39,7 @@ public Scanner() SkipList = new List(); SkipList.Add(TokenType.WHITESPACE); SkipList.Add(TokenType.COMMENTLINE); + SkipList.Add(TokenType.COMMENTBLOCK); regex = new Regex(@"\G(?:(\+|-))"); Patterns.Add(TokenType.PLUSMINUS, regex); @@ -376,6 +377,10 @@ public Scanner() Patterns.Add(TokenType.COMMENTLINE, regex); Tokens.Add(TokenType.COMMENTLINE); + regex = new Regex(@"\G(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/)"); + Patterns.Add(TokenType.COMMENTBLOCK, regex); + Tokens.Add(TokenType.COMMENTBLOCK); + } @@ -690,7 +695,8 @@ public enum TokenType CLOBBERBUILTINS= 150, EOF = 151, WHITESPACE= 152, - COMMENTLINE= 153 + COMMENTLINE= 153, + COMMENTBLOCK= 154 } public class Token diff --git a/src/kOS.Safe/Compilation/KS/kRISC.tpg b/src/kOS.Safe/Compilation/KS/kRISC.tpg index db0645a43..3f2bf3714 100644 --- a/src/kOS.Safe/Compilation/KS/kRISC.tpg +++ b/src/kOS.Safe/Compilation/KS/kRISC.tpg @@ -105,6 +105,8 @@ EOF -> @"$"; WHITESPACE -> @"(\s|\p{C})+"; [Skip] COMMENTLINE -> @"//[^\n]*\n?"; +[Skip] +COMMENTBLOCK -> @"/\*[^*]*\*+(?:[^/*][^*]*\*+)*/"; // Rules // ===================================================