Skip to content

Commit

Permalink
Merge pull request #3199 from masatake/masatake-gdscript
Browse files Browse the repository at this point in the history
GDScript based on #3194
  • Loading branch information
masatake authored Dec 1, 2021
2 parents 1d9e6fe + ebbfee1 commit c7c19ac
Show file tree
Hide file tree
Showing 38 changed files with 1,946 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Tmain/extras-long.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ p pseudo no NONE no Include pseudo tags
q qualified no NONE no Include an extra class-qualified tag entry for each tag
r reference no NONE no Include reference tags
s subparser yes NONE no Include tags generated by subparsers
- implicitClass no GDScript no Include tag for the implicitly defined unnamed class
- doubleSharps no IPythonCell no Include cells starting from ##
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
- funcmap yes QemuHX no Include mapping SQMP to C function name
Expand All @@ -20,6 +21,7 @@ p pseudo yes NONE no Include pseudo tags
q qualified no NONE no Include an extra class-qualified tag entry for each tag
r reference no NONE no Include reference tags
s subparser yes NONE no Include tags generated by subparsers
- implicitClass no GDScript no Include tag for the implicitly defined unnamed class
- doubleSharps no IPythonCell no Include cells starting from ##
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
- funcmap yes QemuHX no Include mapping SQMP to C function name
Expand All @@ -33,6 +35,7 @@ p pseudo yes NONE no Include pseudo tags
q qualified no NONE no Include an extra class-qualified tag entry for each tag
r reference no NONE no Include reference tags
s subparser yes NONE no Include tags generated by subparsers
- implicitClass no GDScript no Include tag for the implicitly defined unnamed class
- doubleSharps no IPythonCell no Include cells starting from ##
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
- funcmap yes QemuHX no Include mapping SQMP to C function name
Expand All @@ -46,6 +49,7 @@ p pseudo yes NONE no Include pseudo tags
q qualified no NONE no Include an extra class-qualified tag entry for each tag
r reference yes NONE no Include reference tags
s subparser yes NONE no Include tags generated by subparsers
- implicitClass no GDScript no Include tag for the implicitly defined unnamed class
- doubleSharps no IPythonCell no Include cells starting from ##
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
- funcmap yes QemuHX no Include mapping SQMP to C function name
Expand All @@ -59,6 +63,7 @@ p pseudo yes NONE no Include pseudo tags
q qualified yes NONE no Include an extra class-qualified tag entry for each tag
r reference yes NONE no Include reference tags
s subparser yes NONE no Include tags generated by subparsers
- implicitClass no GDScript no Include tag for the implicitly defined unnamed class
- doubleSharps no IPythonCell no Include cells starting from ##
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
- funcmap yes QemuHX no Include mapping SQMP to C function name
Expand Down
2 changes: 2 additions & 0 deletions Tmain/list-extras.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ p pseudo yes NONE no Include pseudo tags
q qualified yes NONE no Include an extra class-qualified tag entry for each tag
r reference yes NONE no Include reference tags
s subparser yes NONE no Include tags generated by subparsers
- implicitClass no GDScript no Include tag for the implicitly defined unnamed class
- doubleSharps no IPythonCell no Include cells starting from ##
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
- funcmap yes QemuHX no Include mapping SQMP to C function name
Expand All @@ -20,6 +21,7 @@ p pseudo yes NONE no Include pseudo tags
q qualified yes NONE no Include an extra class-qualified tag entry for each tag
r reference yes NONE no Include reference tags
s subparser yes NONE no Include tags generated by subparsers
- implicitClass no GDScript no Include tag for the implicitly defined unnamed class
- doubleSharps no IPythonCell no Include cells starting from ##
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
- funcmap yes QemuHX no Include mapping SQMP to C function name
Expand Down
1 change: 1 addition & 0 deletions Tmain/list-fields-with-prefix.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ x UCTAGSxpath no NONE s-- no -- xpath for
- UCTAGSmacrodef no CPreProcessor s-- no -- macro definition
- UCTAGSmacrodef no CUDA s-- no -- macro definition
- UCTAGSproperties no CUDA s-- no -- properties (static, inline, mutable,...)
- UCTAGSannotations yes GDScript s-- no -- annotations on functions and variables
- UCTAGShowImported no Go s-- no -- how the package is imported ("inline" for `.' or "init" for `_')
- UCTAGSpackage yes Go s-- no -- the real package specified by the package name
- UCTAGSpackageName yes Go s-- no -- the name for referring the package
Expand Down
1 change: 1 addition & 0 deletions Tmain/list-fields.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ z kind no NONE s-- no r- [tags output] prepend "kind:" to k/ (or K/) field outpu
- macrodef no CPreProcessor s-- no -- macro definition
- macrodef no CUDA s-- no -- macro definition
- properties no CUDA s-- no -- properties (static, inline, mutable,...)
- annotations yes GDScript s-- no -- annotations on functions and variables
- howImported no Go s-- no -- how the package is imported ("inline" for `.' or "init" for `_')
- package yes Go s-- no -- the real package specified by the package name
- packageName yes Go s-- no -- the name for referring the package
Expand Down
2 changes: 2 additions & 0 deletions Tmain/list-roles.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ DTD p/parameterEntity elementName on element names
DTD p/parameterEntity partOfAttDef on part of attribute definition
Elm m/module imported on imported module
Flex I/import import on imports
GDScript c/class extended on used as a base class for extending
Go p/package imported on imported package
Go u/unknown receiverType on receiver type
HTML C/stylesheet extFile on referenced as external files
Expand Down Expand Up @@ -141,6 +142,7 @@ DTD p/parameterEntity elementName on element names
DTD p/parameterEntity partOfAttDef on part of attribute definition
Elm m/module imported on imported module
Flex I/import import on imports
GDScript c/class extended on used as a base class for extending
Go p/package imported on imported package
Go u/unknown receiverType on receiver type
HTML C/stylesheet extFile on referenced as external files
Expand Down
1 change: 1 addition & 0 deletions Units/parser-gdscript.r/broken-input.d/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a crash test.
2 changes: 2 additions & 0 deletions Units/parser-gdscript.r/broken-input.d/input.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@foo
var
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--sort=no
--fields=+irK
--extras=+r
--extras-GDScript=-{implicitClass}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Node input.gd /^class_name MyNode extends Node$/;" class roles:extended
MyNode input.gd /^class_name MyNode extends Node$/;" class inherits:Node roles:def
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class_name MyNode extends Node
4 changes: 4 additions & 0 deletions Units/parser-gdscript.r/class_name-extends.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--sort=no
--fields=+irK
--extras=+r
--extras-GDScript=+{implicitClass}
2 changes: 2 additions & 0 deletions Units/parser-gdscript.r/class_name-extends.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MyNode input.gd /^class_name MyNode extends Node$/;" class inherits:Node roles:def
Node input.gd /^class_name MyNode extends Node$/;" class roles:extended
1 change: 1 addition & 0 deletions Units/parser-gdscript.r/class_name-extends.d/input.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class_name MyNode extends Node
5 changes: 5 additions & 0 deletions Units/parser-gdscript.r/inner-class.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--sort=no
--fields=+{inherits}{signature}
--kinds-GDScript=-{local}
--kinds-GDScript=-{parameter}
--extras-GDScript=+{implicitClass}
29 changes: 29 additions & 0 deletions Units/parser-gdscript.r/inner-class.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
anon_class_186e00360100 input.gd /^# Taken from godot-demo-projects\/networking\/webrtc_signaling\/server\/ws_webrtc_server.gd$/;" c inherits:Node
TIMEOUT input.gd /^const TIMEOUT = 1000 # Unresponsive clients times out after 1 sec$/;" C class:anon_class_186e00360100
SEAL_TIME input.gd /^const SEAL_TIME = 10000 # A sealed room will be closed after this time$/;" C class:anon_class_186e00360100
ALFNUM input.gd /^const ALFNUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"$/;" C class:anon_class_186e00360100
_alfnum input.gd /^var _alfnum = ALFNUM.to_ascii()$/;" v class:anon_class_186e00360100
rand input.gd /^var rand: RandomNumberGenerator = RandomNumberGenerator.new()$/;" v class:anon_class_186e00360100 typeref:typename:RandomNumberGenerator
lobbies input.gd /^var lobbies: Dictionary = {}$/;" v class:anon_class_186e00360100 typeref:typename:Dictionary
server input.gd /^var server: WebSocketServer = WebSocketServer.new()$/;" v class:anon_class_186e00360100 typeref:typename:WebSocketServer
peers input.gd /^var peers: Dictionary = {}$/;" v class:anon_class_186e00360100 typeref:typename:Dictionary
Peer input.gd /^class Peer extends Reference:$/;" c class:anon_class_186e00360100 inherits:Reference
id input.gd /^ var id = -1$/;" v class:anon_class_186e00360100.Peer
lobby input.gd /^ var lobby = ""$/;" v class:anon_class_186e00360100.Peer
time input.gd /^ var time = OS.get_ticks_msec()$/;" v class:anon_class_186e00360100.Peer
_init input.gd /^ func _init(peer_id):$/;" m class:anon_class_186e00360100.Peer signature:(peer_id)
Lobby input.gd /^class Lobby extends Reference:$/;" c class:anon_class_186e00360100 inherits:Reference
peers input.gd /^ var peers: Array = []$/;" v class:anon_class_186e00360100.Lobby typeref:typename:Array
host input.gd /^ var host: int = -1$/;" v class:anon_class_186e00360100.Lobby typeref:typename:int
sealed input.gd /^ var sealed: bool = false$/;" v class:anon_class_186e00360100.Lobby typeref:typename:bool
time input.gd /^ var time = 0$/;" v class:anon_class_186e00360100.Lobby
_init input.gd /^ func _init(host_id: int):$/;" m class:anon_class_186e00360100.Lobby signature:(host_id: int)
join input.gd /^ func join(peer_id, server) -> bool:$/;" m class:anon_class_186e00360100.Lobby typeref:typename:bool signature:(peer_id, server)
leave input.gd /^ func leave(peer_id, server) -> bool:$/;" m class:anon_class_186e00360100.Lobby typeref:typename:bool signature:(peer_id, server)
seal input.gd /^ func seal(peer_id, server) -> bool:$/;" m class:anon_class_186e00360100.Lobby typeref:typename:bool signature:(peer_id, server)
Circle2D input.gd /^class Circle2D:$/;" c class:anon_class_186e00360100 inherits:Node2D
center input.gd /^ var center$/;" v class:anon_class_186e00360100.Circle2D
radius input.gd /^ var radius$/;" v class:anon_class_186e00360100.Circle2D
color input.gd /^ var color$/;" v class:anon_class_186e00360100.Circle2D
_draw input.gd /^ func _draw():$/;" m class:anon_class_186e00360100.Circle2D signature:()
_init input.gd /^func _init():$/;" m class:anon_class_186e00360100 signature:()
96 changes: 96 additions & 0 deletions Units/parser-gdscript.r/inner-class.d/input.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Taken from godot-demo-projects/networking/webrtc_signaling/server/ws_webrtc_server.gd
# of https://github.com/godotengine/godot-demo-projects.git

extends Node

const TIMEOUT = 1000 # Unresponsive clients times out after 1 sec
const SEAL_TIME = 10000 # A sealed room will be closed after this time
const ALFNUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

var _alfnum = ALFNUM.to_ascii()

var rand: RandomNumberGenerator = RandomNumberGenerator.new()
var lobbies: Dictionary = {}
var server: WebSocketServer = WebSocketServer.new()
var peers: Dictionary = {}

class Peer extends Reference:
var id = -1
var lobby = ""
var time = OS.get_ticks_msec()

func _init(peer_id):
id = peer_id



class Lobby extends Reference:
var peers: Array = []
var host: int = -1
var sealed: bool = false
var time = 0

func _init(host_id: int):
host = host_id

func join(peer_id, server) -> bool:
if sealed: return false
if not server.has_peer(peer_id): return false
var new_peer: WebSocketPeer = server.get_peer(peer_id)
new_peer.put_packet(("I: %d\n" % (1 if peer_id == host else peer_id)).to_utf8())
for p in peers:
if not server.has_peer(p):
continue
server.get_peer(p).put_packet(("N: %d\n" % peer_id).to_utf8())
new_peer.put_packet(("N: %d\n" % (1 if p == host else p)).to_utf8())
peers.push_back(peer_id)
return true


func leave(peer_id, server) -> bool:
if not peers.has(peer_id): return false
peers.erase(peer_id)
var close = false
if peer_id == host:
# The room host disconnected, will disconnect all peers.
close = true
if sealed: return close
# Notify other peers.
for p in peers:
if not server.has_peer(p): return close
if close:
# Disconnect peers.
server.disconnect_peer(p)
else:
# Notify disconnection.
server.get_peer(p).put_packet(("D: %d\n" % peer_id).to_utf8())
return close


func seal(peer_id, server) -> bool:
# Only host can seal the room.
if host != peer_id: return false
sealed = true
for p in peers:
server.get_peer(p).put_packet("S: \n".to_utf8())
time = OS.get_ticks_msec()
return true


# Taken from godot-demo-projects/2d/physics_tests/test.gd
class Circle2D:
extends Node2D
var center
var radius
var color

func _draw():
draw_circle(center, radius, color)

func _init():
server.connect("data_received", self, "_on_data")
server.connect("client_connected", self, "_peer_connected")
server.connect("client_disconnected", self, "_peer_disconnected")


# ...
4 changes: 4 additions & 0 deletions Units/parser-gdscript.r/modifiers.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--sort=no
--kinds-GDScript=+zl
--fields-GDScript={annotations}
--extras-GDScript=+{implicitClass}
14 changes: 14 additions & 0 deletions Units/parser-gdscript.r/modifiers.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
anon_class_025551790100 input.gd /^# Taken from godot-demo-projects\/3d\/voxel\/world\/chunk.gd$/;" c
_create_block_collider input.gd /^func _create_block_collider(block_sub_position):$/;" m class:anon_class_025551790100
block_sub_position input.gd /^func _create_block_collider(block_sub_position):$/;" z method:anon_class_025551790100._create_block_collider file:
collider input.gd /^ var collider = CollisionShape.new()$/;" l method:anon_class_025551790100._create_block_collider file:
calculate_block_uvs input.gd /^static func calculate_block_uvs(block_id):$/;" m class:anon_class_025551790100 annotations:static
block_id input.gd /^static func calculate_block_uvs(block_id):$/;" z method:anon_class_025551790100.calculate_block_uvs file:
row input.gd /^ var row = block_id \/ TEXTURE_SHEET_WIDTH$/;" l method:anon_class_025551790100.calculate_block_uvs file:
col input.gd /^ var col = block_id % TEXTURE_SHEET_WIDTH$/;" l method:anon_class_025551790100.calculate_block_uvs file:
id input.gd /^func id(a):$/;" m class:anon_class_025551790100
a input.gd /^func id(a):$/;" z method:anon_class_025551790100.id file:
r input.gd /^remote func r(b):$/;" m class:anon_class_025551790100 annotations:remote
b input.gd /^remote func r(b):$/;" z method:anon_class_025551790100.r file:
x input.gd /^remote static func x(c):$/;" m class:anon_class_025551790100 annotations:remote,static
c input.gd /^remote static func x(c):$/;" z method:anon_class_025551790100.x file:
28 changes: 28 additions & 0 deletions Units/parser-gdscript.r/modifiers.d/input.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Taken from godot-demo-projects/3d/voxel/world/chunk.gd
func _create_block_collider(block_sub_position):
var collider = CollisionShape.new()
collider.shape = BoxShape.new()
collider.shape.extents = Vector3.ONE / 2
collider.transform.origin = block_sub_position + Vector3.ONE / 2
add_child(collider)

static func calculate_block_uvs(block_id):
# This method only supports square texture sheets.
var row = block_id / TEXTURE_SHEET_WIDTH
var col = block_id % TEXTURE_SHEET_WIDTH

return [
TEXTURE_TILE_SIZE * Vector2(col, row),
TEXTURE_TILE_SIZE * Vector2(col, row + 1),
TEXTURE_TILE_SIZE * Vector2(col + 1, row),
TEXTURE_TILE_SIZE * Vector2(col + 1, row + 1),
]

func id(a):
return a

remote func r(b):
return b

remote static func x(c):
return c
3 changes: 3 additions & 0 deletions Units/parser-gdscript.r/no-implicit-class.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--sort=no
--extras=+r
--fields=+rEiS
27 changes: 27 additions & 0 deletions Units/parser-gdscript.r/no-implicit-class.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
BaseClass input.gd /^extends BaseClass$/;" c roles:extended extras:reference
MyClass input.gd /^class_name MyClass, "res:\/\/path\/to\/optional\/icon.svg"$/;" c roles:def
a input.gd /^@export_range(start=0, end=100, step=1) var a = 5$/;" v roles:def annotations:export_range(start=0, end=100, step=1)
s input.gd /^var s = "Hello"$/;" v roles:def annotations:export
arr input.gd /^@onready var arr = [1, 2, 3]$/;" v roles:def annotations:onready
dict input.gd /^var dict = {"key": "value", 2: 3}$/;" v roles:def
typed_var input.gd /^var typed_var: int$/;" v typeref:typename:int roles:def
inferred_type input.gd /^inferred_type\\$/;" v roles:def annotations:onready,export_multiline
ANSWER input.gd /^const ANSWER = 42$/;" C roles:def
THE_NAME input.gd /^const THE_NAME:String = "Charly"$/;" C typeref:typename:String roles:def
anon_enum_84e343bf0104 input.gd /^enum {UNIT_NEUTRAL, UNIT_ENEMY, UNIT_ALL}$/;" g roles:def extras:anonymous
UNIT_NEUTRAL input.gd /^enum {UNIT_NEUTRAL, UNIT_ENEMY, UNIT_ALL}$/;" e enum:anon_enum_84e343bf0104 file: roles:def
UNIT_ENEMY input.gd /^enum {UNIT_NEUTRAL, UNIT_ENEMY, UNIT_ALL}$/;" e enum:anon_enum_84e343bf0104 file: roles:def
UNIT_ALL input.gd /^enum {UNIT_NEUTRAL, UNIT_ENEMY, UNIT_ALL}$/;" e enum:anon_enum_84e343bf0104 file: roles:def
Named input.gd /^enum Named {THING_1, THING_2, ANOTHER_THING=1}$/;" g roles:def
THING_1 input.gd /^enum Named {THING_1, THING_2, ANOTHER_THING=1}$/;" e enum:Named file: roles:def
THING_2 input.gd /^enum Named {THING_1, THING_2, ANOTHER_THING=1}$/;" e enum:Named file: roles:def
ANOTHER_THING input.gd /^enum Named {THING_1, THING_2, ANOTHER_THING=1}$/;" e enum:Named file: roles:def
v2 input.gd /^var v2 = Vector2(1, 2)$/;" v roles:def
v3 input.gd /^var v3 = Vector3(1, 2, 3)$/;" v roles:def
some_function input.gd /^func some_function(param1: Vector3, param2: int) -> int:$/;" m typeref:typename:int signature:(param1: Vector3, param2: int) roles:def annotations:master
something input.gd /^func something(p1, p2):$/;" m signature:(p1, p2) roles:def annotations:puppet
Something input.gd /^class Something:$/;" c inherits: roles:def
a input.gd /^ var a = 10$/;" v class:Something roles:def
_private_var input.gd /^ const _private_var:String = "hi\\n\\\\escape"$/;" C class:Something typeref:typename:String roles:def
foooooooo input.gd /^ func foooooooo() -> String:$/;" m class:Something typeref:typename:String signature:() roles:def
_init input.gd /^func _init():$/;" m signature:() roles:def
Loading

0 comments on commit c7c19ac

Please sign in to comment.