Skip to content

Commit

Permalink
Add a script to test lexer on all the testing queries
Browse files Browse the repository at this point in the history
  • Loading branch information
JanJakes committed Oct 1, 2024
1 parent 71292fb commit 1ab3723
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/parser/run-lexer-tests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

// Throw exception if anything fails.
set_error_handler(function ($severity, $message, $file, $line) {
throw new ErrorException($message, 0, $severity, $file, $line);
});

require_once __DIR__ . '/../../custom-parser/parser/DynamicRecursiveDescentParser.php';
require_once __DIR__ . '/../../custom-parser/parser/MySQLLexer.php';

$handle = fopen(__DIR__ . '/data/queries.csv', 'r');

$i = 1;
$start = microtime(true);
while (($query = fgetcsv($handle)) !== false) {
$query = $query[0];

$tokens = tokenizeQuery($query);
if (empty($tokens)) {
throw new Exception('Failed to tokenize query: ' . $query);
}
$i++;
}

echo "Tokenized $i queries in ", microtime(true) - $start, 's', PHP_EOL;
File renamed without changes.

0 comments on commit 1ab3723

Please sign in to comment.