Skip to content

EttyKitty/Gobo

 
 

Repository files navigation

Gobo: GML Formatter

Try the formatter here!

Gobo is an opinionated formatter for GameMaker Language. It enforces a consistent style by parsing and re-printing your code with its own rules, taking maximum line length into account.

By using Gobo, you agree to cede control over the nitty-gritty details of formatting. In return, Gobo gives you speed, determinism, and smaller git diffs. End style debates with your team and save mental energy for what's important!

Gobo provides a few basic formatting options and has no plans to add more. It follows the Option Philosophy of Prettier.

⭐ What is different in this fork?

  • An option to format structs vertically.
  • An option to format arrays vertically (1-length arrays are exempt).
    • (Both of the above work only during variable initialization/declaration, and won't format vars in statements/expressions)
  • An option to disable line width limit completely, instead of having to set it to 999.
  • Array accessors will be chained separately (array[0, 2] > array[0][2]).

Input

x = a and b or c  a=0xFG=1 var var var i := 0
do begin
;;;;show_debug_message(i)
;;;;++constructor
end until not constructor < 10 return

call()

Output

x = a && b || c;
a = 0xF;
G = 1;
var i = 0;
do {
    show_debug_message(i);
    ++constructor;
} until (!constructor < 10)
return call();

How does it work?

Gobo is written in C# and compiles to a self-contained binary using Native AOT in .NET 8.

Gobo uses a custom GML parser to read your code and ensure that formatted code is equivalent to the original. The parser is designed to only accept valid GML (with a few exceptions) to ensure correctness. There is no officially-documented format for GML's syntax tree, so Gobo uses a format similar to JavaScript parsers.

Gobo converts your code into an intermediate "Doc" format to make decisions about wrapping lines and printing comments. The doc printing algorithm is taken from CSharpier, which is itself adapted from Prettier.

Limitations

Gobo cannot parse code that relies on macro expansion to be valid. Any standalone expression will be formatted with a semicolon, even if the expression is a macro.

THESE_MACROS;
ARE.VALID;
BECAUSE_THEY_ARE_EXPRESSIONS()

About

Gobo is an opinionated code formatter for GameMaker Language (GML).

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • C# 87.3%
  • JavaScript 7.1%
  • HTML 4.5%
  • CSS 1.1%