Install Asset
Install via Godot
To maintain one source of truth, Godot Asset Library is just a mirror of the old asset library so you can download directly on Godot via the integrated asset library browser



Quick Information

A small godot project with a (very simple) tokenizer written in GDScript. Supports bash like commands and command chains/pipes. BETA: I have not tested this really well yet. Please use with care.
GD-Tokenizer
A small godot project with a (very simple) tokenizer written in GDScript.
Screenshots
Details
This project includes:
- a terminal to input bash like commands
- a very naive and simple tokenizer
- a method to execute the result of the tokenizer
Features:
- string support (double and single quoted)
- bash like commands
- multiple commands in one line (seperator:
;
) - command piping with
|
(reuse command output as the input for the next command)
What this currently can not do:
- flow control structures like
if
,for
orwhile
- subshells
The tokenizer is seperated from the execution/parsing. It should be
relatively easy to implement your own execution method. If you want
to support things like if
, for
or while
you could implement these
in the execution method, there is no need to change the tokenizing method.
You may need to define a few more tokens though.
Files
Some important files/directories:
./cmd
./cmd/BashLikeCommands.gd
(class that provides a few example bash commands)./cmd/CommandParser.gd
(class containing the tokenizer and a method to execute results)./fonts
./fonts/fira-code
(directory containing the monospace font I use for the terminal)./ExampleTerminal.tscn
(scene with a minimalistic terminal setup)./ExampleTerminal.gd
(implements the behaviour of the terminal scene)
Usage
Minimal Example
extends Node
var parser := CommandParser.new()
var commands := BashLikeCommands.new()
func _ready():
# Parse and execute one of the bash like commands: echo
var result := parser.tokenize("echo 'Hello world!'")
var stdout := parser.execute(result, [self, commands], "%s")
print(stdout)
# Parse and execute the command 'hello' defined below
var result := parser.tokenize("hello 'godot'")
var stdout := parser.execute(result, [self, commands], "%s")
print(stdout)
func cmd_hello(args: Array, stdin: String):
if args.size() == 0:
return "Hello unknown person!"
elif args.size() == 1:
return "Hello %s!"
else:
return "Error: too many arguments"
Tokenizer and executor method
The most important file is ./cmd/CommandParser.gd
. This is where the tokenization
and execution methods are defined.
To use the class file you need to create a parser object with var parser := CommandParser.new()
.
It provides two important methods:
CommandParser.tokenize(input)
Arguments:
input
: String
This method will tokenize your input.
Returns: object of type TokenizedResult
CommandParser.execute()
Arguments:
tr
: TokenResultproviders
: Array of Objectserr_tpl
: String (where%s
represents the error)pre
: String
This method takes a TokenizedResult and tries to execute it. You need to call execute()
using a list of command providers and an error template. The template is used to
format errors, the simplest possible of which is '%s'
(which simply represents only the error itself).
A command provider can implement commands by defining methods that start with
cmd_
. This prefix can be changed with an optional parameter. If you want to use
the bash like commands, you can add an instance of BashLikeCommands
to the command
provider list.
License
All files (except the fonts in ./fonts/fira-code
) are licensed by the MIT License.
Please see the License File for more details.
The font used in the Terminal is named "fira-code". Please see the License File for more details.
Links to other projects
All links in this section point to amazing external projects. These are not created by me.
TODO (Add to this readme later)
- how to define your own tokens
- how to write your own executor (maybe?)
A small godot project with a (very simple) tokenizer written in GDScript. Supports bash like commands and command chains/pipes. BETA: I have not tested this really well yet. Please use with care.
Reviews
Quick Information

A small godot project with a (very simple) tokenizer written in GDScript. Supports bash like commands and command chains/pipes. BETA: I have not tested this really well yet. Please use with care.