mirror of
https://github.com/Nikolay-Shirokov/cc-1c-skills.git
synced 2026-06-15 18:34:57 +03:00
feat(skd): StandardBeginningDate в dataParameters через shape inference
Раньше StandardBeginningDate (используется когда top-level param имеет
тип xs:dateTime + UI выбор "Начало дня"/"Custom") декомпилировалась
через InnerText: variant+date конкатенировались в "Custom2022-10-25..."
и compile эмитил как xs:string.
Cross-reference на корпусе (671 отчёт):
608 v8:StandardPeriod → v8:StandardPeriod
180 xs:dateTime → v8:StandardBeginningDate
120 xs:dateTime → xs:dateTime (raw)
Decompile теперь сохраняет SBD как объект {variant, date} (без @type marker).
Compile различает SP/SBD по форме value:
{variant, date} → SBD
{variant, startDate, endDate} → SP с датами
{variant} only → инференс по имени (BeginningOf* → SBD)
В корпусе ни одного ambiguous (variant=Custom без полей) не существует:
все 33 SBD/Custom имеют date, все 93 SP/Custom — startDate/endDate.
sample30: −22 строки (932 → 910).
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# skd-compile v1.85 — Compile 1C DCS from JSON
|
||||
# skd-compile v1.86 — Compile 1C DCS from JSON
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
param(
|
||||
[string]$DefinitionFile,
|
||||
@@ -2585,26 +2585,51 @@ function Emit-DataParameters {
|
||||
} elseif ($null -ne $dp.value) {
|
||||
$vtype = "$($dp.valueType)"
|
||||
if (($dp.value -is [PSCustomObject] -or $dp.value -is [hashtable]) -and ($dp.value.variant)) {
|
||||
# StandardPeriod (PSCustomObject from JSON / hashtable from shorthand parser).
|
||||
# Platform-pattern: startDate/endDate ТОЛЬКО для variant=Custom.
|
||||
$_sd = $null; $_ed = $null
|
||||
# Standard{Period,BeginningDate} — различаем по форме value:
|
||||
# {variant, date} → SBD
|
||||
# {variant, startDate, endDate} → SP с датами
|
||||
# {variant} only → инференс по имени (BeginningOf* → SBD, иначе SP)
|
||||
$_hasDate = $false; $_hasSD = $false
|
||||
if ($dp.value -is [PSCustomObject]) {
|
||||
if ($dp.value.PSObject.Properties['startDate']) { $_sd = "$($dp.value.startDate)" }
|
||||
if ($dp.value.PSObject.Properties['endDate']) { $_ed = "$($dp.value.endDate)" }
|
||||
$_hasDate = [bool]$dp.value.PSObject.Properties['date']
|
||||
$_hasSD = [bool]$dp.value.PSObject.Properties['startDate']
|
||||
} else {
|
||||
if ($dp.value.Contains('startDate')) { $_sd = "$($dp.value['startDate'])" }
|
||||
if ($dp.value.Contains('endDate')) { $_ed = "$($dp.value['endDate'])" }
|
||||
$_hasDate = $dp.value.Contains('date')
|
||||
$_hasSD = $dp.value.Contains('startDate')
|
||||
}
|
||||
$_variantStr = "$($dp.value.variant)"
|
||||
X "$indent`t`t<dcscor:value xsi:type=`"v8:StandardPeriod`">"
|
||||
X "$indent`t`t`t<v8:variant xsi:type=`"v8:StandardPeriodVariant`">$(Esc-Xml $_variantStr)</v8:variant>"
|
||||
if ($_variantStr -eq 'Custom') {
|
||||
if (-not $_sd) { $_sd = '0001-01-01T00:00:00' }
|
||||
if (-not $_ed) { $_ed = '0001-01-01T00:00:00' }
|
||||
X "$indent`t`t`t<v8:startDate>$(Esc-Xml $_sd)</v8:startDate>"
|
||||
X "$indent`t`t`t<v8:endDate>$(Esc-Xml $_ed)</v8:endDate>"
|
||||
$_isSBD = $_hasDate -or (-not $_hasSD -and $_variantStr -like 'BeginningOf*')
|
||||
if ($_isSBD) {
|
||||
$_d = $null
|
||||
if ($dp.value -is [PSCustomObject] -and $dp.value.PSObject.Properties['date']) { $_d = "$($dp.value.date)" }
|
||||
elseif ($dp.value -is [System.Collections.IDictionary] -and $dp.value.Contains('date')) { $_d = "$($dp.value['date'])" }
|
||||
X "$indent`t`t<dcscor:value xsi:type=`"v8:StandardBeginningDate`">"
|
||||
X "$indent`t`t`t<v8:variant xsi:type=`"v8:StandardBeginningDateVariant`">$(Esc-Xml $_variantStr)</v8:variant>"
|
||||
if ($_variantStr -eq 'Custom') {
|
||||
if (-not $_d) { $_d = '0001-01-01T00:00:00' }
|
||||
X "$indent`t`t`t<v8:date>$(Esc-Xml $_d)</v8:date>"
|
||||
}
|
||||
X "$indent`t`t</dcscor:value>"
|
||||
} else {
|
||||
# StandardPeriod — platform-pattern: startDate/endDate ТОЛЬКО для variant=Custom.
|
||||
$_sd = $null; $_ed = $null
|
||||
if ($dp.value -is [PSCustomObject]) {
|
||||
if ($dp.value.PSObject.Properties['startDate']) { $_sd = "$($dp.value.startDate)" }
|
||||
if ($dp.value.PSObject.Properties['endDate']) { $_ed = "$($dp.value.endDate)" }
|
||||
} else {
|
||||
if ($dp.value.Contains('startDate')) { $_sd = "$($dp.value['startDate'])" }
|
||||
if ($dp.value.Contains('endDate')) { $_ed = "$($dp.value['endDate'])" }
|
||||
}
|
||||
X "$indent`t`t<dcscor:value xsi:type=`"v8:StandardPeriod`">"
|
||||
X "$indent`t`t`t<v8:variant xsi:type=`"v8:StandardPeriodVariant`">$(Esc-Xml $_variantStr)</v8:variant>"
|
||||
if ($_variantStr -eq 'Custom') {
|
||||
if (-not $_sd) { $_sd = '0001-01-01T00:00:00' }
|
||||
if (-not $_ed) { $_ed = '0001-01-01T00:00:00' }
|
||||
X "$indent`t`t`t<v8:startDate>$(Esc-Xml $_sd)</v8:startDate>"
|
||||
X "$indent`t`t`t<v8:endDate>$(Esc-Xml $_ed)</v8:endDate>"
|
||||
}
|
||||
X "$indent`t`t</dcscor:value>"
|
||||
}
|
||||
X "$indent`t`t</dcscor:value>"
|
||||
} elseif ($vtype -match '^[a-zA-Z]+:') {
|
||||
# Полный xsi:type из decompile (например "xs:boolean", "dcscor:DesignTimeValue").
|
||||
$vStr = if ($dp.value -is [bool]) { "$($dp.value)".ToLower() } else { "$($dp.value)" }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# skd-compile v1.85 — Compile 1C DCS from JSON
|
||||
# skd-compile v1.86 — Compile 1C DCS from JSON
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
import argparse
|
||||
import json
|
||||
@@ -2100,16 +2100,31 @@ def emit_data_parameters(lines, items, indent):
|
||||
val = dp['value']
|
||||
vtype = str(dp.get('valueType') or '')
|
||||
if isinstance(val, dict) and val.get('variant'):
|
||||
# StandardPeriod. Platform-pattern: startDate/endDate ТОЛЬКО для variant=Custom.
|
||||
# Standard{Period,BeginningDate} — различаем по форме value:
|
||||
# {variant, date} → SBD
|
||||
# {variant, startDate, endDate} → SP с датами
|
||||
# {variant} only → инференс по имени (BeginningOf* → SBD, иначе SP)
|
||||
variant_str = str(val['variant'])
|
||||
lines.append(f'{indent}\t\t<dcscor:value xsi:type="v8:StandardPeriod">')
|
||||
lines.append(f'{indent}\t\t\t<v8:variant xsi:type="v8:StandardPeriodVariant">{esc_xml(variant_str)}</v8:variant>')
|
||||
if variant_str == 'Custom':
|
||||
sd = str(val.get('startDate') or '0001-01-01T00:00:00')
|
||||
ed = str(val.get('endDate') or '0001-01-01T00:00:00')
|
||||
lines.append(f'{indent}\t\t\t<v8:startDate>{esc_xml(sd)}</v8:startDate>')
|
||||
lines.append(f'{indent}\t\t\t<v8:endDate>{esc_xml(ed)}</v8:endDate>')
|
||||
lines.append(f'{indent}\t\t</dcscor:value>')
|
||||
has_date = 'date' in val
|
||||
has_sd = 'startDate' in val
|
||||
is_sbd = has_date or (not has_sd and variant_str.startswith('BeginningOf'))
|
||||
if is_sbd:
|
||||
lines.append(f'{indent}\t\t<dcscor:value xsi:type="v8:StandardBeginningDate">')
|
||||
lines.append(f'{indent}\t\t\t<v8:variant xsi:type="v8:StandardBeginningDateVariant">{esc_xml(variant_str)}</v8:variant>')
|
||||
if variant_str == 'Custom':
|
||||
d = str(val.get('date') or '0001-01-01T00:00:00')
|
||||
lines.append(f'{indent}\t\t\t<v8:date>{esc_xml(d)}</v8:date>')
|
||||
lines.append(f'{indent}\t\t</dcscor:value>')
|
||||
else:
|
||||
# StandardPeriod — platform-pattern: startDate/endDate ТОЛЬКО для variant=Custom.
|
||||
lines.append(f'{indent}\t\t<dcscor:value xsi:type="v8:StandardPeriod">')
|
||||
lines.append(f'{indent}\t\t\t<v8:variant xsi:type="v8:StandardPeriodVariant">{esc_xml(variant_str)}</v8:variant>')
|
||||
if variant_str == 'Custom':
|
||||
sd = str(val.get('startDate') or '0001-01-01T00:00:00')
|
||||
ed = str(val.get('endDate') or '0001-01-01T00:00:00')
|
||||
lines.append(f'{indent}\t\t\t<v8:startDate>{esc_xml(sd)}</v8:startDate>')
|
||||
lines.append(f'{indent}\t\t\t<v8:endDate>{esc_xml(ed)}</v8:endDate>')
|
||||
lines.append(f'{indent}\t\t</dcscor:value>')
|
||||
elif re.match(r'^[a-zA-Z]+:', vtype):
|
||||
# Полный xsi:type из decompile (например "xs:boolean", "dcscor:DesignTimeValue").
|
||||
v_str = str(val).lower() if isinstance(val, bool) else str(val)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# skd-decompile v0.68 — Decompile 1C DCS Template.xml to JSON DSL (draft)
|
||||
# skd-decompile v0.69 — Decompile 1C DCS Template.xml to JSON DSL (draft)
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
@@ -1807,6 +1807,8 @@ function Build-DataParameters {
|
||||
$vDisplay = $null
|
||||
$stdPeriodObj = $null
|
||||
if ($vt -eq 'StandardPeriod') {
|
||||
# Shape inference в compile: {variant, startDate, endDate} → SP с датами,
|
||||
# {variant} only с SP-вариантом (ThisMonth/Custom/etc) → SP без дат.
|
||||
$variant = Get-Text $valNode "v8:variant"
|
||||
$sd = Get-Text $valNode "v8:startDate"
|
||||
$ed = Get-Text $valNode "v8:endDate"
|
||||
@@ -1817,14 +1819,23 @@ function Build-DataParameters {
|
||||
if ($ed) { $stdPeriodObj['endDate'] = $ed }
|
||||
$canAuto = $false
|
||||
} elseif ($variant) {
|
||||
# Для shorthand эмитим как строку "Period = ThisMonth"; для object form —
|
||||
# объектом {variant: ThisMonth}, чтобы compile сгенерировал <v8:variant>
|
||||
# вместо плоского <value xsi:type="v8:StandardPeriod">ThisMonth</value>.
|
||||
$vDisplay = $variant
|
||||
if ($vmN -or $uspN) {
|
||||
$stdPeriodObj = [ordered]@{ variant = $variant }
|
||||
}
|
||||
}
|
||||
} elseif ($vt -eq 'StandardBeginningDate') {
|
||||
# Shape inference в compile: {variant, date} → SBD, либо variant начинается с BeginningOf*.
|
||||
$variant = Get-Text $valNode "v8:variant"
|
||||
$d = Get-Text $valNode "v8:date"
|
||||
$hasExplicitDate = $d -and $d -ne '0001-01-01T00:00:00'
|
||||
if ($hasExplicitDate) {
|
||||
$stdPeriodObj = [ordered]@{ variant = $variant; date = $d }
|
||||
$canAuto = $false
|
||||
} elseif ($variant) {
|
||||
$stdPeriodObj = [ordered]@{ variant = $variant }
|
||||
$canAuto = $false
|
||||
}
|
||||
} elseif ($vt -eq 'DesignTimeValue') {
|
||||
$vDisplay = $valNode.InnerText
|
||||
} elseif ($vt -eq 'LocalStringType') {
|
||||
|
||||
Reference in New Issue
Block a user