create: () => {
normalizeOption: (descriptor) => {
required: (name) => {
descriptor.hasSlot(name).ifFalse(() => {
fail()
})
descriptor.slotValue(name)
}
validateString: (value) => {
String.recognizes(value).ifFalse(() => {
fail()
})
value
}
validateNonEmptyString: (value) => {
validateString(value)
if(value == "") {
fail()
}
value
}
validateOptionalString: (value) => {
(value === null).ifFalse(() => {
validateString(value)
})
value
}
isAlpha: (octet) => {
((octet >= 65) && (octet <= 90)) ||
((octet >= 97) && (octet <= 122))
}
isDigit: (octet) => {
(octet >= 48) && (octet <= 57)
}
validateLongName: (value) => {
validateString(value)
source: Encoding.UTF8.encode(value)
if(source.size() == 0) {
fail()
}
isAlpha(source[0]).ifFalse(() => {
fail()
})
index: 1
while(index < source.size()) {
octet: source[index]
allowed: isAlpha(octet) || isDigit(octet) || (octet == 45)
allowed.ifFalse(() => {
fail()
})
index = index + 1
}
value
}
validateShortName: (value) => {
validateString(value)
source: Encoding.UTF8.encode(value)
(source.size() == 1).ifFalse(() => {
fail()
})
(isAlpha(source[0]) || isDigit(source[0])).ifFalse(() => {
fail()
})
value
}
validateInteger: (value) => {
Integer.recognizes(value).ifFalse(() => {
fail()
})
value
}
keyValue: validateNonEmptyString(required("key"))
longValue: required("long")
shortValue: required("short")
minValuesValue: validateInteger(required("minValues"))
maxValuesValue: validateInteger(required("maxValues"))
minOccurrencesValue: validateInteger(required("minOccurrences"))
maxOccurrencesValue: required("maxOccurrences")
valueNameValue: validateOptionalString(required("valueName"))
helpValue: validateOptionalString(required("help"))
(longValue === null).ifFalse(() => {
validateLongName(longValue)
})
(shortValue === null).ifFalse(() => {
validateShortName(shortValue)
})
if((longValue === null) && (shortValue === null)) {
fail()
}
validValueCardinality: ((minValuesValue == 0) && (maxValuesValue == 0)) ||
((minValuesValue == 1) && (maxValuesValue == 1))
validValueCardinality.ifFalse(() => {
fail()
})
if(maxValuesValue == 0) {
(valueNameValue === null).ifFalse(() => {
fail()
})
}
if(maxValuesValue == 1) {
if(valueNameValue === null) {
fail()
}
validateNonEmptyString(valueNameValue)
}
((minOccurrencesValue == 0) || (minOccurrencesValue == 1)).ifFalse(() => {
fail()
})
(maxOccurrencesValue === null).ifFalse(() => {
validateInteger(maxOccurrencesValue)
(maxOccurrencesValue == 1).ifFalse(() => {
fail()
})
})
canonical: {
kind: "option"
key: keyValue
long: longValue
short: shortValue
minValues: minValuesValue
maxValues: maxValuesValue
minOccurrences: minOccurrencesValue
maxOccurrences: maxOccurrencesValue
valueName: valueNameValue
help: helpValue
}
canonical.freeze()
}
normalizePositional: (descriptor) => {
required: (name) => {
descriptor.hasSlot(name).ifFalse(() => {
fail()
})
descriptor.slotValue(name)
}
validateString: (value) => {
String.recognizes(value).ifFalse(() => {
fail()
})
value
}
validateNonEmptyString: (value) => {
validateString(value)
if(value == "") {
fail()
}
value
}
validateOptionalString: (value) => {
(value === null).ifFalse(() => {
validateString(value)
})
value
}
validateInteger: (value) => {
Integer.recognizes(value).ifFalse(() => {
fail()
})
value
}
keyValue: validateNonEmptyString(required("key"))
minOccurrencesValue: validateInteger(required("minOccurrences"))
maxOccurrencesValue: required("maxOccurrences")
valueNameValue: validateNonEmptyString(required("valueName"))
helpValue: validateOptionalString(required("help"))
((minOccurrencesValue == 0) || (minOccurrencesValue == 1)).ifFalse(() => {
fail()
})
(maxOccurrencesValue === null).ifFalse(() => {
validateInteger(maxOccurrencesValue)
(maxOccurrencesValue == 1).ifFalse(() => {
fail()
})
})
canonical: {
kind: "positional"
key: keyValue
minOccurrences: minOccurrencesValue
maxOccurrences: maxOccurrencesValue
valueName: valueNameValue
help: helpValue
}
canonical.freeze()
}
normalizers: {
option: normalizeOption
positional: normalizePositional
}
normalizers
}