Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block comment support #3032

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/KerboscriptLexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 11 additions & 0 deletions doc/source/language/syntax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)``.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/kOS.Safe/Compilation/KS/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public Scanner()
SkipList = new List<TokenType>();
SkipList.Add(TokenType.WHITESPACE);
SkipList.Add(TokenType.COMMENTLINE);
SkipList.Add(TokenType.COMMENTBLOCK);

regex = new Regex(@"\G(?:(\+|-))");
Patterns.Add(TokenType.PLUSMINUS, regex);
Expand Down Expand Up @@ -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);


}

Expand Down Expand Up @@ -690,7 +695,8 @@ public enum TokenType
CLOBBERBUILTINS= 150,
EOF = 151,
WHITESPACE= 152,
COMMENTLINE= 153
COMMENTLINE= 153,
COMMENTBLOCK= 154
}

public class Token
Expand Down
2 changes: 2 additions & 0 deletions src/kOS.Safe/Compilation/KS/kRISC.tpg
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ EOF -> @"$";
WHITESPACE -> @"(\s|\p{C})+";
[Skip]
COMMENTLINE -> @"//[^\n]*\n?";
[Skip]
COMMENTBLOCK -> @"/\*[^*]*\*+(?:[^/*][^*]*\*+)*/";

// Rules
// ===================================================
Expand Down