Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add PHP grammar #647

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions org.eclipse.tm4e.language_pack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ for the [Eclipse IDE](https://eclipseide.org).
| Objective-C++ | file-extensions="mm" | [1.79.0@microsoft/vscode](https://github.com/microsoft/vscode/tree/b380da4ef1ee00e224a15c1d4d9793e27c2b6302/extensions/objective-c) [[upstream]](https://github.com/jeff-hykin/better-objcpp-syntax/commit/5a7eb15eee382dd5aa388bc04fdb60a0d2128e14)
| Perl | file-extensions="PL, pl, pm, pod, psgi, t" | [1.79.0@microsoft/vscode](https://github.com/microsoft/vscode/tree/b380da4ef1ee00e224a15c1d4d9793e27c2b6302/extensions/perl) [[upstream]](https://github.com/textmate/perl.tmbundle/commit/a85927a902d6e5d7805f56a653f324d34dfad53a)
| Perl 6 (Raku) | file-extensions="nqp, p6, pl6, pm6" | [1.79.0@microsoft/vscode](https://github.com/microsoft/vscode/tree/b380da4ef1ee00e224a15c1d4d9793e27c2b6302/extensions/perl) [[upstream]](https://github.com/textmate/perl.tmbundle/commit/d9841a0878239fa43f88c640f8d458590f97e8f5)
| PHP | file-extensions="ctp, php, php4, php5, phtml" | [1.79.0@microsoft/vscode](https://github.com/microsoft/vscode/tree/b380da4ef1ee00e224a15c1d4d9793e27c2b6302/extensions/php) [[upstream]](https://github.com/KapitanOczywisty/language-php/commit/5e8f000cb5a20f44f7a7a89d07ad0774031c53f3)
| PowerShell | file-extensions="ps1, psd1, psm1, psrc, pssc" | [1.79.0@microsoft/vscode](https://github.com/microsoft/vscode/tree/b380da4ef1ee00e224a15c1d4d9793e27c2b6302/extensions/powershell) [[upstream]](https://github.com/PowerShell/EditorSyntax/commit/742f0b5d4b60f5930c0b47fcc1f646860521296e)
| Pug | file-extensions="jade, pug" | [1.79.0@microsoft/vscode](https://github.com/microsoft/vscode/tree/b380da4ef1ee00e224a15c1d4d9793e27c2b6302/extensions/pug) [[upstream]](https://github.com/davidrios/pug-tmbundle/commit/ae1dd60ca4aa4b45617f236d584216cd8d19eecf)
| Python | file-extensions="cpy, gyp, gypi, ipy, py, pyi, pyt, pyw, rpy"<br />file-names="SConscript, SConstruct" | [1.79.0@microsoft/vscode](https://github.com/microsoft/vscode/tree/b380da4ef1ee00e224a15c1d4d9793e27c2b6302/extensions/python) [[upstream]](https://github.com/MagicStack/MagicPython/commit/7d0f2b22a5ad8fccbd7341bc7b7a715169283044)
Expand Down
5 changes: 5 additions & 0 deletions org.eclipse.tm4e.language_pack/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ <h2>About This Content</h2>
<td>file-extensions="nqp, p6, pl6, pm6"</td>
<td><a href="https://github.com/microsoft/vscode/tree/b380da4ef1ee00e224a15c1d4d9793e27c2b6302/extensions/perl">1.79.0@microsoft/vscode</a> <a href="https://github.com/textmate/perl.tmbundle/commit/d9841a0878239fa43f88c640f8d458590f97e8f5">[upstream]</a>
</tr>
<tr>
<td>PHP</td>
<td>file-extensions="ctp, php, php4, php5, phtml"</td>
<td><a href="https://github.com/microsoft/vscode/tree/b380da4ef1ee00e224a15c1d4d9793e27c2b6302/extensions/php">1.79.0@microsoft/vscode</a> <a href="https://github.com/KapitanOczywisty/language-php/commit/5e8f000cb5a20f44f7a7a89d07ad0774031c53f3">[upstream]</a>
</tr>
<tr>
<td>PowerShell</td>
<td>file-extensions="ps1, psd1, psm1, psrc, pssc"</td>
Expand Down
20 changes: 20 additions & 0 deletions org.eclipse.tm4e.language_pack/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,26 @@
<languageConfiguration contentTypeId="org.eclipse.tm4e.language_pack.perl6" path="syntaxes/perl/perl6.language-configuration.json" />
</extension>

<!-- ======================================== -->
<!-- php/php: PHP -->
<!-- ======================================== -->
<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type id="org.eclipse.tm4e.language_pack.php" name="PHP" base-type="org.eclipse.tm4e.language_pack.basetype" priority="low"
file-extensions="ctp,php,php4,php5,phtml" />
</extension>
<extension point="org.eclipse.tm4e.registry.grammars">
<grammar scopeName="source.php" path="syntaxes/php/php.tmLanguage.json" />
<scopeNameContentTypeBinding scopeName="source.php" contentTypeId="org.eclipse.tm4e.language_pack.php" />
</extension>

<extension point="org.eclipse.tm4e.languageconfiguration.languageConfigurations">
<languageConfiguration contentTypeId="org.eclipse.tm4e.language_pack.php" path="syntaxes/php/php.language-configuration.json" />
</extension>

<extension point="org.eclipse.tm4e.ui.snippets">
<snippet name="PHP Example" path="syntaxes/php/php.example.php" scopeName="source.php" />
</extension>

<!-- ======================================== -->
<!-- powershell/powershell: PowerShell -->
<!-- ======================================== -->
Expand Down
85 changes: 85 additions & 0 deletions org.eclipse.tm4e.language_pack/syntaxes/php/php.example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

// Variables and Data Types
$name = "John";
$age = 30;
$isStudent = false;
$grades = [85, 90, 78];

// Control Structures
if ($age >= 18) {
echo "Welcome, $name! You are eligible.";
} else {
echo "Sorry, $name. You are not eligible.";
}

// Loops
for ($i = 0; $i < count($grades); $i++) {
echo "Grade $i: {$grades[$i]}";
}

// Functions
function greet($name) {
return "Hello, $name!";
}

echo greet($name);

// Arrays
$colors = ["red", "green", "blue"];
$associativeArray = [
"name" => "Jane",
"age" => 25,
"isStudent" => true
];

// Classes and Objects
class Person {
public $name;
public $age;

public function __construct($name, $age) {
$this->name = $name;
$this->age = $age;
}

public function greet() {
echo "Hello, my name is $this->name.";
}
}

$person = new Person("Alice", 22);
$person->greet();

// Traits
trait Logging {
public function log($message) {
echo "Logging: $message";
}
}

// Namespaces
namespace MyApp;

// Error Handling
try {
// Code that might throw an exception
throw new Exception("Something went wrong!");
} catch (Exception $e) {
echo "Caught exception: " . $e->getMessage();
}

// File Handling
$fileContent = file_get_contents("example.txt");
file_put_contents("output.txt", $fileContent);

// Regular Expressions
$pattern = "/\d{2}-\d{2}-\d{4}/";
$dateString = "12-31-2022";

if (preg_match($pattern, $dateString)) {
echo "Valid date format.";
} else {
echo "Invalid date format.";
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"comments": {
"lineComment": "//", // "#"
"blockComment": [ "/*", "*/" ]
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
"autoClosingPairs": [
{ "open": "{", "close": "}", "notIn": ["string"] },
{ "open": "[", "close": "]", "notIn": ["string"] },
{ "open": "(", "close": ")", "notIn": ["string"] },
{ "open": "'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "/**", "close": " */", "notIn": ["string"] }
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["'", "'"],
["\"", "\""],
["`", "`"]
],
"indentationRules": {
"increaseIndentPattern": "({(?!.*}).*|\\(|\\[|((else(\\s)?)?if|else|for(each)?|while|switch|case).*:)\\s*((/[/*].*|)?$|\\?>)",
"decreaseIndentPattern": "^(.*\\*\\/)?\\s*((\\})|(\\)+[;,])|(\\]\\)*[;,])|\\b(else:)|\\b((end(if|for(each)?|while|switch));))"
},
"folding": {
"markers": {
"start": "^\\s*(#|\/\/)region\\b",
"end": "^\\s*(#|\/\/)endregion\\b"
}
},
"wordPattern": "(-?\\d*\\.\\d\\w*)|([^\\-\\`\\~\\!\\@\\#\\%\\^\\&\\*\\(\\)\\=\\+\\[\\{\\]\\}\\\\\\|\\;\\:\\'\\\"\\,\\.\\<\\>\\/\\?\\s]+)",
"onEnterRules": [
{
// e.g. /** | */
"beforeText": "^\\s*\\/\\*\\*(?!\\/)([^\\*]|\\*(?!\\/))*$",
"afterText": "^\\s*\\*\\/$",
"action": {
"indent": "indentOutdent",
"appendText": " * "
}
},
{
// e.g. /** ...|
"beforeText": "^\\s*\\/\\*\\*(?!\\/)([^\\*]|\\*(?!\\/))*$",
"action": {
"indent": "none",
"appendText": " * "
}
},
{
// e.g. * ...|
"beforeText": "^(\\t|(\\ \\ ))*\\ \\*(\\ ([^\\*]|\\*(?!\\/))*)?$",
"action": {
"indent": "none",
"appendText": "* ",
},
},
{
// e.g. */|
"beforeText": "^(\\t|(\\ \\ ))*\\ \\*\\/\\s*$",
"action": {
"indent": "none",
"removeText": 1
},
},
{
// e.g. *-----*/|
"beforeText": "^(\\t|(\\ \\ ))*\\ \\*[^/]*\\*\\/\\s*$",
"action": {
"indent": "none",
"removeText": 1
}
}
]
}
Loading