pad.mattdiesel.co.uk

Snippet - Ini Specification

Ini Specification (Text only)

Ini Specification
Created 2014-07-10 16:05:54.212620 by Matt.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
INI Specification
-----------------


1.0 Contents
--------

TODO


2.0 Lexical Elements
--------------------

2.1 Horizontal Whitespace

Any of: Space, Tab.

2.2 Newline

Any of: "\r\n",  "\r" and "\n"

2.3 Quoted strings

Strings can be with double or single quotes. There are no escapes, to insert a
literal quote then double it.

Quoted strings can't include newlines. 

2.4 Comments

Comments can be anywhere in the file, and start with a semicolon. A comment
after a value is kept when changing the value. Comments within sections are
removed when the section is deleted.

2.5 Brackets...

Correct terminology as I understand it is:

{} - Braces
[] - Brackets
() - Parentheses

Doesn't really matter for this, but thought I'd add it in.


3.0 Syntax
--------------------

Any text before the first section is ignored. 

3.1 Section header

An open bracket as the first non-whitespace character on a line, followed by
the section header Text, then a closing bracket and a newline.

If multiple closing brackets appear on the line the last is taken, so section
names may include closing brackets.

Section names can be blank.

Section header sequence: 
Newline [whitespace] '[' Text ']' [whitespace] [comment] Newline


3.2 Key/Value pairs

Within a section, any line that is not empty and does not begin with an opening
bracket is treated as a key/value pair.

The key is any Text before the first equals sign.
Values are the Text after the first equals sign. 

If no equals sign appears outside of quoted strings on the line then the line
is taken to be a key, and the value is blank.

Key/value pair sequence.
[whitespace] KeyText [whitespace] = [whitespace] ValueText [whitespace] [comment] Newline

3.3 Text

Text consists of quoted strings, strings or a combination of both. 


Text:
[whitespace] (String | QuotedString)* [whitespace]

KeyText:
[whitespace] (KeyString | QuotedString)* [whitespace]

KeyString:
KeyChar*

KeyChar:
Any Char that is not: Semicolon, newline, equals, quote.

ValueString:
String

String:
Char*

Char:
Anything that is not: Semicolon, newline, quote.


QuotedString:
" String ["" String]* "



4.0 Logic
-----------

4.1 ini_enumSectionNames

Reads until it finds the following sequence:
Newline [whitespace] '[' Text ']' [whitespace] [comment] Newline

The enum callback function is then called on Text. 

This function does not check if section names are duplicated.

4.2 ini_enumSection

Reads until it finds the section header sequence with a matching section name.

Reads 


5.0 Example
-----------


{{{
Any text before the first section is ignored.

[Section Title]
Key = Value
"Key with an = sign in it" = "Value with a ; in it" ; an actual comment

[Another "Section"]