Skip to content
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
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/checkout@v7
with:
repository: OpenStatSpec/specification
ref: 864e84479f554b8ee250ffed44c4dfb963750d4a
ref: d76121ec343cf9614fb8ad2f8cc50f72ee29966e
path: openstatspec-specification
- uses: shivammathur/setup-php@v2
with:
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
uses: actions/checkout@v7
with:
repository: OpenStatSpec/specification
ref: 864e84479f554b8ee250ffed44c4dfb963750d4a
ref: d76121ec343cf9614fb8ad2f8cc50f72ee29966e
path: openstatspec-specification
- uses: shivammathur/setup-php@v2
with:
Expand Down Expand Up @@ -110,7 +110,7 @@ jobs:
uses: actions/checkout@v7
with:
repository: OpenStatSpec/specification
ref: 864e84479f554b8ee250ffed44c4dfb963750d4a
ref: d76121ec343cf9614fb8ad2f8cc50f72ee29966e
path: openstatspec-specification
- uses: shivammathur/setup-php@v2
with:
Expand Down Expand Up @@ -156,7 +156,7 @@ jobs:
uses: actions/checkout@v7
with:
repository: OpenStatSpec/specification
ref: 864e84479f554b8ee250ffed44c4dfb963750d4a
ref: d76121ec343cf9614fb8ad2f8cc50f72ee29966e
path: openstatspec-specification
- uses: shivammathur/setup-php@v2
with:
Expand Down Expand Up @@ -206,7 +206,7 @@ jobs:
uses: actions/checkout@v7
with:
repository: OpenStatSpec/specification
ref: 864e84479f554b8ee250ffed44c4dfb963750d4a
ref: d76121ec343cf9614fb8ad2f8cc50f72ee29966e
path: openstatspec-specification
- uses: shivammathur/setup-php@v2
with:
Expand Down
52 changes: 51 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,52 @@

## [Unreleased]

## [0.9.0] - 2026-12-01

Targets OpenStatSpec specification `v0.6.0` and passes its Conformance
Supplement 0.6 manifests for every profile this adapter claims. The Frontend
0.1 boundary case is skipped: PHP does not claim the Frontend 0.1 contract.

### Changed

- Frontend requests that break the request schema now fail with
`request_schema_invalid` instead of `plan_schema_invalid`. So do input
schemas with two names that are equal case-insensitively and numeric value
labels on a string variable.
- Case-insensitive name matching lowercases each code point on its own, so
the context-sensitive final sigma rule of `mb_strtolower()` no longer
applies.
- A `*` or `COMMENT` comment ends only at a period followed by whitespace or
the end of input. A name may contain an inner period (`a.b`). `AND`, `OR`,
`NOT`, `TO`, `EQ`, `NE`, `LT`, `LE`, `GT`, `GE`, `BY`, `ALL` and `WITH` are
never variable names or `INTO` targets. `FORMATS x (F8)` means `F8.0`.
- `VAR LAB` and `VAL LAB` are no longer accepted as abbreviations; they fail
with `unsupported_spss_command`.
- A replace recode whose target is not its source fails plan validation with
`target_already_exists` (before: `type_mismatch` at binding).
- The catalogue stores `variable.measurement_level`, `variable_role` and
`display_alignment` as text (`nominal`, `input`, `left` and so on, with
`unknown` for an unknown measurement level). Readers still accept the
numeric codes that earlier releases wrote. `migrateCatalog()` rewrites them
as text.
- `catalog_identity.schema_version` is now 1, the version of the
specification's `schema-outline.sql`. The adapter keeps its own migration
counter in `openstatspec_schema_migration`, now at 5. A catalogue completed
by 0.8.x stays usable without migration; run `migrateCatalog()` to convert
its vocabulary and identity.
- Exported dataset and variable attributes are ordered by name in code-point
order on every server.

### Fixed

- Negative zero in a numeric case value, and in a MySQL-family dictionary
value, is refused before mutation (`target_capability_exceeded`). Before, it
was stored silently as positive zero. The Dolt capability declaration lists
the refusal.
- A command at the end of the program without its terminating period now
fails with `spss_syntax_error` even when the command is unsupported or a
`*` comment that Frontend 0.2 does not accept.

## [0.8.4] - 2026-12-01

### Fixed
Expand Down Expand Up @@ -222,7 +268,11 @@ ownership checks are retained; this release requires no new migration.
- Pinned active conformance fixtures and capabilities to released OpenStatSpec
specification v0.1.0 at commit `d287c2cde9ade71f04e27dd012caec876901aed5`.

