Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
I3csstatus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jiří Kalvoda
I3csstatus
Commits
98158b32
Commit
98158b32
authored
2 years ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
Rename ConfigKeyValue -> ConfigOption
parent
1906caca
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ConfigParser.cs
+25
-25
25 additions, 25 deletions
ConfigParser.cs
with
25 additions
and
25 deletions
ConfigParser.cs
+
25
−
25
View file @
98158b32
...
...
@@ -71,8 +71,8 @@ class ConfigDuplicitKeyException: ConfigDuplicitException
}
class
ConfigNoAmenException
:
ConfigException
{
public
Config
KeyValue
Value
;
public
ConfigNoAmenException
(
Config
KeyValue
value
):
base
(
value
.
Section
.
Root
)
public
Config
Option
Value
;
public
ConfigNoAmenException
(
Config
Option
value
):
base
(
value
.
Section
.
Root
)
{
Value
=
value
;
}
...
...
@@ -83,9 +83,9 @@ class ConfigNoAmenException: ConfigException
}
class
ConfigMixedTabException
:
ConfigException
{
public
Config
KeyValue
Value
;
public
Config
Option
Value
;
public
int
Line
;
public
ConfigMixedTabException
(
Config
KeyValue
value
,
int
line
):
base
(
value
.
Section
.
Root
)
public
ConfigMixedTabException
(
Config
Option
value
,
int
line
):
base
(
value
.
Section
.
Root
)
{
Value
=
value
;
Line
=
line
;
...
...
@@ -97,9 +97,9 @@ class ConfigMixedTabException: ConfigException
}
class
ConfigWrongIndentException
:
ConfigException
{
public
Config
KeyValue
?
Value
;
public
Config
Option
?
Value
;
public
int
Line
;
public
ConfigWrongIndentException
(
ConfigSection
section
,
Config
KeyValue
?
value
,
int
line
):
base
(
section
.
Root
)
public
ConfigWrongIndentException
(
ConfigSection
section
,
Config
Option
?
value
,
int
line
):
base
(
section
.
Root
)
{
Value
=
value
;
Line
=
line
;
...
...
@@ -153,8 +153,8 @@ class ConfigNoValueException: ConfigException
}
class
ConfigUnusedOptionException
:
ConfigException
{
public
Config
KeyValue
Value
;
public
ConfigUnusedOptionException
(
Config
KeyValue
value
):
base
(
value
.
Root
)
public
Config
Option
Value
;
public
ConfigUnusedOptionException
(
Config
Option
value
):
base
(
value
.
Root
)
{
Value
=
value
;
}
...
...
@@ -311,14 +311,14 @@ abstract class ConfigValue
}
public
static
implicit
operator
string
(
ConfigValue
v
)
=>
v
.
AsString
();
}
class
Config
KeyValue
:
ConfigValue
class
Config
Option
:
ConfigValue
{
public
ConfigSection
Section
{
get
;
init
;}
internal
string
?
amen
;
internal
string
?
tabs
;
public
string
Key
{
get
;
init
;}
public
bool
Used
=
false
;
public
Config
KeyValue
Use
()
public
Config
Option
Use
()
{
Used
=
true
;
return
this
;
...
...
@@ -327,7 +327,7 @@ class ConfigKeyValue: ConfigValue
{
get
=>
Section
.
SectionName
!=
null
?
$"
{
Section
.
SectionName
}
:
{
Key
}
"
:
Key
;
}
internal
Config
KeyValue
(
ConfigSection
_Section
,
string
_Key
,
int
_line
):
base
(
_Section
.
Root
)
internal
Config
Option
(
ConfigSection
_Section
,
string
_Key
,
int
_line
):
base
(
_Section
.
Root
)
{
Section
=
_Section
;
Key
=
_Key
;
...
...
@@ -342,7 +342,7 @@ class ConfigKeyAsValue: ConfigValue
{
get
=>
(
Section
.
SectionName
!=
null
?
$"
{
Section
.
SectionName
}
: "
:
""
)
+
$"Key
{
Value
}
"
;
}
internal
ConfigKeyAsValue
(
Config
KeyValue
keyValue
):
base
(
keyValue
.
Root
)
internal
ConfigKeyAsValue
(
Config
Option
keyValue
):
base
(
keyValue
.
Root
)
{
Line
=
keyValue
.
Line
;
Value
=
keyValue
.
Key
;
...
...
@@ -375,13 +375,13 @@ class ConfigSectionNameAsDefaultValue: ConfigSectionNameAsValue
get
=>
base
.
FullName
+
$" as default for \"
{
defaultFor
}
\" option"
;
}
}
class
ConfigSection
:
IReadOnlyList
<
Config
KeyValue
>
class
ConfigSection
:
IReadOnlyList
<
Config
Option
>
{
public
ConfigParser
Root
{
get
;
init
;}
public
string
?
SectionName
{
get
;
init
;}
public
int
Line
;
List
<
Config
KeyValue
>
values
=
new
();
Dictionary
<
string
,
Config
KeyValue
>
valueByName
=
new
();
List
<
Config
Option
>
values
=
new
();
Dictionary
<
string
,
Config
Option
>
valueByName
=
new
();
public
bool
Used
=
false
;
public
ConfigSection
Use
()
{
...
...
@@ -394,14 +394,14 @@ class ConfigSection: IReadOnlyList<ConfigKeyValue>
SectionName
=
_SectionName
;
Line
=
_line
;
}
internal
void
Add
(
Config
KeyValue
v
)
internal
void
Add
(
Config
Option
v
)
{
if
(
valueByName
.
ContainsKey
(
v
.
Key
))
throw
new
ConfigDuplicitKeyException
(
this
,
v
.
Key
,
v
.
Line
,
valueByName
[
v
.
Key
].
Line
);
valueByName
[
v
.
Key
]
=
v
;
values
.
Add
(
v
);
}
public
IEnumerator
<
Config
KeyValue
>
GetEnumerator
()
public
IEnumerator
<
Config
Option
>
GetEnumerator
()
{
foreach
(
var
s
in
values
)
yield
return
s
;
...
...
@@ -409,15 +409,15 @@ class ConfigSection: IReadOnlyList<ConfigKeyValue>
System
.
Collections
.
IEnumerator
System
.
Collections
.
IEnumerable
.
GetEnumerator
()
=>
GetEnumerator
();
public
int
Count
{
get
{
return
values
.
Count
;}}
public
Config
KeyValue
this
[
int
i
]
public
Config
Option
this
[
int
i
]
{
get
{
return
values
[
i
];
}
}
public
Config
KeyValue
?
this
[
string
key
]
public
Config
Option
?
this
[
string
key
]
{
get
{
return
Optional
(
key
);
}
}
public
Config
KeyValue
?
Optional
(
string
key
)
public
Config
Option
?
Optional
(
string
key
)
{
if
(!
valueByName
.
TryGetValue
(
key
,
out
var
r
))
return
null
;
...
...
@@ -427,7 +427,7 @@ class ConfigSection: IReadOnlyList<ConfigKeyValue>
{
return
(
ConfigValue
?)
Optional
(
key
)
??
new
ConfigSectionNameAsDefaultValue
(
this
,
key
);
}
public
Config
KeyValue
Mandatory
(
string
key
)
public
Config
Option
Mandatory
(
string
key
)
{
if
(!
valueByName
.
TryGetValue
(
key
,
out
var
r
))
throw
new
ConfigNotDefinedException
(
this
,
key
);
...
...
@@ -448,7 +448,7 @@ class ConfigSection: IReadOnlyList<ConfigKeyValue>
public
ConfigSectionNameAsValue
SectionNameAsValue
()
=>
new
(
this
);
public
void
CheckUnused
()
{
foreach
(
Config
KeyValue
it
in
this
)
foreach
(
Config
Option
it
in
this
)
{
if
(
it
.
Used
==
false
)
throw
new
ConfigUnusedOptionException
(
it
);
...
...
@@ -466,7 +466,7 @@ class ConfigParser: IReadOnlyList<ConfigSection>
FileName
=
_FileName
;
string
[]
lines
=
s
.
Split
(
"\n"
);
var
currentSection
=
MainSection
=
new
(
this
,
null
,
0
);
Config
KeyValue
?
lastVal
=
null
;
Config
Option
?
lastVal
=
null
;
for
(
int
i
=
0
;
i
<
lines
.
Count
();
i
++)
{
string
l
=
lines
[
i
];
...
...
@@ -519,12 +519,12 @@ class ConfigParser: IReadOnlyList<ConfigSection>
int
indexArrow
=
l
.
IndexOf
(
"<<"
);
if
(
indexIs
==
-
1
&&
indexArrow
==
-
1
)
{
currentSection
.
Add
(
lastVal
=
new
Config
KeyValue
(
currentSection
,
tl
,
firstLineIndex
+
i
));
currentSection
.
Add
(
lastVal
=
new
Config
Option
(
currentSection
,
tl
,
firstLineIndex
+
i
));
continue
;
}
int
index
=
indexIs
==
-
1
?
indexArrow
:
indexArrow
==
-
1
?
indexIs
:
Math
.
Min
(
indexIs
,
indexArrow
);
string
key
=
l
[
0
..
index
].
Trim
();
currentSection
.
Add
(
lastVal
=
new
Config
KeyValue
(
currentSection
,
key
,
firstLineIndex
+
i
));
currentSection
.
Add
(
lastVal
=
new
Config
Option
(
currentSection
,
key
,
firstLineIndex
+
i
));
if
(
indexIs
!=
-
1
&&
(
indexArrow
==
-
1
||
indexIs
<
indexArrow
))
{
string
val
=
l
[(
indexIs
+
1
)..].
Trim
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment