From 764bb5125c5c5749efe3189f039a82140d1a6ae7 Mon Sep 17 00:00:00 2001 From: Guillaume Hachez Date: Sun, 11 Aug 2024 16:17:25 +0200 Subject: [PATCH] fix: add support for svh, lvh, dvh, svw, lvw, dvw, svmin, lvmin, dvmin, svmax, lvmax, dvmax units --- parser.jison | 40 ++++++++++++++++++++++++++++++++++++++++ src/lib/reducer.js | 20 ++++++++++++++++++++ src/parser.d.ts | 20 ++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/parser.jison b/parser.jison index d308d91..36cb668 100644 --- a/parser.jison +++ b/parser.jison @@ -22,9 +22,29 @@ (([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)ch\b return 'CHS'; (([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)rem\b return 'REMS'; (([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)vw\b return 'VWS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)svw\b return 'SVWS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)lvw\b return 'LVWS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)dvw\b return 'DVWS'; (([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)vh\b return 'VHS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)svh\b return 'SVHS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)lvh\b return 'LVHS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)dvh\b return 'DVHS'; (([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)vmin\b return 'VMINS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)svmin\b return 'SVMINS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)lvmin\b return 'LVMINS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)dvmin\b return 'DVMINS'; (([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)vmax\b return 'VMAXS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)svmax\b return 'SVMAXS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)lvmax\b return 'LVMAXS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)dvmax\b return 'DVMAXS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)vb\b return 'VBS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)svb\b return 'SVBS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)lvb\b return 'LVBS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)dvb\b return 'DVBS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)vi\b return 'VIS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)svi\b return 'SVIS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)lvi\b return 'LVIS'; +(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)dvi\b return 'DVIS'; (([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)cqw\b return 'CQWS'; (([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)cqh\b return 'CQHS'; (([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)cqi\b return 'CQIS'; @@ -102,9 +122,29 @@ expression | CHS { $$ = { type: 'ChValue', value: parseFloat($1), unit: 'ch' }; } | REMS { $$ = { type: 'RemValue', value: parseFloat($1), unit: 'rem' }; } | VHS { $$ = { type: 'VhValue', value: parseFloat($1), unit: 'vh' }; } + | SVHS { $$ = { type: 'SvhValue', value: parseFloat($1), unit: 'svh' }; } + | LVHS { $$ = { type: 'LvhValue', value: parseFloat($1), unit: 'lvh' }; } + | DVHS { $$ = { type: 'DvhValue', value: parseFloat($1), unit: 'dvh' }; } | VWS { $$ = { type: 'VwValue', value: parseFloat($1), unit: 'vw' }; } + | SVWS { $$ = { type: 'SvwValue', value: parseFloat($1), unit: 'svw' }; } + | LVWS { $$ = { type: 'LvwValue', value: parseFloat($1), unit: 'lvw' }; } + | DVWS { $$ = { type: 'DvwValue', value: parseFloat($1), unit: 'dvw' }; } | VMINS { $$ = { type: 'VminValue', value: parseFloat($1), unit: 'vmin' }; } + | SVMINS { $$ = { type: 'SvminValue', value: parseFloat($1), unit: 'svmin' }; } + | LVMINS { $$ = { type: 'LvminValue', value: parseFloat($1), unit: 'lvmin' }; } + | DVMINS { $$ = { type: 'DvminValue', value: parseFloat($1), unit: 'dvmin' }; } | VMAXS { $$ = { type: 'VmaxValue', value: parseFloat($1), unit: 'vmax' }; } + | SVMAXS { $$ = { type: 'SvmaxValue', value: parseFloat($1), unit: 'svmax' }; } + | LVMAXS { $$ = { type: 'LvmaxValue', value: parseFloat($1), unit: 'lvmax' }; } + | DVMAXS { $$ = { type: 'DvmaxValue', value: parseFloat($1), unit: 'dvmax' }; } + | VBS { $$ = { type: 'VbValue', value: parseFloat($1), unit: 'vb' }; } + | SVBS { $$ = { type: 'SvbValue', value: parseFloat($1), unit: 'svb' }; } + | LVBS { $$ = { type: 'LvbValue', value: parseFloat($1), unit: 'lvb' }; } + | DVBS { $$ = { type: 'DvbValue', value: parseFloat($1), unit: 'dvb' }; } + | VIS { $$ = { type: 'VhValue', value: parseFloat($1), unit: 'vi' }; } + | SVIS { $$ = { type: 'SvhValue', value: parseFloat($1), unit: 'svi' }; } + | LVIS { $$ = { type: 'LvhValue', value: parseFloat($1), unit: 'lvi' }; } + | DVIS { $$ = { type: 'DvhValue', value: parseFloat($1), unit: 'dvi' }; } | CQWS { $$ = { type: 'CqwValue', value: parseFloat($1), unit: 'cqw' }; } | CQHS { $$ = { type: 'CqhValue', value: parseFloat($1), unit: 'cqh' }; } | CQIS { $$ = { type: 'CqiValue', value: parseFloat($1), unit: 'cqi' }; } diff --git a/src/lib/reducer.js b/src/lib/reducer.js index 93e4928..b7a6e28 100644 --- a/src/lib/reducer.js +++ b/src/lib/reducer.js @@ -17,9 +17,29 @@ function isValueType(node) { case 'ChValue': case 'RemValue': case 'VhValue': + case 'SvhValue': + case 'LvhValue': + case 'DvhValue': case 'VwValue': + case 'SvwValue': + case 'LvwValue': + case 'DvwValue': case 'VminValue': + case 'SvminValue': + case 'LvminValue': + case 'DvminValue': case 'VmaxValue': + case 'SvmaxValue': + case 'LvmaxValue': + case 'DvmaxValue': + case 'VbValue': + case 'SvbValue': + case 'LvbValue': + case 'DvbValue': + case 'ViValue': + case 'SviValue': + case 'LviValue': + case 'DviValue': case 'CqwValue': case 'CqhValue': case 'CqiValue': diff --git a/src/parser.d.ts b/src/parser.d.ts index e2e4b7b..5ab6579 100644 --- a/src/parser.d.ts +++ b/src/parser.d.ts @@ -23,9 +23,29 @@ export interface DimensionExpression { | 'ChValue' | 'RemValue' | 'VhValue' + | 'SvhValue' + | 'LvhValue' + | 'DvhValue' | 'VwValue' + | 'SvwValue' + | 'LvwValue' + | 'DvwValue' | 'VminValue' + | 'SvminValue' + | 'LvminValue' + | 'DvminValue' | 'VmaxValue' + | 'SvmaxValue' + | 'LvmaxValue' + | 'DvmaxValue' + | 'VbValue' + | 'SvbValue' + | 'LvbValue' + | 'DvbValue' + | 'ViValue' + | 'SviValue' + | 'LviValue' + | 'DviValue' | 'CqwValue' | 'CqhValue' | 'CqbValue'