1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-02-05 13:05:18 +02:00

Added updated GDScript lexer. (#842)

This commit is contained in:
Andrew Moore 2023-09-04 17:33:36 -04:00 committed by GitHub
parent 4796a27270
commit 6428fb4e65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1252 additions and 493 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,268 @@
<lexer>
<config>
<name>GDScript3</name>
<alias>gdscript3</alias>
<alias>gd3</alias>
<filename>*.gd</filename>
<mime_type>text/x-gdscript</mime_type>
<mime_type>application/x-gdscript</mime_type>
<analyse single="true">
<regex pattern="^export" score="0.1"/>
</analyse>
</config>
<rules>
<state name="builtins">
<rule pattern="(?&lt;!\.)(instance_from_id|nearest_po2|print_stack|type_exist|rand_range|linear2db|var2bytes|dict2inst|randomize|bytes2var|rand_seed|db2linear|inst2dict|printerr|printraw|decimals|preload|deg2rad|str2var|stepify|var2str|convert|weakref|fposmod|funcref|rad2deg|dectime|printt|is_inf|is_nan|assert|Color8|typeof|ColorN|prints|floor|atan2|yield|randf|print|range|clamp|round|randi|sqrt|tanh|cosh|ceil|ease|acos|load|fmod|lerp|seed|sign|atan|sinh|hash|asin|sin|str|cos|tan|pow|exp|min|abs|log|max)\b">
<token type="NameBuiltin"/>
</rule>
<rule pattern="(?&lt;!\.)(self|false|true|PI|NAN|INF)\b">
<token type="NameBuiltinPseudo"/>
</rule>
<rule pattern="(?&lt;!\.)(Physics2DShapeQueryParameters|PhysicsShapeQueryParameters|Physics2DDirectBodyStateSW|NavigationPolygonInstance|ResourceInteractiveLoader|Physics2DDirectSpaceState|Physics2DShapeQueryResult|Physics2DTestMotionResult|InputEventJoystickButton|InputEventJoystickMotion|Physics2DDirectBodyState|PhysicsDirectBodyStateSW|PhysicsShapeQueryResult|PhysicsDirectSpaceState|SpatialSound2DServerSW|PackedDataContainerRef|NavigationMeshInstance|ResourceImportMetadata|PhysicsDirectBodyState|ConcavePolygonShape2D|CanvasItemShaderGraph|EditorScenePostImport|InputEventScreenTouch|InputEventMouseButton|InputEventMouseMotion|SpatialSound2DServer|AudioStreamOGGVorbis|VisibilityNotifier2D|InputEventScreenDrag|ConvexPolygonShape2D|SpatialSoundServerSW|ParticleAttractor2D|PackedDataContainer|SpatialStreamPlayer|RenderTargetTexture|AnimationTreePlayer|ConcavePolygonShape|InstancePlaceholder|MaterialShaderGraph|AudioStreamPlayback|VisibilityEnabler2D|SpatialSamplePlayer|DampedSpringJoint2D|InterpolatedCamera|ConvexPolygonShape|ConfirmationDialog|SpatialSoundServer|BakedLightInstance|ParallaxBackground|CollisionPolygon2D|CanvasItemMaterial|VisibilityNotifier|EditorImportPlugin|VideoStreamTheora|TouchScreenButton|ResourcePreloader|OccluderPolygon2D|BakedLightSampler|CollisionObject2D|RemoteTransform2D|PolygonPathFinder|StyleBoxImageMask|NavigationPolygon|TranslationServer|MultiMeshInstance|ImmediateGeometry|Physics2DServerSW|ColorPickerButton|VisibilityEnabler|PHashTranslation|RectangleShape2D|DirectionalLight|AnimatedSprite3D|WorldEnvironment|CollisionShape2D|EventStreamChibi|InputEventAction|CollisionPolygon|AudioStreamSpeex|EditorFileDialog|GeometryInstance|Generic6DOFJoint|PacketPeerStream|CanvasItemShader|KinematicBody2D|StyleBoxTexture|PhysicsServerSW|VSplitContainer|CenterContainer|GDFunctionState|AudioStreamOpus|TextureProgress|MarginContainer|CollisionObject|LightOccluder2D|AnimationPlayer|HSplitContainer|ScrollContainer|SoundRoomParams|Physics2DServer|MaterialShader|ShaderMaterial|ViewportSprite|SplitContainer|AudioStreamMPC|VisualInstance|PanelContainer|BackBufferCopy|SamplePlayer2D|CanvasModulate|ResourceLoader|CapsuleShape2D|ReferenceFrame|NavigationMesh|CollisionShape|ConeTwistJoint|ProximityGroup|AnimatedSprite|SegmentShape2D|BoneAttachment|RichTextLabel|CircleShape2D|VBoxContainer|PacketPeerUDP|SpatialPlayer|TextureButton|KinematicBody|SoundPlayer2D|PhysicsServer|ParallaxLayer|InputEventKey|GrooveJoint2D|PhysicsBody2D|FixedMaterial|GridContainer|HBoxContainer|StreamPeerSSL|StyleBoxEmpty|StreamPeerTCP|SampleLibrary|GDNativeClass|AudioServerSW|ResourceSaver|SpriteBase3D|StreamPlayer|AtlasTexture|VisualServer|SamplePlayer|StyleBoxFlat|StaticBody2D|SpriteFrames|MeshDataTool|MeshInstance|Vector3Array|BoxContainer|TabContainer|HButtonArray|LargeTexture|Navigation2D|WindowDialog|EditorScript|EditorPlugin|TextureFrame|AcceptDialog|ImageTexture|CapsuleShape|VehicleWheel|VButtonArray|Vector2Array|InputDefault|OptionButton|PathFollow2D|VehicleBody|ColorPicker|PopupDialog|ProgressBar|CanvasLayer|Translation|Environment|EventPlayer|VideoPlayer|EventStream|VideoStream|ButtonGroup|Particles2D|Patch9Frame|ButtonArray|SurfaceTool|MeshLibrary|PackedScene|PhysicsBody|AudioStream|Performance|StringArray|AudioServer|RigidBody2D|LineShape2D|SliderJoint|SphereShape|ShaderGraph|CheckButton|StreamPeer|FileDialog|PathFollow|SceneState|RoomBounds|Dictionary|VSeparator|PacketPeer|VScrollBar|MenuButton|HTTPClient|PinJoint2D|BakedLight|PlaneShape|InputEvent|BaseButton|HSeparator|HScrollBar|Navigation|PopupPanel|StaticBody|Position2D|Position3D|ToolButton|HingeJoint|CanvasItem|RayShape2D|ColorArray|ConfigFile|TCP_Server|RayCast2D|ColorRamp|SpotLight|RealArray|GraphNode|Container|Reference|PopupMenu|Separator|Polygon2D|MultiMesh|Semaphore|Transform|OmniLight|GraphEdit|Particles|Animation|Marshalls|SceneTree|RigidBody|XMLParser|PathRemap|ScrollBar|Directory|PCKPacker|RawArray|TextEdit|MainLoop|TreeItem|StyleBox|Material|Geometry|Matrix32|Resource|UndoRedo|RayShape|TestCube|ItemList|CheckBox|Camera2D|Skeleton|Sprite3D|Viewport|NodePath|IntArray|BoxShape|PinJoint|InputMap|LineEdit|GDScript|Vector3|TileMap|HSlider|Spatial|SpinBox|World2D|IP_Unix|Curve2D|Curve3D|WeakRef|GridMap|Matrix3|VSlider|CubeMap|Joint2D|Globals|Shape2D|Texture|Control|TileSet|Light2D|FuncRef|Vector2|RayCast|Script|Node2D|Button|BitMap|Sample|Object|String|Shader|Area2D|Slider|Sprite|Thread|Path2D|Camera|Portal|float|Theme|World|YSort|Shape|Joint|Mutex|Tween|RegEx|Label|Rect2|Array|Plane|Light|Range|Color|Input|Popup|Panel|Timer|Image|Area|Quad|bool|AABB|Quat|File|Tabs|Path|Font|Tree|Room|Mesh|Node|RID|int|Nil|IP|OS)\b">
<token type="NameException"/>
</rule>
</state>
<state name="sqs">
<rule pattern="&#39;">
<token type="LiteralStringSingle"/>
<pop depth="1"/>
</rule>
<rule pattern="\\\\|\\&#39;|\\\n">
<token type="LiteralStringEscape"/>
</rule>
<rule>
<include state="strings-single"/>
</rule>
</state>
<state name="stringescape">
<rule pattern="\\([\\abfnrtv&#34;\&#39;]|\n|N\{.*?\}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})">
<token type="LiteralStringEscape"/>
</rule>
</state>
<state name="classname">
<rule pattern="[a-zA-Z_]\w*">
<token type="NameClass"/>
<pop depth="1"/>
</rule>
</state>
<state name="strings-single">
<rule pattern="%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?[hlL]?[E-GXc-giorsux%]">
<token type="LiteralStringInterpol"/>
</rule>
<rule pattern="[^\\\&#39;&#34;%\n]+">
<token type="LiteralStringSingle"/>
</rule>
<rule pattern="[\&#39;&#34;\\]">
<token type="LiteralStringSingle"/>
</rule>
<rule pattern="%">
<token type="LiteralStringSingle"/>
</rule>
</state>
<state name="funcname">
<rule pattern="[a-zA-Z_]\w*">
<token type="NameFunction"/>
<pop depth="1"/>
</rule>
<rule>
<pop depth="1"/>
</rule>
</state>
<state name="numbers">
<rule pattern="(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?">
<token type="LiteralNumberFloat"/>
</rule>
<rule pattern="\d+[eE][+-]?[0-9]+j?">
<token type="LiteralNumberFloat"/>
</rule>
<rule pattern="0[xX][a-fA-F0-9]+">
<token type="LiteralNumberHex"/>
</rule>
<rule pattern="\d+j?">
<token type="LiteralNumberInteger"/>
</rule>
</state>
<state name="tdqs">
<rule pattern="&#34;&#34;&#34;">
<token type="LiteralStringDouble"/>
<pop depth="1"/>
</rule>
<rule>
<include state="strings-double"/>
</rule>
<rule pattern="\n">
<token type="LiteralStringDouble"/>
</rule>
</state>
<state name="name">
<rule pattern="[a-zA-Z_]\w*">
<token type="Name"/>
</rule>
</state>
<state name="root">
<rule pattern="\n">
<token type="Text"/>
</rule>
<rule pattern="^(\s*)([rRuUbB]{,2})(&#34;&#34;&#34;(?:.|\n)*?&#34;&#34;&#34;)">
<bygroups>
<token type="Text"/>
<token type="LiteralStringAffix"/>
<token type="LiteralStringDoc"/>
</bygroups>
</rule>
<rule pattern="^(\s*)([rRuUbB]{,2})(&#39;&#39;&#39;(?:.|\n)*?&#39;&#39;&#39;)">
<bygroups>
<token type="Text"/>
<token type="LiteralStringAffix"/>
<token type="LiteralStringDoc"/>
</bygroups>
</rule>
<rule pattern="[^\S\n]+">
<token type="Text"/>
</rule>
<rule pattern="#.*$">
<token type="CommentSingle"/>
</rule>
<rule pattern="[]{}:(),;[]">
<token type="Punctuation"/>
</rule>
<rule pattern="\\\n">
<token type="Text"/>
</rule>
<rule pattern="\\">
<token type="Text"/>
</rule>
<rule pattern="(in|and|or|not)\b">
<token type="OperatorWord"/>
</rule>
<rule pattern="!=|==|&lt;&lt;|&gt;&gt;|&amp;&amp;|\+=|-=|\*=|/=|%=|&amp;=|\|=|\|\||[-~+/*%=&lt;&gt;&amp;^.!|$]">
<token type="Operator"/>
</rule>
<rule>
<include state="keywords"/>
</rule>
<rule pattern="(def)((?:\s|\\\s)+)">
<bygroups>
<token type="Keyword"/>
<token type="Text"/>
</bygroups>
<push state="funcname"/>
</rule>
<rule pattern="(class)((?:\s|\\\s)+)">
<bygroups>
<token type="Keyword"/>
<token type="Text"/>
</bygroups>
<push state="classname"/>
</rule>
<rule>
<include state="builtins"/>
</rule>
<rule pattern="([rR]|[uUbB][rR]|[rR][uUbB])(&#34;&#34;&#34;)">
<bygroups>
<token type="LiteralStringAffix"/>
<token type="LiteralStringDouble"/>
</bygroups>
<push state="tdqs"/>
</rule>
<rule pattern="([rR]|[uUbB][rR]|[rR][uUbB])(&#39;&#39;&#39;)">
<bygroups>
<token type="LiteralStringAffix"/>
<token type="LiteralStringSingle"/>
</bygroups>
<push state="tsqs"/>
</rule>
<rule pattern="([rR]|[uUbB][rR]|[rR][uUbB])(&#34;)">
<bygroups>
<token type="LiteralStringAffix"/>
<token type="LiteralStringDouble"/>
</bygroups>
<push state="dqs"/>
</rule>
<rule pattern="([rR]|[uUbB][rR]|[rR][uUbB])(&#39;)">
<bygroups>
<token type="LiteralStringAffix"/>
<token type="LiteralStringSingle"/>
</bygroups>
<push state="sqs"/>
</rule>
<rule pattern="([uUbB]?)(&#34;&#34;&#34;)">
<bygroups>
<token type="LiteralStringAffix"/>
<token type="LiteralStringDouble"/>
</bygroups>
<combined state="stringescape" state="tdqs"/>
</rule>
<rule pattern="([uUbB]?)(&#39;&#39;&#39;)">
<bygroups>
<token type="LiteralStringAffix"/>
<token type="LiteralStringSingle"/>
</bygroups>
<combined state="stringescape" state="tsqs"/>
</rule>
<rule pattern="([uUbB]?)(&#34;)">
<bygroups>
<token type="LiteralStringAffix"/>
<token type="LiteralStringDouble"/>
</bygroups>
<combined state="stringescape" state="dqs"/>
</rule>
<rule pattern="([uUbB]?)(&#39;)">
<bygroups>
<token type="LiteralStringAffix"/>
<token type="LiteralStringSingle"/>
</bygroups>
<combined state="stringescape" state="sqs"/>
</rule>
<rule>
<include state="name"/>
</rule>
<rule>
<include state="numbers"/>
</rule>
</state>
<state name="keywords">
<rule pattern="(breakpoint|continue|onready|extends|signal|return|export|static|setget|switch|break|const|while|class|tool|pass|func|case|enum|else|elif|var|for|do|if)\b">
<token type="Keyword"/>
</rule>
</state>
<state name="dqs">
<rule pattern="&#34;">
<token type="LiteralStringDouble"/>
<pop depth="1"/>
</rule>
<rule pattern="\\\\|\\&#34;|\\\n">
<token type="LiteralStringEscape"/>
</rule>
<rule>
<include state="strings-double"/>
</rule>
</state>
<state name="tsqs">
<rule pattern="&#39;&#39;&#39;">
<token type="LiteralStringSingle"/>
<pop depth="1"/>
</rule>
<rule>
<include state="strings-single"/>
</rule>
<rule pattern="\n">
<token type="LiteralStringSingle"/>
</rule>
</state>
<state name="strings-double">
<rule pattern="%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?[hlL]?[E-GXc-giorsux%]">
<token type="LiteralStringInterpol"/>
</rule>
<rule pattern="[^\\\&#39;&#34;%\n]+">
<token type="LiteralStringDouble"/>
</rule>
<rule pattern="[\&#39;&#34;\\]">
<token type="LiteralStringDouble"/>
</rule>
<rule pattern="%">
<token type="LiteralStringDouble"/>
</rule>
</state>
</rules>
</lexer>

View File

@ -1,37 +1,48 @@
# a file is a class!
# Everything after "#" is a comment.
# A file is a class!
# inheritance
# (optional) icon to show in the editor dialogs:
@icon("res://path/to/optional/icon.svg")
# (optional) class definition:
class_name MyClass
# Inheritance:
extends BaseClass
# member variables
# Member variables.
var a = 5
var s = "Hello"
var arr = [1, 2, 3]
var dict = {"key": "value", 2:3}
var dict = {"key": "value", 2: 3}
var other_dict = {key = "value", other_key = 2}
var typed_var: int
var inferred_type := "String"
# constants
const answer = 42
const thename = "Charly"
# enums
# Constants.
const ANSWER = 42
const THE_NAME = "Charly"
# Enums.
enum {UNIT_NEUTRAL, UNIT_ENEMY, UNIT_ALLY}
enum Named {THING_1, THING_2, ANOTHER_THING = -1}
# function
# Built-in vector types.
var v2 = Vector2(1, 2)
var v3 = Vector3(1, 2, 3)
func some_function(param1, param2):
var local_var = 5
if param1 < local_var:
# Functions.
func some_function(param1, param2, param3):
const local_const = 5
if param1 < local_const:
print(param1)
elif param2 > 5:
print(param2)
else:
print("fail!")
print("Fail!")
for i in range(20):
print(i)
@ -39,18 +50,34 @@ func some_function(param1, param2):
while param2 != 0:
param2 -= 1
var local_var2 = param1+3
return local_var2
match param3:
3:
print("param3 is 3!")
_:
print("param3 is not 3!")
var local_var = param1 + 3
return local_var
# inner class
# Functions override functions with the same name on the base/super class.
# If you still want to call them, use "super":
func something(p1, p2):
super(p1, p2)
# It's also possible to call another function in the super class:
func other_something(p1, p2):
super.something(p1, p2)
# Inner class
class Something:
var a = 10
# constructor
# Constructor
func _init():
print("constructed!")
print("Constructed!")
var lv = Something.new()
print(lv.a)
print(lv.a)

View File

@ -1,258 +1,414 @@
[
{"type":"CommentSingle","value":"# a file is a class!"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# inheritance"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"extends"},
{"type":"Text","value":" "},
{"type":"Name","value":"BaseClass"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# member variables"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"5"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"s"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"Hello\""},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"arr"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"["},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"2"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"3"},
{"type":"Punctuation","value":"]"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"dict"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"LiteralStringDouble","value":"\"key\""},
{"type":"Punctuation","value":":"},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"value\""},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"2"},
{"type":"Punctuation","value":":"},
{"type":"LiteralNumberInteger","value":"3"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# constants"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"const"},
{"type":"Text","value":" "},
{"type":"Name","value":"answer"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"42"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"const"},
{"type":"Text","value":" "},
{"type":"Name","value":"thename"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"Charly\""},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# enums"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"enum"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Name","value":"UNIT_NEUTRAL"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"UNIT_ENEMY"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"UNIT_ALLY"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"enum"},
{"type":"Text","value":" "},
{"type":"Name","value":"Named"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Name","value":"THING_1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"THING_2"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"ANOTHER_THING"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Operator","value":"-"},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# function"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"func"},
{"type":"Text","value":" "},
{"type":"Name","value":"some_function"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"param1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"param2"},
{"type":"Punctuation","value":"):"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"local_var"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"5"},
{"type":"Text","value":"\n\n "},
{"type":"Keyword","value":"if"},
{"type":"Text","value":" "},
{"type":"Name","value":"param1"},
{"type":"Text","value":" "},
{"type":"Operator","value":"\u003c"},
{"type":"Text","value":" "},
{"type":"Name","value":"local_var"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"param1"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"elif"},
{"type":"Text","value":" "},
{"type":"Name","value":"param2"},
{"type":"Text","value":" "},
{"type":"Operator","value":"\u003e"},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"5"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"param2"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"else"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"LiteralStringDouble","value":"\"fail!\""},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n\n "},
{"type":"Keyword","value":"for"},
{"type":"Text","value":" "},
{"type":"Name","value":"i"},
{"type":"Text","value":" "},
{"type":"OperatorWord","value":"in"},
{"type":"Text","value":" "},
{"type":"NameBuiltin","value":"range"},
{"type":"Punctuation","value":"("},
{"type":"LiteralNumberInteger","value":"20"},
{"type":"Punctuation","value":"):"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"i"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n\n "},
{"type":"Keyword","value":"while"},
{"type":"Text","value":" "},
{"type":"Name","value":"param2"},
{"type":"Text","value":" "},
{"type":"Operator","value":"!="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"0"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"Name","value":"param2"},
{"type":"Text","value":" "},
{"type":"Operator","value":"-="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Text","value":"\n\n "},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"local_var2"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Name","value":"param1"},
{"type":"Operator","value":"+"},
{"type":"LiteralNumberInteger","value":"3"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"return"},
{"type":"Text","value":" "},
{"type":"Name","value":"local_var2"},
{"type":"Text","value":"\n\n\n"},
{"type":"CommentSingle","value":"# inner class"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"class"},
{"type":"Text","value":" "},
{"type":"Name","value":"Something"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"10"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# constructor"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"func"},
{"type":"Text","value":" "},
{"type":"Name","value":"_init"},
{"type":"Punctuation","value":"():"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"LiteralStringDouble","value":"\"constructed!\""},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"lv"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Name","value":"Something"},
{"type":"Operator","value":"."},
{"type":"Name","value":"new"},
{"type":"Punctuation","value":"()"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"lv"},
{"type":"Operator","value":"."},
{"type":"Name","value":"a"},
{"type":"Punctuation","value":")"}
{"type":"CommentSingle","value":"# Everything after \"#\" is a comment."},
{"type":"Text","value":"\n"},
{"type":"CommentSingle","value":"# A file is a class!"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# (optional) icon to show in the editor dialogs:"},
{"type":"Text","value":"\n"},
{"type":"NameDecorator","value":"@icon"},
{"type":"Punctuation","value":"("},
{"type":"LiteralStringDouble","value":"\"res://path/to/optional/icon.svg\""},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# (optional) class definition:"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"class_name"},
{"type":"Text","value":" "},
{"type":"NameClass","value":"MyClass"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# Inheritance:"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"extends"},
{"type":"Text","value":" "},
{"type":"NameClass","value":"BaseClass"},
{"type":"Text","value":"\n\n\n"},
{"type":"CommentSingle","value":"# Member variables."},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"5"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"s"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"Hello\""},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"arr"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"["},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"2"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"3"},
{"type":"Punctuation","value":"]"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"dict"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"LiteralStringDouble","value":"\"key\""},
{"type":"Punctuation","value":":"},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"value\""},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"2"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"3"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"other_dict"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Name","value":"key"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"value\""},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"other_key"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"2"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"typed_var"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":" "},
{"type":"KeywordType","value":"int"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"inferred_type"},
{"type":"Text","value":" "},
{"type":"Operator","value":":="},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"String\""},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# Constants."},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"const"},
{"type":"Text","value":" "},
{"type":"Name","value":"ANSWER"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"42"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"const"},
{"type":"Text","value":" "},
{"type":"Name","value":"THE_NAME"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"Charly\""},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# Enums."},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"enum"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Name","value":"UNIT_NEUTRAL"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"UNIT_ENEMY"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"UNIT_ALLY"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"enum"},
{"type":"Text","value":" "},
{"type":"Name","value":"Named"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Name","value":"THING_1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"THING_2"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"ANOTHER_THING"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Operator","value":"-"},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# Built-in vector types."},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"v2"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"NameClass","value":"Vector2"},
{"type":"Punctuation","value":"("},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"2"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"v3"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"NameClass","value":"Vector3"},
{"type":"Punctuation","value":"("},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"2"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"3"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n\n\n"},
{"type":"CommentSingle","value":"# Functions."},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"func"},
{"type":"Text","value":" "},
{"type":"NameFunction","value":"some_function"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"param1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"param2"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"param3"},
{"type":"Punctuation","value":"):"},
{"type":"Text","value":"\n "},
{"type":"KeywordDeclaration","value":"const"},
{"type":"Text","value":" "},
{"type":"Name","value":"local_const"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"5"},
{"type":"Text","value":"\n\n "},
{"type":"Keyword","value":"if"},
{"type":"Text","value":" "},
{"type":"Name","value":"param1"},
{"type":"Text","value":" "},
{"type":"Operator","value":"\u003c"},
{"type":"Text","value":" "},
{"type":"Name","value":"local_const"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"param1"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"elif"},
{"type":"Text","value":" "},
{"type":"Name","value":"param2"},
{"type":"Text","value":" "},
{"type":"Operator","value":"\u003e"},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"5"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"param2"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"else"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"LiteralStringDouble","value":"\"Fail!\""},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n\n "},
{"type":"Keyword","value":"for"},
{"type":"Text","value":" "},
{"type":"Name","value":"i"},
{"type":"Text","value":" "},
{"type":"OperatorWord","value":"in"},
{"type":"Text","value":" "},
{"type":"NameBuiltin","value":"range"},
{"type":"Punctuation","value":"("},
{"type":"LiteralNumberInteger","value":"20"},
{"type":"Punctuation","value":"):"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"i"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n\n "},
{"type":"Keyword","value":"while"},
{"type":"Text","value":" "},
{"type":"Name","value":"param2"},
{"type":"Text","value":" "},
{"type":"Operator","value":"!="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"0"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"Name","value":"param2"},
{"type":"Text","value":" "},
{"type":"Operator","value":"-="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Text","value":"\n\n "},
{"type":"Keyword","value":"match"},
{"type":"Text","value":" "},
{"type":"Name","value":"param3"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"LiteralNumberInteger","value":"3"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"LiteralStringDouble","value":"\"param3 is 3!\""},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n "},
{"type":"Name","value":"_"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"LiteralStringDouble","value":"\"param3 is not 3!\""},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n\n "},
{"type":"KeywordDeclaration","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"local_var"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Name","value":"param1"},
{"type":"Text","value":" "},
{"type":"Operator","value":"+"},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"3"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"return"},
{"type":"Text","value":" "},
{"type":"Name","value":"local_var"},
{"type":"Text","value":"\n\n\n"},
{"type":"CommentSingle","value":"# Functions override functions with the same name on the base/super class."},
{"type":"Text","value":"\n"},
{"type":"CommentSingle","value":"# If you still want to call them, use \"super\":"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"func"},
{"type":"Text","value":" "},
{"type":"NameFunction","value":"something"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"p1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"p2"},
{"type":"Punctuation","value":"):"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"super"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"p1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"p2"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n\n\n"},
{"type":"CommentSingle","value":"# It's also possible to call another function in the super class:"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"func"},
{"type":"Text","value":" "},
{"type":"NameFunction","value":"other_something"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"p1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"p2"},
{"type":"Punctuation","value":"):"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"super"},
{"type":"Operator","value":"."},
{"type":"NameFunction","value":"something"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"p1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"p2"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n\n\n"},
{"type":"CommentSingle","value":"# Inner class"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"class"},
{"type":"Text","value":" "},
{"type":"NameClass","value":"Something"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"KeywordDeclaration","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"10"},
{"type":"Text","value":"\n\n\n"},
{"type":"CommentSingle","value":"# Constructor"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"func"},
{"type":"Text","value":" "},
{"type":"NameFunction","value":"_init"},
{"type":"Punctuation","value":"():"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"LiteralStringDouble","value":"\"Constructed!\""},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n "},
{"type":"KeywordDeclaration","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"lv"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Name","value":"Something"},
{"type":"Operator","value":"."},
{"type":"NameFunction","value":"new"},
{"type":"Punctuation","value":"()"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"lv"},
{"type":"Operator","value":"."},
{"type":"Name","value":"a"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n"}
]

56
lexers/testdata/gdscript3.actual vendored Normal file
View File

@ -0,0 +1,56 @@
# a file is a class!
# inheritance
extends BaseClass
# member variables
var a = 5
var s = "Hello"
var arr = [1, 2, 3]
var dict = {"key": "value", 2:3}
# constants
const answer = 42
const thename = "Charly"
# enums
enum {UNIT_NEUTRAL, UNIT_ENEMY, UNIT_ALLY}
enum Named {THING_1, THING_2, ANOTHER_THING = -1}
# function
func some_function(param1, param2):
var local_var = 5
if param1 < local_var:
print(param1)
elif param2 > 5:
print(param2)
else:
print("fail!")
for i in range(20):
print(i)
while param2 != 0:
param2 -= 1
var local_var2 = param1+3
return local_var2
# inner class
class Something:
var a = 10
# constructor
func _init():
print("constructed!")
var lv = Something.new()
print(lv.a)

258
lexers/testdata/gdscript3.expected vendored Normal file
View File

@ -0,0 +1,258 @@
[
{"type":"CommentSingle","value":"# a file is a class!"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# inheritance"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"extends"},
{"type":"Text","value":" "},
{"type":"Name","value":"BaseClass"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# member variables"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"5"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"s"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"Hello\""},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"arr"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"["},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"2"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"3"},
{"type":"Punctuation","value":"]"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"dict"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"LiteralStringDouble","value":"\"key\""},
{"type":"Punctuation","value":":"},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"value\""},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"2"},
{"type":"Punctuation","value":":"},
{"type":"LiteralNumberInteger","value":"3"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# constants"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"const"},
{"type":"Text","value":" "},
{"type":"Name","value":"answer"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"42"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"const"},
{"type":"Text","value":" "},
{"type":"Name","value":"thename"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"Charly\""},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# enums"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"enum"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Name","value":"UNIT_NEUTRAL"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"UNIT_ENEMY"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"UNIT_ALLY"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"enum"},
{"type":"Text","value":" "},
{"type":"Name","value":"Named"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Name","value":"THING_1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"THING_2"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"ANOTHER_THING"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Operator","value":"-"},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# function"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"func"},
{"type":"Text","value":" "},
{"type":"Name","value":"some_function"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"param1"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"param2"},
{"type":"Punctuation","value":"):"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"local_var"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"5"},
{"type":"Text","value":"\n\n "},
{"type":"Keyword","value":"if"},
{"type":"Text","value":" "},
{"type":"Name","value":"param1"},
{"type":"Text","value":" "},
{"type":"Operator","value":"\u003c"},
{"type":"Text","value":" "},
{"type":"Name","value":"local_var"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"param1"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"elif"},
{"type":"Text","value":" "},
{"type":"Name","value":"param2"},
{"type":"Text","value":" "},
{"type":"Operator","value":"\u003e"},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"5"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"param2"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"else"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"LiteralStringDouble","value":"\"fail!\""},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n\n "},
{"type":"Keyword","value":"for"},
{"type":"Text","value":" "},
{"type":"Name","value":"i"},
{"type":"Text","value":" "},
{"type":"OperatorWord","value":"in"},
{"type":"Text","value":" "},
{"type":"NameBuiltin","value":"range"},
{"type":"Punctuation","value":"("},
{"type":"LiteralNumberInteger","value":"20"},
{"type":"Punctuation","value":"):"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"i"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n\n "},
{"type":"Keyword","value":"while"},
{"type":"Text","value":" "},
{"type":"Name","value":"param2"},
{"type":"Text","value":" "},
{"type":"Operator","value":"!="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"0"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"Name","value":"param2"},
{"type":"Text","value":" "},
{"type":"Operator","value":"-="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Text","value":"\n\n "},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"local_var2"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Name","value":"param1"},
{"type":"Operator","value":"+"},
{"type":"LiteralNumberInteger","value":"3"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"return"},
{"type":"Text","value":" "},
{"type":"Name","value":"local_var2"},
{"type":"Text","value":"\n\n\n"},
{"type":"CommentSingle","value":"# inner class"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"class"},
{"type":"Text","value":" "},
{"type":"Name","value":"Something"},
{"type":"Punctuation","value":":"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"a"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralNumberInteger","value":"10"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"# constructor"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"func"},
{"type":"Text","value":" "},
{"type":"Name","value":"_init"},
{"type":"Punctuation","value":"():"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"LiteralStringDouble","value":"\"constructed!\""},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"var"},
{"type":"Text","value":" "},
{"type":"Name","value":"lv"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Name","value":"Something"},
{"type":"Operator","value":"."},
{"type":"Name","value":"new"},
{"type":"Punctuation","value":"()"},
{"type":"Text","value":"\n "},
{"type":"NameBuiltin","value":"print"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"lv"},
{"type":"Operator","value":"."},
{"type":"Name","value":"a"},
{"type":"Punctuation","value":")"}
]