[rfc] KConfig Schema (was: Re: Experiences with KDE-CVS at LinuxWorldExpo)

Marc Mutz mutz at kde.org
Mon Nov 18 23:37:39 GMT 2002


<snip>
> Looks good indeed. Although I'm not thrilled by the idea that we have
> to parse a XML file first in order to read a config file. That's not
> going to help performance.
<snip>

Also, the fact that every config item seems to be a QObject is not 
nice... ( sizeof( QObject ) == 40 ).

I've hammered together a proposal for a lightweight config item type 
declaration language that is based on "XML Schema (2): Datatypes", but 
is not XML.

A set of programs needs to be written for that, but all of them are 
relatively easy, given that you just have to implement what's in the 
Schema spec:

1. A KConfigSchema validator that is run on the app's schema file on at 
build time and checks the schema for validity and then creates
1a. A konfigrc that contains all the declared config items with their 
default settings.
1b. A .h file containing a precompiled version of the schema to be used 
by a KConfig validator at runtime (while reading values and - 
optionally for debug purposes - while writing values).

2. Said KConfigValidator (part of kdecore).

TODO in what follows:
- Nicer declaration of groups
- Referencing a system type library
- Support for the "whiteSpace" facet, if needed
- Support for fixed restrictions (restricting to a fixed minInclusive of 
  0 doesn't allow derived values to increase the lower bound anymore).
- Adding annotation to config items to be translated and displayed in a
  kconfedit

Comments? Any cases unaccounted for?

Oh, and the question "do we need unions?" below: The answer is yes:

@fourDigits restricts @integer
	by totalDigits 4
@sixDigits restricts @integer
	by totalDigits 6
@fourOrSixDigits restricts union( @fourDigits, @sixDigits )

Marc

-- 
It's good fortune for the government that the masses don't think.
                                                         -- Adolf Hitler
-------------- next part --------------
# everything after the hash mark is a comment (till eol)

# known built-ins: (freely adapted from XML Schema)
# anySimpleType (anything; parsing is done by app)
#  string
#   normalizedString (simplyfyWhiteSpace)
#    token
#     language
#  decimal
#   integer
#    nonPositiveInterger
#     negativeInteger
#    long (== long long)
#     int
#      short
#       byte
#    nonNegativeInteger
#     positiveInteger
#     unsignedLong ( == unsigned long long )
#      unsignedInt
#       unsignedShort
#        unsignedByte
#  uri (kurl)
#  float
#  double
#  binary (base64-serialization of QByteArray)
#  boolean
#  dateTime
#  time
#  date
#  duration
#  year
#  month
#  day
#  yearMonth
#  monthDay

# facets for unordered:
#  length, minLength, maxLength
#  pattern (regexp)
#  enumeration
# additional facets for ordered:
#  maxInclusive, minInclusive, maxExclusive, minExclusive
# additional facets for numbers:
#  totalDigits, fractionDigits

# multiple patterns (from XML Schema spec):
# It is a consequence of the schema representation constraint Multiple
# patterns (�4.3.4.3) and of the rules for *restriction* that
# *pattern* facets specified on the same step in a type derivation are
# ORed together, while *pattern* facets specified on different steps
# of a type derivation are ANDed together.

# multiple enumerations:
# like pattern: in the same step "or", in different steps "and"

# types are prefixed by the at-sign: @typename
# and derived from base types by the following construct:

@type restricts @basetype
	by facet1 value-of-facet1
	by facet2 value-of-facet2

#e.g.:

@nonNegativeInteger restricts @integer
	by minInclusive 0

# you can build lists from atomic types:
# reasoning: QStringList, QValueList<int>, ...

@listOfUInt restricts list(@unsignedInt)
	# by nothing or
	# by length 8 # exactly eight elememts

@qsize restricts @listOfUInt
	by length 2

@qrect restricts @listOfUInt
	by length 4

# etc...

# do we need unions?

@dateOrDateTime restricts union(@date, at dateTime)
	# can only use pattern and enumeration for unions

# spaces in typenames are supported:

@"type with spaces" restricts @date
	by minInclusive "2000-01-01"

# this is how a config option is declared (is is a synonym for "restricts")

myConfigOption is @"type with spaces"
	default "2001-01-01"

# since "is" == "restricts", you can also say:

@listOfInts is list(@int)

# or

orderOfComponents is list(@int)
	by enumeration "1, 2, 3"
	by enumeration "3, 1, 2"
	by enumeration "2, 3, 1"
	by enumeration "1, 3, 2"
	by enumeration "2, 1, 3"
	by enumeration "3, 2, 1"

# example for an enumerated type that is not a string:

@onlyLeapDays restricts @"type with spaces"
	by enumeration "2004-02-29"
	by enumeration "2008-02-29"
	by enumeration "2012-02-29"
	by enumeration "2016-02-29"
	by enumeration "2020-02-29"
	by enumeration "2024-02-29"
	by enumeration "2028-02-29"
	by enumeration "2032-02-29"
	by enumeration "2036-02-29"
	# ends here, since time_t overflows

# attempt at grammar ( [ \t]+ allowed (mostly required) between tokens):

start := line*

line := ( head-line | body-line )? comment? CRLF

comment := "#" [^\n]*
	; comments start with # and extends to EOL

head-line := ( typename | configname ) ( "restricts" | "is" ) basename
body-line := by-line | defaults-line

by-line := "by" facet value
default-line := "default" value

typename := "@" identifier

configname := ( '[' identifier ']' )? identifier
	; [group]key syntax

basename := typename
	 | "list(" typename ")"
	 | "union(" typename ( "," typenmae )+ ")"

identifier := itext+ | '"' ( itext | SP | '\' itext )+ '"'
	; identifier is a token or a restricted quoted-string
	; '\x' is sematically equivalent to 'x'

itext := [A-Za-z0-9-_+.] ; what else?

facet := literal ; any facet listed above
value := string
	; any string (possibly quoted) that corresponds to a type suitable
	; to the facet (by) or the basetype (default)

string := literal | quoted-string

literal := < sequence of any chars except whitespace and CTLs >
quoted-string := < see rfc2822 >

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: signature
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20021119/1caf4f24/attachment.sig>


More information about the kde-core-devel mailing list