[Unreleased]: https://github.com/OpenStatSpec/php/compare/v0.8.1...HEAD
[Unreleased]: https://github.com/OpenStatSpec/php/compare/v0.9.0...HEAD
[0.9.0]: https://github.com/OpenStatSpec/php/compare/v0.8.4...v0.9.0
[0.8.4]: https://github.com/OpenStatSpec/php/compare/v0.8.3...v0.8.4
[0.8.3]: https://github.com/OpenStatSpec/php/compare/v0.8.2...v0.8.3
[0.8.2]: https://github.com/OpenStatSpec/php/compare/v0.8.1...v0.8.2
[0.8.1]: https://github.com/OpenStatSpec/php/compare/v0.8.0...v0.8.1
[0.8.0]: https://github.com/OpenStatSpec/php/compare/v0.7.1...v0.8.0
[0.7.1]: https://github.com/OpenStatSpec/php/compare/v0.7.0...v0.7.1
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ It imports an unencrypted SPSS `.sav` or `.zsav` dataset into a relational datab

## Status

PHP v0.8.1 targets released OpenStatSpec specification `v0.5.0` at immutable
commit `864e84479f554b8ee250ffed44c4dfb963750d4a`
PHP v0.9.0 targets released OpenStatSpec specification `v0.6.0` at immutable
commit `d76121ec343cf9614fb8ad2f8cc50f72ee29966e`
(`specification_status: released`). Composer derives the package version from its
Git tag; it is independent of the specification version.

Expand Down Expand Up @@ -260,7 +260,7 @@ Run the local gate before committing:

```bash
composer install
# Checkout specification v0.5.0 at 864e84479f554b8ee250ffed44c4dfb963750d4a first.
# Checkout specification v0.6.0 at d76121ec343cf9614fb8ad2f8cc50f72ee29966e first.
OPENSTATSPEC_SPECIFICATION_DIR=/path/to/exact-specification-checkout composer check
```

Expand Down
5 changes: 4 additions & 1 deletion docs/transformations.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,13 @@ composer check
They cover all 4 Plan 0.1, 26 Plan 0.2, 44 Frontend 0.2, 6 In-Place 0.1,
and 11 In-Place 0.2 manifest cases, plus all 90 effective Frontend 0.3 cases
(35 declared plus inherited cases minus the two comment supersessions).
They also run the v0.6.0 supplement manifests: 43 Frontend cases (the Frontend
0.1 boundary case is skipped, as PHP does not claim Frontend 0.1), 2 + 2 Plan,
1 In-Place 0.1 and 9 SAV/ZSAV fixtures.
Frontend checks compare source/plan hashes, exact inherited plans, diagnostics
and declared metadata preservation. Use
`OPENSTATSPEC_SPECIFICATION_DIR=/tmp/openstatspec-alignment-spec` for the
alignment checkout at unchanged commit `864e84479f554b8ee250ffed44c4dfb963750d4a`.
alignment checkout at commit `d76121ec343cf9614fb8ad2f8cc50f72ee29966e`.
The public Frontend 0.3 → native SQLite apply regression checks UNKNOWN,
metadata, provenance and unchanged dataset/table identity without extra data
artifacts or history. All 20 jobs in the
Expand Down
5 changes: 3 additions & 2 deletions src/Core/CapabilityDeclaration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
final readonly class CapabilityDeclaration implements JsonSerializable
{
public const SPECIFICATION_STATUS = 'released';
public const SPECIFICATION_RELEASE = 'v0.5.0';
public const SPECIFICATION_COMMIT = '864e84479f554b8ee250ffed44c4dfb963750d4a';
public const SPECIFICATION_RELEASE = 'v0.6.0';
public const SPECIFICATION_COMMIT = 'd76121ec343cf9614fb8ad2f8cc50f72ee29966e';

private Connection $connection;

Expand Down Expand Up @@ -193,6 +193,7 @@ private function profile(string $name, PdoSqlProfile $profile, bool $active): ar
'nan' => 'reject_before_mutation',
'positive_infinity' => 'reject_before_mutation',
'negative_infinity' => 'reject_before_mutation',
'negative_zero' => 'reject_before_mutation',
'system_missing' => 'sql_null',
] : null,
'storage_evidence' => $name === 'dolt' ? [
Expand Down
2 changes: 1 addition & 1 deletion src/Frontend/Spss/Binding/SchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,6 @@ public function addNumeric(string $name): void

private function key(string $name): string
{
return mb_strtolower($name, 'UTF-8');
return InputSchema::matchKey($name);
}
}
19 changes: 15 additions & 4 deletions src/Frontend/Spss/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ public function tokenize(string $source, bool $officialV03 = false): array
$this->comment($source, $offset, $line, $column, false);
continue;
}
// The termination rule comes first: trailing text without its period is a syntax error.
$terminated = preg_match('/\.(?:\s|\z)/', $source, offset: $offset) === 1;
$this->fail(
new SourceSpan($offset, $offset + 1, $line, $column, $line, $column + 1),
'Leading-star comments are not supported.',
'unsupported_spss_command',
$terminated ? 'Leading-star comments are not supported.' : 'Every SPSS command must end with a period.',
$terminated ? 'unsupported_spss_command' : 'spss_syntax_error',
);
}

