Skip to content

Commit 1476b05

Browse files
committed
BugFix doppelte Kommentare in der Ausgabe des Quelltextes
1 parent 786e39a commit 1476b05

19 files changed

Lines changed: 1314 additions & 397 deletions

Sources/BMF2Code/BMF2Code.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import LStXML2Code
99
/// Quelletxtgenerator zur Nutzung des durch das BMF bereitgestellten Pseudo-Quelltext zur Berechnung der Lohnsteuerabzüge bei der Einkommensteuer.
1010
public struct BMF2Code {
1111
/// Interne Version
12-
public static let VERSION = "1.0.2"
12+
public static let VERSION = "1.0.3"
1313

1414

1515
// MARK: main entry point

Sources/LStXML2Code/Node.swift

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ public class Node : CustomStringConvertible {
3838

3939
public init(newParent: Node? = nil) {
4040
self.parent = newParent
41+
parent?.addAndSetParent(child: self)
4142
}
4243

4344
public func getChilds () -> [Node] {
4445
return self.childs
4546
}
4647

47-
public func add (child : Node) {
48+
public func addAndSetParent (child : Node) {
4849
self.childs.append(child)
4950
child.parent = self
5051
}
@@ -61,7 +62,26 @@ public class Node : CustomStringConvertible {
6162
}
6263
return self.childs[at]
6364
}
64-
65+
func removeChild (node : Node) -> Node? {
66+
for (offset, maybeSelf) in self.childs.enumerated() {
67+
if node === maybeSelf { // self reference? not compare content or whatever
68+
self.childs.remove(at: offset)
69+
return self
70+
}
71+
}
72+
return nil
73+
}
74+
func removeChildAndRemoveParent (node : Node) -> Node? {
75+
for (offset, maybeSelf) in self.childs.enumerated() {
76+
if node === maybeSelf { // self reference? not compare content or whatever
77+
self.childs.remove(at: offset)
78+
node.parent = nil
79+
return self
80+
}
81+
}
82+
return nil
83+
}
84+
6585
public func isLeaf () -> Bool {
6686
return childs.isEmpty
6787
}
@@ -98,5 +118,20 @@ public class Node : CustomStringConvertible {
98118
public func getParent () -> Node? {
99119
return self.parent
100120
}
121+
122+
/// Set new parent to the node.
123+
///
124+
/// This function remove if existing the parent and itself from parent child list and then add self to the parent child list and set the parent here
125+
///
126+
/// - Parameters:
127+
/// - Parameter with newParent to set
128+
/// - Returns self
129+
public func setParent (with newParent : Node?) -> Node {
130+
if let current = self.parent {
131+
current.removeChild (node: self)?.parent = nil
132+
}
133+
self.parent?.addAndSetParent(child: self)
134+
return self
135+
}
101136
}
102137

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 - Sebastian Ritter <bastie@users.noreply.github.com>
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
/// A value Node, e.g. in programming language with value types these value
7+
///
8+
/// - Note: A AssignNode is a Leaf and can not have a child
9+
public class AssignNode : Node, CustomDebugStringConvertible {
10+
11+
public var debugDescription: String {
12+
get {
13+
return "="
14+
}
15+
}
16+
17+
override public func addAndSetParent(child: Node) {
18+
fatalError("Value node can not have a child.")
19+
}
20+
21+
public func isInt () -> Bool {
22+
return false
23+
}
24+
public func isFloat () -> Bool {
25+
return false
26+
}
27+
public func isDouble () -> Bool {
28+
return false
29+
}
30+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 - Sebastian Ritter <bastie@users.noreply.github.com>
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
public class CharNode : Node , CustomDebugStringConvertible {
7+
8+
public var debugDescription: String {
9+
get {
10+
return "\(char)"
11+
}
12+
}
13+
14+
let char : Character
15+
16+
static var initiated : [Character:CharNode] = [:]
17+
public static func value (of newChar : Character) -> CharNode {
18+
if let result = initiated[newChar] {
19+
return result
20+
}
21+
initiated[newChar] = CharNode(with: newChar)
22+
return initiated[newChar]! // with get from initiated it is secure that instance is stored in it
23+
}
24+
public static func value (of characters : String) -> [CharNode] {
25+
var result : [CharNode] = []
26+
for char in characters {
27+
result.append(CharNode.value(of: char))
28+
}
29+
return result
30+
}
31+
32+
private init(newParent: Node? = nil, with newChar : Character) {
33+
self.char = newChar
34+
}
35+
36+
public func getValue () -> String {
37+
return "\(char)"
38+
}
39+
40+
public override func isLeaf() -> Bool {
41+
return true
42+
}
43+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 - Sebastian Ritter <bastie@users.noreply.github.com>
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
/// A value Node, e.g. in programming language with value types these value
7+
///
8+
/// - Note: A ClosedRoundBracketNode is a Leaf and can not have a child
9+
public class ClosedRoundBracketNode : Node, CustomDebugStringConvertible {
10+
11+
public var debugDescription: String {
12+
get {
13+
return ")"
14+
}
15+
}
16+
17+
override public func addAndSetParent(child: Node) {
18+
fatalError("Value node can not have a child.")
19+
}
20+
21+
public func isInt () -> Bool {
22+
return false
23+
}
24+
public func isFloat () -> Bool {
25+
return false
26+
}
27+
public func isDouble () -> Bool {
28+
return false
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 - Sebastian Ritter <bastie@users.noreply.github.com>
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
/// A value Node, e.g. in programming language with value types these value
7+
///
8+
/// - Note: A ClosedSquareBracketNode is a Leaf and can not have a child
9+
public class ClosedSquareBracketNode : Node, CustomDebugStringConvertible {
10+
11+
public var debugDescription: String {
12+
get {
13+
return "]"
14+
}
15+
}
16+
17+
override public func addAndSetParent(child: Node) {
18+
fatalError("Value node can not have a child.")
19+
}
20+
21+
public func isInt () -> Bool {
22+
return false
23+
}
24+
public func isFloat () -> Bool {
25+
return false
26+
}
27+
public func isDouble () -> Bool {
28+
return false
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 - Sebastian Ritter <bastie@users.noreply.github.com>
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
/// A value Node, e.g. in programming language with value types these value
7+
///
8+
/// - Note: A DotNode is a Leaf and can not have a child
9+
public class DotNode : Node, CustomDebugStringConvertible {
10+
11+
public var debugDescription: String {
12+
get {
13+
return "<Dot>"
14+
}
15+
}
16+
17+
override public func addAndSetParent(child: Node) {
18+
fatalError("Value node can not have a child.")
19+
}
20+
21+
public func isInt () -> Bool {
22+
return false
23+
}
24+
public func isFloat () -> Bool {
25+
return false
26+
}
27+
public func isDouble () -> Bool {
28+
return false
29+
}
30+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 - Sebastian Ritter <bastie@users.noreply.github.com>
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
/// A value Node, e.g. in programming language with value types these value
7+
///
8+
/// - Note: A FloatNumberNode is a Leaf and can not have a child
9+
///
10+
/// - Note: value is stored as string because Double 0.093 is same as 0.09299999999999999
11+
public class FloatNumberNode : Node, CustomDebugStringConvertible {
12+
13+
public var debugDescription: String {
14+
get {
15+
return "[Float value as string='\(asString)']"
16+
}
17+
}
18+
19+
public init(newParent: Node? = nil, with newValue: String) {
20+
super.init(newParent: newParent)
21+
self.setValue(with: newValue)
22+
}
23+
24+
private var asString = "0.0"
25+
26+
/// Set the new Value and return the oldValue. On error return nil
27+
public func setValue (stringRepresentation : String) -> Double?{
28+
if let newValue = Double(stringRepresentation) {
29+
let oldValue = self.asString
30+
self.asString = stringRepresentation
31+
return Double(oldValue)
32+
}
33+
if let result = Double(asString) {
34+
return result
35+
}
36+
return nil
37+
}
38+
39+
public func setValue (with : String) {
40+
self.asString = with
41+
}
42+
43+
public func getValue () -> String {
44+
return self.asString
45+
}
46+
47+
override public func addAndSetParent(child: Node) {
48+
fatalError("Value node can not have a child.")
49+
}
50+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 - Sebastian Ritter <bastie@users.noreply.github.com>
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
/// A value Node, e.g. in programming language with value types these value
7+
///
8+
/// - Note: A IdentiferNode is a Leaf and can not have a child
9+
public class IdentiferNode : Node, CustomDebugStringConvertible {
10+
11+
public var debugDescription: String {
12+
get {
13+
return "[Identifier named >>>\(super.getName())<<<]"
14+
}
15+
}
16+
17+
public init(newParent: Node? = nil, with name : String) {
18+
super.init(newParent: newParent)
19+
super.setName(name)
20+
}
21+
22+
public func getIdentifer () -> String {
23+
return super.getName()
24+
}
25+
26+
override public func addAndSetParent(child: Node) {
27+
fatalError("Value node can not have a child.")
28+
}
29+
30+
public func isInt () -> Bool {
31+
return false
32+
}
33+
public func isFloat () -> Bool {
34+
return false
35+
}
36+
public func isDouble () -> Bool {
37+
return false
38+
}
39+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 - Sebastian Ritter <bastie@users.noreply.github.com>
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
/// A value Node, e.g. in programming language with value types these value
7+
///
8+
/// - Note: A IntNumberNode is a Leaf and can not have a child
9+
public class IntNumberNode : Node, CustomDebugStringConvertible {
10+
11+
public var debugDescription: String {
12+
get {
13+
return "[Integer value='\(value)']"
14+
}
15+
}
16+
17+
public init(newParent: Node? = nil, with newValue: Int) {
18+
super.init(newParent: newParent)
19+
self.setValue(with: newValue)
20+
}
21+
22+
private var value : Int = 0
23+
24+
/// Set the new Value and return the oldValue. On error return nil
25+
public func setValue (stringRepresentation : String) -> Int?{
26+
if let newValue = Int(stringRepresentation) {
27+
self.value = newValue
28+
return self.value
29+
}
30+
return nil
31+
}
32+
33+
public func setValue (with : Int) {
34+
self.value = with
35+
}
36+
37+
public func getValue () -> Int {
38+
return self.value
39+
}
40+
41+
override public func addAndSetParent(child: Node) {
42+
fatalError("Value node can not have a child.")
43+
}
44+
}

0 commit comments

Comments
 (0)