@@ -5,87 +5,115 @@ namespace MTLib.Generative;
55/// Provides a high level interface for sequential syntax generation.
66/// </summary>
77public sealed class SyntacticGenerator {
8- public SyntacticGenerator ( ) { }
8+ public SyntacticGenerator ( ) { }
99
10- public SyntacticGenerator ( String languageName ) {
11- this . Language = languageName ;
12- }
10+ public SyntacticGenerator ( String languageName ) {
11+ this . Language = languageName ;
12+ }
1313
14- public enum TabType {
15- MAINTAIN ,
16- INCREASE ,
17- DECREASE ,
18- }
14+ public enum TabType {
15+ MAINTAIN ,
16+ INCREASE ,
17+ DECREASE ,
18+ }
1919
20- public String ? Language ;
21- public Dictionary < Byte , String > Literals = [ ] ;
22- public StringBuilder Result = new ( ) ;
23- public UInt16 TabCount ;
24- public String TabString {
25- get {
26- return new String ( ' \t ' , TabCount ) ;
27- }
28- }
20+ private String ? language ;
21+ public String ? Language {
22+ get { return language ; }
23+ set { language = value ; }
24+ }
25+ private Dictionary < Byte , String > literals = [ ] ;
26+ public Dictionary < Byte , String > Literals {
27+ get { return literals ; }
28+ }
2929
30- public SyntacticGenerator WriteLine ( Byte literal , TabType tabType = TabType . MAINTAIN ) {
31- ArgumentNullException . ThrowIfNull (
32- Literals [ literal ] , nameof ( literal ) ) ;
33- Result . Append ( TabString + Literals [ literal ] + "\n " ) ;
34- switch ( tabType ) {
35- case TabType . MAINTAIN :
36- break ;
37- case TabType . INCREASE :
38- TabCount ++ ;
39- break ;
40- case TabType . DECREASE :
41- TabCount -- ;
42- break ;
43- }
44- return this ;
45- }
30+ private StringBuilder result = new ( ) ;
31+ public StringBuilder Result {
32+ get { return result ; }
33+ set { result = value ; }
34+ }
4635
47- /// <summary>
48- /// Writes the given <c>Literal</c> to the <see cref="StringBuilder"/>.
49- /// </summary>
50- /// <returns><c>this</c> instance, for consecutive calls.</returns>
51- public SyntacticGenerator Write ( Byte literal , Boolean putTab = false , TabType tabType = TabType . MAINTAIN ) {
52- ArgumentNullException . ThrowIfNull (
53- Literals [ literal ] , nameof ( literal ) ) ;
54- Result . Append ( ( putTab ? TabString : "" ) + Literals [ literal ] ) ;
55- switch ( tabType ) {
56- case TabType . MAINTAIN :
57- break ;
58- case TabType . INCREASE :
59- TabCount ++ ;
60- break ;
61- case TabType . DECREASE :
62- TabCount -- ;
63- break ;
64- }
65- return this ;
66- }
36+ private UInt16 tabCount ;
37+ public UInt16 TabCount {
38+ get { return tabCount ; }
39+ set { tabCount = value ; }
40+ }
41+ public String TabString {
42+ get {
43+ return new String ( '\t ' , TabCount ) ;
44+ }
45+ }
6746
68- /// <summary>
69- /// Writes the given <see cref="String"/> to the <see cref="StringBuilder"/>.
70- /// </summary>
71- /// <returns><c>this</c> instance, for consecutive calls.</returns>
72- public SyntacticGenerator Write ( String data , Boolean putTab = false , TabType tabType = TabType . MAINTAIN ) {
73- Result . Append ( ( putTab ? TabString : "" ) + data ) ;
74- switch ( tabType ) {
75- case TabType . MAINTAIN :
76- break ;
77- case TabType . INCREASE :
78- TabCount ++ ;
79- break ;
80- case TabType . DECREASE :
81- TabCount -- ;
82- break ;
83- }
84- return this ;
85- }
47+ public SyntacticGenerator WriteLine (
48+ Byte literal ,
49+ TabType tabType = TabType . MAINTAIN
50+ ) {
51+ ArgumentNullException . ThrowIfNull (
52+ Literals [ literal ] , nameof ( literal ) ) ;
53+ Result . Append ( TabString + Literals [ literal ] + "\n " ) ;
54+ switch ( tabType ) {
55+ case TabType . MAINTAIN :
56+ break ;
57+ case TabType . INCREASE :
58+ TabCount ++ ;
59+ break ;
60+ case TabType . DECREASE :
61+ TabCount -- ;
62+ break ;
63+ }
64+ return this ;
65+ }
8666
87- /// <inheritdoc/>
88- public override String ToString ( ) {
89- return Result . ToString ( ) ;
90- }
67+ /// <summary>
68+ /// Writes the given <c>Literal</c> to the <see cref="StringBuilder"/>.
69+ /// </summary>
70+ /// <returns><c>this</c> instance, for consecutive calls.</returns>
71+ public SyntacticGenerator Write (
72+ Byte literal ,
73+ Boolean putTab = false ,
74+ TabType tabType = TabType . MAINTAIN
75+ ) {
76+ ArgumentNullException . ThrowIfNull (
77+ Literals [ literal ] , nameof ( literal ) ) ;
78+ Result . Append ( ( putTab ? TabString : "" ) + Literals [ literal ] ) ;
79+ switch ( tabType ) {
80+ case TabType . MAINTAIN :
81+ break ;
82+ case TabType . INCREASE :
83+ TabCount ++ ;
84+ break ;
85+ case TabType . DECREASE :
86+ TabCount -- ;
87+ break ;
88+ }
89+ return this ;
90+ }
91+
92+ /// <summary>
93+ /// Writes the given <see cref="String"/> to the <see cref="StringBuilder"/>.
94+ /// </summary>
95+ /// <returns><c>this</c> instance, for consecutive calls.</returns>
96+ public SyntacticGenerator Write (
97+ String data ,
98+ Boolean putTab = false ,
99+ TabType tabType = TabType . MAINTAIN
100+ ) {
101+ Result . Append ( ( putTab ? TabString : "" ) + data ) ;
102+ switch ( tabType ) {
103+ case TabType . MAINTAIN :
104+ break ;
105+ case TabType . INCREASE :
106+ TabCount ++ ;
107+ break ;
108+ case TabType . DECREASE :
109+ TabCount -- ;
110+ break ;
111+ }
112+ return this ;
113+ }
114+
115+ /// <inheritdoc/>
116+ public override String ToString ( ) {
117+ return Result . ToString ( ) ;
118+ }
91119}
0 commit comments