Expand Down Expand Up @@ -112,6 +114,15 @@ public function tokenize(string $source, bool $officialV03 = false): array
$start = $offset;
while ($offset < $length) {
$identifierCharacter = $this->characterAt($source, $offset, $line, $column);
// A period is part of a name only when another name character follows it.
if (
$identifierCharacter === '.'
&& $offset + 1 < $length
&& $this->isIdentifierPart($this->characterAt($source, $offset + 1, $line, $column))
) {
$this->advance($identifierCharacter, $offset, $line, $column);
continue;
}
if (!$this->isIdentifierPart($identifierCharacter)) {
break;
}
Expand Down Expand Up @@ -184,7 +195,7 @@ private function comment(string $source, int &$offset, int &$line, int &$column,
} else {
$this->advance($character, $offset, $line, $column);
}
if (!$block && $character === '.') {
if (!$block && $character === '.' && ($offset >= strlen($source) || ctype_space($source[$offset]))) {
return;
}
}
Expand Down Expand Up @@ -288,7 +299,7 @@ private function isIdentifierStart(string $character): bool

private function isIdentifierPart(string $character): bool
{
return preg_match('/\A[\p{L}\p{M}\p{N}]\z/uD', $character) === 1 || str_contains('_@#$', $character);
return preg_match('/\A[\p{L}\p{M}\p{Nd}]\z/uD', $character) === 1 || str_contains('_@#$', $character);
}

private function characterAt(string $source, int $offset, int $line, int $column): string
Expand Down
43 changes: 24 additions & 19 deletions src/Frontend/Spss/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public function parseTokens(array $tokens, bool $officialV03 = false): Program

while (!$this->check(TokenType::EndOfFile)) {
$command = $this->current();
if (!$this->terminatorAhead()) {
$this->fail($command, 'Every SPSS command must end with a period.');
}
if ($this->matchKeyword('RECODE')) {
$statements[] = $this->recode($command);
while ($this->officialV03 && $this->match(TokenType::Slash)) {
Expand All @@ -85,12 +88,6 @@ public function parseTokens(array $tokens, bool $officialV03 = false): Program
} elseif ($this->matchKeyword('VALUE')) {
$this->consumeKeyword('LABELS', 'Expected LABELS after VALUE.');
$statements[] = $this->valueLabels($command);
} elseif ($this->matchKeyword('VAR')) {
$this->consumeKeyword('LAB', 'Expected LAB after VAR.');
$statements[] = $this->variableLabels($command);
} elseif ($this->matchKeyword('VAL')) {
$this->consumeKeyword('LAB', 'Expected LAB after VAL.');
$statements[] = $this->valueLabels($command);
} elseif ($this->matchKeyword('EXECUTE')) {
$statements[] = new ExecuteStatement($command->line, $command->span);
} elseif ($this->matchKeyword('COMPUTE')) {
Expand Down Expand Up @@ -254,7 +251,7 @@ private function expressionOperand(string $message): ExpressionOperand
return new LiteralOperand($token->lexeme, $token->span);
}
if ($this->current()->isWord()) {
$token = $this->advance();
$token = $this->consumeIdentifier($message);

return new VariableOperand($token->lexeme, $token->span);
}
Expand Down Expand Up @@ -302,24 +299,18 @@ private function formats(Token $command): FormatsStatement
do {
[$variables, $spans] = $this->existingVariables('FORMATS requires variables and a format.', $this->officialV03);
$this->consume(TokenType::LeftParenthesis, 'Expected ( before the format.');
$familyAndWidth = $this->consumeIdentifier('Expected an F format such as F8.2.');
if (preg_match('/\AF([1-9][0-9]*)\z/iD', $familyAndWidth->lexeme, $matches) !== 1) {
$this->fail($familyAndWidth, 'Only the numeric F format family is supported.', 'invalid_format');
}
$decimalToken = $this->consume(TokenType::Number, 'F format requires . followed by decimals.');
if (
$familyAndWidth->span->endOffset !== $decimalToken->span->startOffset
|| preg_match('/\A\.([0-9]+)\z/D', $decimalToken->lexeme, $decimalMatches) !== 1
) {
$this->fail($decimalToken, 'F format must use the Fwidth.decimals form.', 'invalid_format');
// The lexer reads Fw.d as one name because a name may contain an inner period.
$format = $this->consumeIdentifier('Expected an F format such as F8.2.');
if (preg_match('/\AF([1-9][0-9]*)(?:\.([0-9]+))?\z/iD', $format->lexeme, $matches) !== 1) {
$this->fail($format, 'Only the numeric F format family is supported.', 'invalid_format');
}
$rightParenthesis = $this->consume(TokenType::RightParenthesis, 'Expected ) after the format.');
foreach ($variables as $index => $variable) {
$targets[] = new FormatTarget(
$variable,
'F',
(int) $matches[1],
(int) $decimalMatches[1],
(int) ($matches[2] ?? 0),
$spans[$index],
SourceSpan::cover($spans[$index], $rightParenthesis->span),
);
Expand Down Expand Up @@ -547,7 +538,7 @@ private function existingVariables(string $message, bool $multiple = true, bool
$spans[$index] = SourceSpan::cover($spans[$index], $last->span);
$variables[$index] = new VariableRange($variables[$index], $last->lexeme, $spans[$index]);
} else {
$variable = $this->advance();
$variable = $this->consumeIdentifier($message);
$variables[] = $variable->lexeme;
$spans[] = $variable->span;
}
Expand Down Expand Up @@ -580,10 +571,24 @@ private function consumeIdentifier(string $message): Token
if (!$this->current()->isWord()) {
$this->fail($this->current(), $message);
}
if ($this->current()->isReservedWord()) {
$this->fail($this->current(), sprintf('%s is a reserved word and cannot name a variable.', $this->current()->lexeme));
}

return $this->advance();
}

private function terminatorAhead(): bool
{
for ($index = $this->position; $index < count($this->tokens); ++$index) {
if ($this->tokens[$index]->type === TokenType::Terminator) {
return true;
}
}

return false;
}

private function consumeKeyword(string $keyword, string $message): Token
{
if (!$this->current()->isKeyword($keyword)) {
Expand Down
23 changes: 21 additions & 2 deletions src/Frontend/Spss/Request/InputSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,34 @@ public function __construct(array $variables)
self::schema('$.input_schema.variables', 'Variables must be a non-empty ordered array.');
}
$validated = [];
foreach ($variables as $variable) {
$keys = [];
foreach ($variables as $index => $variable) {
if (!$variable instanceof InputVariable) {
self::schema('$.input_schema.variables', 'Every schema variable must be an InputVariable.');
}
$key = self::matchKey($variable->name);
if (isset($keys[$key])) {
self::schema('$.input_schema.variables[' . $index . '].name', 'Variable names must differ case-insensitively.');
}
$keys[$key] = true;
$validated[] = $variable;
}
$this->variables = $validated;
}

/**
* Case-insensitive name key: the unconditional per-code-point lowercase
* mapping. Mapping each code point alone keeps mb_strtolower's full
* mappings but never applies the context-sensitive Final_Sigma rule.
*/
public static function matchKey(string $name): string
{
return implode('', array_map(
static fn(string $character): string => mb_strtolower($character, 'UTF-8'),
mb_str_split($name, 1, 'UTF-8'),
));
}

public static function fromArray(mixed $raw, string $path = '$.input_schema'): self
{
if (!is_array($raw) || array_is_list($raw)) {
Expand Down Expand Up @@ -54,6 +73,6 @@ public static function fromArray(mixed $raw, string $path = '$.input_schema'): s

private static function schema(string $path, string $message): never
{
throw TransformationFailure::at('plan_schema_invalid', $path, $message);
throw TransformationFailure::at('request_schema_invalid', $path, $message);
}
}
9 changes: 8 additions & 1 deletion src/Frontend/Spss/Request/InputVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public function __construct(
self::schema('$.input_schema.variables[].measurement_level', 'Invalid measurement level.');
}
self::valueLabels($valueLabels, '$.input_schema.variables[].value_labels');
if ($storageKind === 'string') {
foreach ($valueLabels as $label) {
if ($label['value']['type'] !== 'string') {
self::schema('$.input_schema.variables[].value_labels', 'A string variable cannot have a numeric value label.');
}
}
}
}

public static function fromArray(mixed $raw, string $path): self
Expand Down Expand Up @@ -208,6 +215,6 @@ private static function string(mixed $value, string $path): string

private static function schema(string $path, string $message): never
{
throw TransformationFailure::at('plan_schema_invalid', $path, $message);
throw TransformationFailure::at('request_schema_invalid', $path, $message);
}
}
2 changes: 1 addition & 1 deletion src/Frontend/Spss/Request/SpssFrontendRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ private static function string(mixed $value, string $path): string

private static function schema(string $path, string $message): never
{
throw TransformationFailure::at('plan_schema_invalid', $path, $message);
throw TransformationFailure::at('request_schema_invalid', $path, $message);
}
}
Loading