-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from assertchris/feature/add-gdscript-support
Add GDScript support
- Loading branch information
Showing
22 changed files
with
647 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Highlight\Languages\Gdscript; | ||
|
||
use Tempest\Highlight\Languages\Base\BaseLanguage; | ||
use Tempest\Highlight\Languages\Gdscript\Patterns\AnnotationPattern; | ||
use Tempest\Highlight\Languages\Gdscript\Patterns\AsTypePattern; | ||
use Tempest\Highlight\Languages\Gdscript\Patterns\ClassNamePattern; | ||
use Tempest\Highlight\Languages\Gdscript\Patterns\DoubleQuoteValuePattern; | ||
use Tempest\Highlight\Languages\Gdscript\Patterns\ExtendsPattern; | ||
use Tempest\Highlight\Languages\Gdscript\Patterns\FunctionCallPattern; | ||
use Tempest\Highlight\Languages\Gdscript\Patterns\FunctionNamePattern; | ||
use Tempest\Highlight\Languages\Gdscript\Patterns\KeywordPattern; | ||
use Tempest\Highlight\Languages\Gdscript\Patterns\OperatorPattern; | ||
use Tempest\Highlight\Languages\Gdscript\Patterns\PropertyAccessPattern; | ||
use Tempest\Highlight\Languages\Gdscript\Patterns\ReturnTypePattern; | ||
use Tempest\Highlight\Languages\Gdscript\Patterns\SinglelineCommentPattern; | ||
use Tempest\Highlight\Languages\Gdscript\Patterns\SingleQuoteValuePattern; | ||
use Tempest\Highlight\Languages\Gdscript\Patterns\VarTypePattern; | ||
|
||
class GdscriptLanguage extends BaseLanguage | ||
{ | ||
public function getInjections(): array | ||
{ | ||
return [ | ||
...parent::getInjections(), | ||
]; | ||
} | ||
|
||
public function getPatterns(): array | ||
{ | ||
return [ | ||
...parent::getPatterns(), | ||
|
||
new OperatorPattern('**='), | ||
new OperatorPattern('<<='), | ||
new OperatorPattern('>>='), | ||
new OperatorPattern('**'), | ||
new OperatorPattern('||'), | ||
new OperatorPattern('&&'), | ||
new OperatorPattern('<='), | ||
new OperatorPattern('>='), | ||
new OperatorPattern('=='), | ||
new OperatorPattern('!='), | ||
new OperatorPattern('<<'), | ||
new OperatorPattern('>>'), | ||
new OperatorPattern('+='), | ||
new OperatorPattern('-='), | ||
new OperatorPattern('*='), | ||
new OperatorPattern('/='), | ||
new OperatorPattern('%='), | ||
new OperatorPattern('&='), | ||
new OperatorPattern('|='), | ||
new OperatorPattern('^='), | ||
new OperatorPattern('->'), | ||
new OperatorPattern('/'), | ||
new OperatorPattern('%'), | ||
new OperatorPattern('+'), | ||
new OperatorPattern('-'), | ||
new OperatorPattern('*'), | ||
new OperatorPattern('/'), | ||
new OperatorPattern('&'), | ||
new OperatorPattern('^'), | ||
new OperatorPattern('|'), | ||
new OperatorPattern('<'), | ||
new OperatorPattern('>'), | ||
new OperatorPattern('!'), | ||
|
||
new KeywordPattern('if'), | ||
new KeywordPattern('elif'), | ||
new KeywordPattern('else'), | ||
new KeywordPattern('for'), | ||
new KeywordPattern('while'), | ||
new KeywordPattern('match'), | ||
new KeywordPattern('break'), | ||
new KeywordPattern('continue'), | ||
new KeywordPattern('pass'), | ||
new KeywordPattern('return'), | ||
new KeywordPattern('class'), | ||
new KeywordPattern('class_name'), | ||
new KeywordPattern('extends'), | ||
new KeywordPattern('is'), | ||
new KeywordPattern('not'), | ||
new KeywordPattern('and'), | ||
new KeywordPattern('or'), | ||
new KeywordPattern('in'), | ||
new KeywordPattern('as'), | ||
new KeywordPattern('self'), | ||
new KeywordPattern('signal'), | ||
new KeywordPattern('func'), | ||
new KeywordPattern('static'), | ||
new KeywordPattern('const'), | ||
new KeywordPattern('enum'), | ||
new KeywordPattern('var'), | ||
new KeywordPattern('breakpoint'), | ||
new KeywordPattern('preload'), | ||
new KeywordPattern('await'), | ||
new KeywordPattern('yield'), | ||
new KeywordPattern('assert'), | ||
new KeywordPattern('super'), | ||
new KeywordPattern('PI'), | ||
new KeywordPattern('INF'), | ||
new KeywordPattern('TAU'), | ||
new KeywordPattern('NAN'), | ||
|
||
new SinglelineCommentPattern(), | ||
|
||
new AnnotationPattern(), | ||
new ExtendsPattern(), | ||
new ClassNamePattern(), | ||
new FunctionNamePattern(), | ||
new FunctionCallPattern(), | ||
new ReturnTypePattern(), | ||
new AsTypePattern(), | ||
new VarTypePattern(), | ||
new PropertyAccessPattern(), | ||
|
||
new SingleQuoteValuePattern(), | ||
new DoubleQuoteValuePattern(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Highlight\Languages\Gdscript\Patterns; | ||
|
||
use Tempest\Highlight\IsPattern; | ||
use Tempest\Highlight\Pattern; | ||
use Tempest\Highlight\Tokens\TokenType; | ||
|
||
final readonly class AnnotationPattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
$variations = join('|@export_', [ | ||
'category', | ||
'color_no_alpha', | ||
'dir', | ||
'enum', | ||
'exp_easing', | ||
'file', | ||
'flags', | ||
'flags_2d_navigation', | ||
'flags_2d_physics', | ||
'flags_2d_render', | ||
'flags_3d_navigation', | ||
'flags_3d_physics', | ||
'flags_3d_render', | ||
'flags_avoidance', | ||
'global_dir', | ||
'global_file', | ||
'group', | ||
'multiline', | ||
'node_path', | ||
'placeholder', | ||
'range', | ||
'subgroup', | ||
]); | ||
|
||
return "(?<match>(@onready|@icon|@export|@export_{$variations}|@rpc|@static_unload|@tool|@warning_ignore))"; | ||
} | ||
|
||
public function getTokenType(): TokenType | ||
{ | ||
return TokenType::KEYWORD; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Highlight\Languages\Gdscript\Patterns; | ||
|
||
use Tempest\Highlight\IsPattern; | ||
use Tempest\Highlight\Pattern; | ||
use Tempest\Highlight\PatternTest; | ||
use Tempest\Highlight\Tokens\TokenType; | ||
|
||
#[PatternTest(input: 'as int', output: 'int')] | ||
final readonly class AsTypePattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return 'as\s+\b(?<match>[a-zA-Z][a-zA-Z0-9]+)\b'; | ||
} | ||
|
||
public function getTokenType(): TokenType | ||
{ | ||
return TokenType::TYPE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Highlight\Languages\Gdscript\Patterns; | ||
|
||
use Tempest\Highlight\IsPattern; | ||
use Tempest\Highlight\Pattern; | ||
use Tempest\Highlight\PatternTest; | ||
use Tempest\Highlight\Tokens\TokenType; | ||
|
||
#[PatternTest(input: 'class_name Foo', output: 'Foo')] | ||
final readonly class ClassNamePattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return 'class_name\s(?<match>[\w]+)'; | ||
} | ||
|
||
public function getTokenType(): TokenType | ||
{ | ||
return TokenType::TYPE; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Languages/Gdscript/Patterns/DoubleQuoteValuePattern.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Highlight\Languages\Gdscript\Patterns; | ||
|
||
use Tempest\Highlight\IsPattern; | ||
use Tempest\Highlight\Pattern; | ||
use Tempest\Highlight\PatternTest; | ||
use Tempest\Highlight\Tokens\TokenType; | ||
|
||
#[PatternTest( | ||
input: 'return "hello"', | ||
output: 'hello', | ||
)] | ||
final readonly class DoubleQuoteValuePattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return '"(?<match>.*?)"'; | ||
} | ||
|
||
public function getTokenType(): TokenType | ||
{ | ||
return TokenType::VALUE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Highlight\Languages\Gdscript\Patterns; | ||
|
||
use Tempest\Highlight\IsPattern; | ||
use Tempest\Highlight\Pattern; | ||
use Tempest\Highlight\PatternTest; | ||
use Tempest\Highlight\Tokens\TokenType; | ||
|
||
#[PatternTest(input: 'extends Foo', output: 'Foo')] | ||
final readonly class ExtendsPattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return 'extends\s(?<match>[\w]+)'; | ||
} | ||
|
||
public function getTokenType(): TokenType | ||
{ | ||
return TokenType::TYPE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Highlight\Languages\Gdscript\Patterns; | ||
|
||
use Tempest\Highlight\IsPattern; | ||
use Tempest\Highlight\Pattern; | ||
use Tempest\Highlight\PatternTest; | ||
use Tempest\Highlight\Tokens\TokenType; | ||
|
||
#[PatternTest(input: 'foo()', output: 'foo')] | ||
#[PatternTest(input: '.foo()', output: 'foo')] | ||
final readonly class FunctionCallPattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return '\b(?<match>[a-z][\w]+)\('; | ||
} | ||
|
||
public function getTokenType(): TokenType | ||
{ | ||
return TokenType::PROPERTY; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Highlight\Languages\Gdscript\Patterns; | ||
|
||
use Tempest\Highlight\IsPattern; | ||
use Tempest\Highlight\Pattern; | ||
use Tempest\Highlight\PatternTest; | ||
use Tempest\Highlight\Tokens\TokenType; | ||
|
||
#[PatternTest(input: 'func foo()', output: 'foo')] | ||
final readonly class FunctionNamePattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return 'func (?<match>[\w]+)'; | ||
} | ||
|
||
public function getTokenType(): TokenType | ||
{ | ||
return TokenType::PROPERTY; | ||
} | ||
} |
Oops, something went wrong.