Skip to content

Commit

Permalink
Merge pull request #1 from infection/feature/ast
Browse files Browse the repository at this point in the history
Add AST Explorer
  • Loading branch information
maks-rafalko authored May 26, 2024
2 parents fe89389 + 495a624 commit b88e85d
Show file tree
Hide file tree
Showing 31 changed files with 4,098 additions and 54 deletions.
10 changes: 9 additions & 1 deletion app/assets/css/app.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@tailwind utilities;

#clickable-nodes-code a.active-node {
color: forestgreen;
}

pre code.hljs {
border-radius: .6em;
}
7 changes: 3 additions & 4 deletions app/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

// any CSS you import will output into a single css file (app.css in this case)
import '../css/app.css';
import initApp from './app/main';

// Need jQuery? Install it with "yarn add jquery", then uncomment to import it.
// import $ from 'jquery';
initApp();
import {initMutationEditors} from './app/editor';

initMutationEditors();
75 changes: 70 additions & 5 deletions app/assets/js/app/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as monaco from 'monaco-editor';

let diffEditor;

export function initEditors() {
export function initMutationEditors() {
const codeEditor = initCodeEditor();
const testEditor = initTestEditor();
const configEditor = initConfigEditor();
Expand Down Expand Up @@ -226,6 +226,53 @@ function showDiffEditor(mutator) {
});
}

export function initAstEditor() {
const loadedCodeElement = document.getElementById('loaded-code');
const code = loadedCodeElement !== null
? loadedCodeElement.dataset.code
: [
'<?php',
'',
'function add(int $a, int $b): int',
'{',
' return $a + $b;',
'}',
].join('\n');

const editorNode = document.getElementById('editor-code-ast');

if (!editorNode) {
return;
}

const codeEditor = monaco.editor.create(editorNode, {
minimap: {
enabled: false
},
value: code,
language: 'php'
});

document.getElementById('js-submit').addEventListener(
'click',
function () {
disableButton(this);

document.getElementById('create_ast_run_code').textContent = codeEditor.getValue();
document.getElementsByName("create_ast_run")[0].submit()

return false;
}
);

window.addEventListener('resize', function() {
setTimeout(function () {
codeEditor.layout();
}, 50);

}, true);
}

function initCodeEditor() {
const loadedCodeElement = document.getElementById('loaded-code');
const code = loadedCodeElement !== null
Expand All @@ -246,7 +293,13 @@ function initCodeEditor() {
'}'
].join('\n');

return monaco.editor.create(document.getElementById('editor-code'), {
const editorNode = document.getElementById('editor-code');

if (!editorNode) {
return;
}

return monaco.editor.create(editorNode, {
minimap: {
enabled: false
},
Expand Down Expand Up @@ -281,9 +334,15 @@ function initTestEditor() {
' self::assertSame(3, $result);',
' }',
'}'
].join('\n')
].join('\n');

const editorNode = document.getElementById('editor-test');

if (!editorNode) {
return;
}

return monaco.editor.create(document.getElementById('editor-test'), {
return monaco.editor.create(editorNode, {
minimap: {
enabled: false
},
Expand All @@ -304,7 +363,13 @@ function initConfigEditor() {
'}'
].join('\n');

return monaco.editor.create(document.getElementById('editor-config'), {
const editorNode = document.getElementById('editor-config');

if (!editorNode) {
return;
}

return monaco.editor.create(editorNode, {
minimap: {
enabled: false
},
Expand Down
5 changes: 0 additions & 5 deletions app/assets/js/app/main.js

This file was deleted.

5 changes: 5 additions & 0 deletions app/assets/js/ast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import '../css/app.css';

import {initAstEditor} from "./app/editor";

initAstEditor();
1 change: 1 addition & 0 deletions app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"symfony/flex": "^2",
"symfony/form": "7.0.*",
"symfony/framework-bundle": "7.0.*",
"symfony/maker-bundle": "^1.59",
"symfony/process": "7.0.*",
"symfony/runtime": "7.0.*",
"symfony/twig-bundle": "7.0.*",
Expand Down
94 changes: 93 additions & 1 deletion app/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 1 addition & 33 deletions app/config/bundles.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,4 @@
<?php
/**
* This code is licensed under the BSD 3-Clause License.
*
* Copyright (c) 2017, Maks Rafalko
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

declare(strict_types=1);

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Expand All @@ -41,4 +8,5 @@
Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
];
70 changes: 70 additions & 0 deletions app/migrations/Version20240521220725.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* This code is licensed under the BSD 3-Clause License.
*
* Copyright (c) 2017, Maks Rafalko
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240521220725 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE ast_run (
id INT AUTO_INCREMENT NOT NULL,
code LONGTEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT \'(DC2Type:datetime_immutable)\',
id_hash VARCHAR(10) DEFAULT NULL,
input_hash VARCHAR(32) NOT NULL,
UNIQUE INDEX UNIQ_D10C36992D5D98F (input_hash),
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE ast_run');
}
}
1 change: 1 addition & 0 deletions app/phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ parameters:
- tests/
excludePaths:
- src/Html/Ansi/*
- src/PhpParser/*
ignoreErrors:
- '#Access to an undefined property Symfony\\Component\\Validator\\Constraint::\$(.*?)#'
- '#^Property App\\Entity\\(.*):\$id is never written, only read.$#'
Expand Down
Loading

0 comments on commit b88e85d

Please sign in to comment.