Base Language Extensions Style Guide
Base Language is by far the most widely extended language in MPS. Since it is very likely that a typical MPS project will use a lot of different extensions from different sources or language vendors, the community might benefit from having a unified style across all languages. In this document we describe the conventions that creators should apply to all Base Language extensions.
Quick Reference
If you use... | Set its style to... |
|---|---|
.
| Dot |
[
| LeftBracket |
]
| RightBracket |
{
| LeftBrace |
}
| RightBrace |
=
+
-
*
/
%
++
--
!
==
!=
>
>=
<
<=
&&
||
?: (ternary)
~
<<
>>
>>>
&
^
|
:eq:
:ne:
| Operator |
@interface
abstract
assert
boolean
break
byte
case
catch
char
class
const
continue
default
do
double
else
enum
extends
false
final
finally
float
for
get
goto
if
implements
import
instanceof
int
interface
long
native
new
null
package
private
protected
public
return
set
short
static
strictfp
super
switch
synchronized
this
throw
throws
transient
try
true
void
volatile
while
| KeyWord |
Keywords
A keyword is a widely used string, which identifies important concepts from a language. For example, all the primitive types from Base Language are keywords. Also names of statements such as ifStatement, forStatement are keywords. Use the KeyWord style from base language's stylesheet for keywords.
Curly braces
Curly braces are often used to demarcate a block of code inside a containing construct. If you create an if-like construct, place the opening curly brace on the same line as the construct header. That is, use:
instead of
Use the LeftBrace and RightBrace styles to set correct offsets. Make sure that the space between a character to the left of the opening curly brace and the brace itself is exactly 1 space. You can do so with the help of padding-left/padding-right styles.
Parentheses
When you use parentheses, set the LeftParen/RightParen styles to the left/right parenthesis. If a parenthesis cell's sibling is a named node's property, disable the first/last position of a parenthesis with first/last-position-allowed style.
Identifiers
When you use named nodes such as methods, variables, and fields, their name properties should have zero left and right padding. It's also a good idea to give identifier declarations and references the same color. For example, in Base Language, field declarations and references share the same color.
Punctuation
If you have a semicolon somewhere, set its style to Semicolon. If you have a dot, use the Dot style. If you have a binary operator, use the Operator style for it.