godot-xterm/addons/godot_xterm/parser/transition_table.gd

27 lines
764 B
GDScript3
Raw Normal View History

2020-05-09 19:07:31 +02:00
# Copyright (c) 2019 The xterm.js authors. All rights reserved.
2020-05-10 12:56:49 +02:00
# Ported to GDScript by the GodotXterm authors.
2020-05-09 19:07:31 +02:00
# License MIT
extends Reference
enum TableAccess {
TRANSITION_ACTION_SHIFT = 4,
TRANSITION_STATE_MASK = 15,
INDEX_STATE_SHIFT = 8
}
var table: PoolByteArray = PoolByteArray()
func _init(length: int):
table.resize(length)
func setDefault(action: int, next: int):
for i in range(table.size()):
table[i] = action << TableAccess.TRANSITION_ACTION_SHIFT | next
func add(code: int, state: int, action: int, next: int):
table[state << TableAccess.INDEX_STATE_SHIFT | code] = action << TableAccess.TRANSITION_ACTION_SHIFT | next
func addMany(codes: Array, state: int, action: int, next: int):
for code in codes:
add(code, state, action, next)