From ede5eff0ca6cda376a650818b559222643011a88 Mon Sep 17 00:00:00 2001 From: DanTGL <33489389+DanTGL@users.noreply.github.com> Date: Fri, 10 Dec 2021 20:18:13 +0100 Subject: [PATCH 1/3] Added comment block support to KerboScript --- src/kOS.Safe/Compilation/KS/Scanner.cs | 8 +++++++- src/kOS.Safe/Compilation/KS/kRISC.tpg | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/kOS.Safe/Compilation/KS/Scanner.cs b/src/kOS.Safe/Compilation/KS/Scanner.cs index 4b47fad089..cd1e5a96d2 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); @@ -372,6 +373,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); + } @@ -684,7 +689,8 @@ public enum TokenType LAZYGLOBAL= 148, EOF = 149, WHITESPACE= 150, - COMMENTLINE= 151 + COMMENTLINE= 151, + COMMENTBLOCK= 152 } public class Token diff --git a/src/kOS.Safe/Compilation/KS/kRISC.tpg b/src/kOS.Safe/Compilation/KS/kRISC.tpg index c646ec3a95..7b7ae4caee 100644 --- a/src/kOS.Safe/Compilation/KS/kRISC.tpg +++ b/src/kOS.Safe/Compilation/KS/kRISC.tpg @@ -103,6 +103,8 @@ EOF -> @"$"; WHITESPACE -> @"(\s|\p{C})+"; [Skip] COMMENTLINE -> @"//[^\n]*\n?"; +[Skip] +COMMENTBLOCK -> @"/\*[^*]*\*+(?:[^/*][^*]*\*+)*/"; // Rules // =================================================== From 81e192986ec79599b204e321df963a07b146d9e1 Mon Sep 17 00:00:00 2001 From: DanTGL <33489389+DanTGL@users.noreply.github.com> Date: Fri, 10 Dec 2021 21:37:43 +0100 Subject: [PATCH 2/3] Updated docs with block comments. --- doc/KerboscriptLexer.py | 1 + doc/source/language/syntax.rst | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/doc/KerboscriptLexer.py b/doc/KerboscriptLexer.py index 09db027201..61c69cd332 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 b4d6c00e06..d5bec0efea 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 From 3c53ec78081c3a2daf8f955243212e7b14324f66 Mon Sep 17 00:00:00 2001 From: DanTGL <33489389+DanTGL@users.noreply.github.com> Date: Sun, 15 May 2022 13:22:56 +0200 Subject: [PATCH 3/3] Regenerated Scanner.cs --- src/kOS.Safe/Compilation/KS/Scanner.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/kOS.Safe/Compilation/KS/Scanner.cs b/src/kOS.Safe/Compilation/KS/Scanner.cs index b438a9ead4..042153ac46 100644 --- a/src/kOS.Safe/Compilation/KS/Scanner.cs +++ b/src/kOS.Safe/Compilation/KS/Scanner.cs @@ -695,7 +695,8 @@ public enum TokenType CLOBBERBUILTINS= 150, EOF = 151, WHITESPACE= 152, - COMMENTLINE= 153 + COMMENTLINE= 153, + COMMENTBLOCK= 154 } public class Token