Page 1 of 1

Data

Posted: Wed Apr 22, 2020 1:49 pm
by punt
Been playing around with some data formats for text files; I am looking for something that I won't use a library on, simple enough to code (don't want the make the syntax parser a project in itself), yet easy enough to understand for the user.

Been toying with this concept:

{section name: data}

that is the highest level contract. So you can have a file with a series of those. Examine data for a moment:

data charaterstics:
Multiple lines, and of course entries
Can nest sections in it.
so one can this:

Code: Select all

{top section: 
       {subsection:
              key = value
              key = value
       }
}

Now, clearly one can have comments. I plan on single line comments initially, with a simple "//" being a comment.
The only other thing I am working on is how to do array type values. Say I want this:

Code: Select all

{shortlist:
    values = (name = value, ip = value, port = value), (name = value1, ip = value1, port = value1)
}
And of course, how to do line continuations. probably the "\", but not sure

Re: Data

Posted: Wed Apr 22, 2020 1:58 pm
by punt
Of course, thinking just a nanosecond more.

I could forget the array concept, and just do like UOX3, and have the same key entered multiple times. Might be a good solution to balance against code complexity. And then just forget the line continuation.

Re: Data

Posted: Wed Apr 22, 2020 7:18 pm
by Xuri
My two cents: The more special characters and matching bracket pairs etc required, the easier it will be to mess up for the average user - especially as files get longer and more complex - which will ultimately lead to support requests like "Why is my stuff not working? Pls help look at my data!" accompanied by hundreds (or thousands) of lines of data! :D

Re: Data

Posted: Thu Apr 23, 2020 12:07 am
by punt
Agree. But I also need it simple coding wise, so I can trigger of line endings, etc. I think this is where I am out, hopefully simple enough:

So how does the text processing work.

The concept is fairly straightforward.

We expect text files to have the following format

{ sectionname:

key = value;
}

That is the base format. Now a few other notes:
1. Sections can be nested in sections.
2. Line comments are indicated by "//". Anything after a "//" is ignored
3. Values can be comprised of multiple values, seperated by a ","
4. value can be null, and just the key can be present (no trailing = is needed).

And a few constraints:
1. Values can not span multiple lines
2. A line can not exceed 4094 characters
3. Values are either text, or numbers

A file, does not require a "section" at the top level. Depening on the particualar
file, this may or not make a difference. But for text parsing a file can look
like this:
"FILE CONTENTS"

Code: Select all

key = value1
key2 = value,value,value
{section1:
       key = value
       key = value
       {   subsection1:
             key = value
        }
}
key3 = value
{section2:
   key = value
}
This example, as three top level key,value pairs at the "file" level, two
sections (section1 and section2), with those having key,value pairs. Section1
has one subsection.


Now in the code, what makes this all work

class KeyValue:
This contains the values for any key. It will indicate the value count,
and the type of each value
class ConfSection
This contains a section, and it values. It also has any subsections (so
nesting of ConfSection occurs)
class ConfFile
THis contains the data for a given file. It has flie level values, and holds
any top level sections in that file.

what is a keypath? a keypath looks like the following: "key1.key2.key3". That
would reference section with name key1, subsection name key2 of section key1, and
finally return the vlaue for key3 in subsction key2.


That is the concept. A few things I don't like or have right now:
1. values can't span multiple lines
2. no sense of a "arrays" of complex values. Such a value being multiple
subsections in of it self.
3. The handling of duplicate keys in a section (will probably addrss this).

Re: Data

Posted: Thu Apr 23, 2020 11:41 am
by punt
Ok, I said I didn't like the lack of line continuation. I believe I have updated it, that is a line has a "\" at the end of the line, it will continue on to the next line(but there will.be a space inserted).