[x3d-public] Check parameters for range, enum, what else? TypeScript?
John Carlson
yottzumm at gmail.com
Thu Jun 18 18:12:04 PDT 2020
I haven't figured out how to do imports in TypeScript yet. Contributions
for setter and constructor validation code welcome!
Here's what I've got so far:
John
def settervalidate(self, field, name):
fld = self.getField(name)
str = ""
rel = { 'minInclusive':" < ",
'maxInclusive':" > ",
'minExclusive':" <= ",
'maxExclusive':" >= "}
for k,v in rel.items():
try:
if field.get('type').startswith("MF") or field.get('type')
== "SFColor" or field.get('type') == "SFVec2f" or field.get('type') ==
"SFVec3f":
str += " if ("+fld+" == null || "+fld+".length
<= 0 || Math."+k[0:3] +"("+fld+") " + v + " " + field.get(k) + ") {\n"
str += " return undefined;\n\t}\n"
else:
str += " if ("+fld+" == null || "+fld+" " + v +
" " + field.get(k) + ") {\n"
str += " return undefined;\n\t}\n"
except:
pass
try:
if field.get('additionalEnumerationValuesAllowed') != "true":
enumerations = field.iter("enumeration")
efound = 0
for enum in enumerations:
if efound == 0:
str += " if (" + "'"+enum.get('value')+"'" +
' === '+fld+') {\n'
efound = 1
else:
str += " } else if (" +
"'"+enum.get('value')+"'" + ' === '+fld+') {\n'
if efound == 1:
if enum.get('use') == 'required':
str += " } else if (" +
"'"+enum.get('use')+"'" +" === 'required') {\n"
str += "
console.error('"+field.get('name')+" required, but does not have legal
value (undefined?)');\n"
str += " return undefined;\n"
str += " }\n"
except KeyError:
pass
# if field.get('type') == 'SFVec2d':
# str += " if ("+fld+" == null || "+fld+".length
!== 2 ) {\n"
# str += " return undefined;\n"
# str += " }\n"
# elif field.get('type') == 'SFVec2f':
# str += " if ("+fld+" == null || "+fld+".length
!== 2 ) {\n"
# str += " return undefined;\n"
# str += " }\n"
# elif field.get('type') == 'SFVec3d':
# str += " if ("+fld+" == null || "+fld+".length
!== 3 ) {\n"
# str += " return undefined;\n"
# str += " }\n"
# elif field.get('type') == 'SFVec3f':
# str += " if ("+fld+" == null || "+fld+".length
!== 3 ) {\n"
# str += " return undefined;\n"
# str += " }\n"
# elif field.get('type') == 'SFColor':
# str += " if ("+fld+" == null || "+fld+".length
!== 3 ) {\n"
# str += " return undefined;\n"
# str += " }\n"
# elif field.get('type') == 'SFRotation':
# str += " if ("+fld+" == null || "+fld+".length
!== 4 ) {\n"
# str += " return undefined;\n"
# str += " }\n"
# elif field.get('type') == 'SFColorRGBA':
# str += " if ("+fld+" == null || "+fld+".length
!== 4 ) {\n"
# str += " return undefined;\n"
# str += " }\n"
# elif field.get('type') == 'MFVec2d':
# str += " if ("+fld+" == null || "+fld+".length
% 2 !== 0 ) {\n"
# str += " return undefined;\n"
# str += " }\n"
# elif field.get('type') == 'MFVec2f':
# str += " if ("+fld+" == null || "+fld+".length
% 2 !== 0 ) {\n"
# str += " return undefined;\n"
# str += " }\n"
# elif field.get('type') == 'MFVec3d':
# str += " if ("+fld+" == null || "+fld+".length
% 3 !== 3 ) {\n"
# str += " return undefined;\n"
# str += " }\n"
# elif field.get('type') == 'MFVec3f':
# str += " if ("+fld+" == null || "+fld+".length
% 3 !== 3 ) {\n"
# str += " return undefined;\n"
# str += " }\n"
return str
On Tue, Jun 16, 2020 at 6:18 PM Cecile Muller <contact at wildpeaks.fr> wrote:
> Good evening,
>
>
> As a data point, I would highly recommend Typescript: it has solid tooling
> and, for example, saves a lot of time
> by providing immediate feedback while you're typing (in editors with
> intellisense).
>
> And if you worry about adding a transpilation step, know that you can also
> run it directly using "ts-node" package:
> https://www.npmjs.com/package/ts-node
>
> Example:
> node -r ts-node/register/transpile-only src/script.ts
>
>
> See you,
> Cecile
>
> On Tue, Jun 16, 2020 at 5:16 AM John Carlson <yottzumm at gmail.com> wrote:
>
>> I am checking parameters for range, enum, length, not type(s) yet, ...
>> what else is there for setter and constructor parameter checking?
>>
>> My first gulp would be to give parameters to their types, ala
>> TypeScript. That would be one way to solve the parameter type problem. Is
>> it OK to convert my ES6 x3d.mjs module to TypeScript? Those who are against
>> the coffee languages might approve.
>>
>> I can see that the X3DUOM supports multiple types for parameters. It
>> looks like TypeScript allows overloading as well.
>>
>> Thanks,
>>
>> John
>> _______________________________________________
>> x3d-public mailing list
>> x3d-public at web3d.org
>> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>>
> _______________________________________________
> x3d-public mailing list
> x3d-public at web3d.org
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20200618/52920421/attachment.html>
More information about the x3d-public
mailing list