@@ -89,196 +89,196 @@ private static void Main(string[] args)
8989 {
9090 try
9191 {
92- LoadApplicationSettings ( ) ;
93- Console . BackgroundColor = _Settings . EditorBackgroundColor ;
94- Console . ForegroundColor = _Settings . EditorTextColor ;
95- FillCurrentLineBackground ( ) ;
96-
97- var parser = new Parser ( with => with . HelpWriter = null ) ;
98- var parserResult = parser . ParseArguments < Options > ( args ) ;
99- parserResult
100- . WithParsed ( o =>
101- {
102- var options = Grammar . ParseOption . None ;
103- var loadGui = false ;
104- var showParseTree = false ;
105- var writeSvg = false ;
106- ISyntaxHighlightingGuide guide = null ;
107-
108- if ( o . Tokens ) options |= Grammar . ParseOption . Tokens ;
109- if ( o . Diagnostics ) options |= Grammar . ParseOption . Diagnostics ;
110- if ( o . Trace ) options |= Grammar . ParseOption . Trace ;
111- if ( o . Tree )
92+ LoadApplicationSettings ( ) ;
93+ Console . BackgroundColor = _Settings . EditorBackgroundColor ;
94+ Console . ForegroundColor = _Settings . EditorTextColor ;
95+ FillCurrentLineBackground ( ) ;
96+
97+ var parser = new Parser ( with => with . HelpWriter = null ) ;
98+ var parserResult = parser . ParseArguments < Options > ( args ) ;
99+ parserResult
100+ . WithParsed ( o =>
112101 {
113- options |= Grammar . ParseOption . Tree ;
114- showParseTree = true ;
115- }
102+ var options = Grammar . ParseOption . None ;
103+ var loadGui = false ;
104+ var showParseTree = false ;
105+ var writeSvg = false ;
106+ ISyntaxHighlightingGuide guide = null ;
107+
108+ if ( o . Tokens ) options |= Grammar . ParseOption . Tokens ;
109+ if ( o . Diagnostics ) options |= Grammar . ParseOption . Diagnostics ;
110+ if ( o . Trace ) options |= Grammar . ParseOption . Trace ;
111+ if ( o . Tree )
112+ {
113+ options |= Grammar . ParseOption . Tree ;
114+ showParseTree = true ;
115+ }
116116
117- if ( ! string . IsNullOrEmpty ( o . SvgFileName ) )
118- {
119- writeSvg = true ;
120- options |= Grammar . ParseOption . Tree ;
121- }
117+ if ( ! string . IsNullOrEmpty ( o . SvgFileName ) )
118+ {
119+ writeSvg = true ;
120+ options |= Grammar . ParseOption . Tree ;
121+ }
122122
123- if ( o . Sll ) options |= Grammar . ParseOption . Sll ;
124- if ( o . Gui )
125- {
126- loadGui = true ;
127- options |= Grammar . ParseOption . Tree ;
128- }
123+ if ( o . Sll ) options |= Grammar . ParseOption . Sll ;
124+ if ( o . Gui )
125+ {
126+ loadGui = true ;
127+ options |= Grammar . ParseOption . Tree ;
128+ }
129129
130- var workingDirectory = Environment . CurrentDirectory ;
131- var scanner = new Grammar . Scanner ( ) ;
130+ var workingDirectory = Environment . CurrentDirectory ;
131+ var scanner = new Grammar . Scanner ( ) ;
132132
133- var grammar = scanner . LocateGrammar ( workingDirectory , o . GrammarName ) ;
134- if ( grammar == null )
135- {
136- Console . WriteLine ( Resources . GrammarNotFoundErrorMessage , o . GrammarName ) ;
137- return ;
138- }
133+ var grammar = scanner . LocateGrammar ( workingDirectory , o . GrammarName ) ;
134+ if ( grammar == null )
135+ {
136+ Console . WriteLine ( Resources . GrammarNotFoundErrorMessage , o . GrammarName ) ;
137+ return ;
138+ }
139139
140- var guideResult = grammar . LoadSyntaxHighlightingGuide ( ) ;
141- guide = guideResult != null ? guideResult . Item2 : new HeuristicSyntaxHighlightingGuide ( _Settings ) ;
140+ var guideResult = grammar . LoadSyntaxHighlightingGuide ( ) ;
141+ guide = guideResult != null ? guideResult . Item2 : new HeuristicSyntaxHighlightingGuide ( _Settings ) ;
142142
143- var data = string . Empty ;
143+ var data = string . Empty ;
144144
145- if ( ! string . IsNullOrEmpty ( o . FileName ) )
146- {
147- var encodingToUse = ! string . IsNullOrEmpty ( o . EncodingName ) ? Encoding . GetEncoding ( o . EncodingName ) : Encoding . Default ;
148- using ( var reader = new StreamReader ( o . FileName , encodingToUse ) )
149- data = reader . ReadToEnd ( ) ;
150- }
151- else
152- {
153- var analyzer = new Analyzer ( ) ;
154- var builder = new StringBuilder ( ) ;
155- Console . WriteLine ( Resources . ReadingFromStandardInputPromptMessage ) ;
156- var currentLine = Console . CursorTop ;
157- var keepReading = true ;
158- while ( keepReading )
145+ if ( ! string . IsNullOrEmpty ( o . FileName ) )
159146 {
160- if ( Console . KeyAvailable )
147+ var encodingToUse = ! string . IsNullOrEmpty ( o . EncodingName ) ? Encoding . GetEncoding ( o . EncodingName ) : Encoding . Default ;
148+ using ( var reader = new StreamReader ( o . FileName , encodingToUse ) )
149+ data = reader . ReadToEnd ( ) ;
150+ }
151+ else
152+ {
153+ var analyzer = new Analyzer ( ) ;
154+ var builder = new StringBuilder ( ) ;
155+ Console . WriteLine ( Resources . ReadingFromStandardInputPromptMessage ) ;
156+ var currentLine = Console . CursorTop ;
157+ var keepReading = true ;
158+ while ( keepReading )
161159 {
162- while ( Console . KeyAvailable )
160+ if ( Console . KeyAvailable )
163161 {
164- var typed = Console . ReadKey ( true ) ;
165-
166- if ( ( typed . Modifiers & ConsoleModifiers . Control ) == ConsoleModifiers . Control
167- && typed . Key == ConsoleKey . Z )
162+ while ( Console . KeyAvailable )
168163 {
169- Console . Write ( "^Z" ) ;
170- keepReading = false ;
171- break ;
172- }
164+ var typed = Console . ReadKey ( true ) ;
173165
174- if ( typed . Key == ConsoleKey . Enter )
175- {
176- if ( Console . CursorTop == Console . BufferHeight - 1 )
177- _ScrollFadeCount ++ ;
178- Console . WriteLine ( ) ;
179- FillCurrentLineBackground ( ) ;
180- builder . Append ( "\r \n " ) ;
181- }
182- else if ( typed . Key == ConsoleKey . Tab )
183- {
184- var spaces = new string ( ' ' , _Settings . EditorTabLength ) ;
185- Console . Write ( spaces ) ;
186- builder . Append ( spaces ) ;
187- }
188- else if ( typed . Key == ConsoleKey . Backspace )
189- {
190- if ( Console . CursorLeft > 0 )
166+ if ( ( typed . Modifiers & ConsoleModifiers . Control ) == ConsoleModifiers . Control
167+ && typed . Key == ConsoleKey . Z )
168+ {
169+ Console . Write ( "^Z" ) ;
170+ keepReading = false ;
171+ break ;
172+ }
173+
174+ if ( typed . Key == ConsoleKey . Enter )
175+ {
176+ if ( Console . CursorTop == Console . BufferHeight - 1 )
177+ _ScrollFadeCount ++ ;
178+ Console . WriteLine ( ) ;
179+ FillCurrentLineBackground ( ) ;
180+ builder . Append ( "\r \n " ) ;
181+ }
182+ else if ( typed . Key == ConsoleKey . Tab )
183+ {
184+ var spaces = new string ( ' ' , _Settings . EditorTabLength ) ;
185+ Console . Write ( spaces ) ;
186+ builder . Append ( spaces ) ;
187+ }
188+ else if ( typed . Key == ConsoleKey . Backspace )
189+ {
190+ if ( Console . CursorLeft > 0 )
191+ {
192+ Console . Write ( typed . KeyChar ) ;
193+ Console . Write ( ' ' ) ;
194+ Console . Write ( typed . KeyChar ) ;
195+ builder . Remove ( builder . Length - 1 , 1 ) ;
196+ _Cache . FlushTokensForLine ( currentLine - ( _ScrollFadeCount + 1 ) ) ;
197+ }
198+ }
199+ else
191200 {
192201 Console . Write ( typed . KeyChar ) ;
193- Console . Write ( ' ' ) ;
194- Console . Write ( typed . KeyChar ) ;
195- builder . Remove ( builder . Length - 1 , 1 ) ;
196- _Cache . FlushTokensForLine ( currentLine - ( _ScrollFadeCount + 1 ) ) ;
202+ builder . Append ( typed . KeyChar ) ;
197203 }
198204 }
199- else
200- {
201- Console . Write ( typed . KeyChar ) ;
202- builder . Append ( typed . KeyChar ) ;
203- }
204- }
205205
206206 //analyzer.Tokenize(grammar, builder.ToString());
207207 //HighlightSyntaxInConsole(currentLine - (_ScrollFadeCount + 1), analyzer, guide);
208208 }
209- }
209+ }
210210
211- Console . WriteLine ( ) ;
212- data = builder . ToString ( ) ;
213- }
211+ Console . WriteLine ( ) ;
212+ data = builder . ToString ( ) ;
213+ }
214214
215215 // If tokens are the only option we've received, we don't need to parse
216216 if ( options == Grammar . ParseOption . Tokens )
217- {
218- DisplayTokens ( grammar , data ) ;
219- return ;
220- }
217+ {
218+ DisplayTokens ( grammar , data ) ;
219+ return ;
220+ }
221221
222222 // Now we attempt to parse, but still handle a lexer-only grammar.
223223 if ( grammar . Parser != null )
224- {
225- var analyzer = new Analyzer ( ) ;
226- var grammarParser = analyzer . BuildParserWithOptions ( grammar , data , options ) ;
227- analyzer . ExecuteParsing ( grammarParser , o . RuleName ) ;
224+ {
225+ var analyzer = new Analyzer ( ) ;
226+ var grammarParser = analyzer . BuildParserWithOptions ( grammar , data , options ) ;
227+ analyzer . ExecuteParsing ( grammarParser , o . RuleName ) ;
228228
229- if ( showParseTree )
230- Console . WriteLine ( analyzer . ParserContext . ToStringTree ( grammarParser ) ) ;
229+ if ( showParseTree )
230+ Console . WriteLine ( analyzer . ParserContext . ToStringTree ( grammarParser ) ) ;
231231
232- if ( writeSvg )
233- {
234- var rules = scanner . GetParserRulesForGrammarParser ( grammar . Parser ) ;
235- var grapher = new ParseTreeGrapher ( )
232+ if ( writeSvg )
236233 {
237- BackgroundColor = _Settings . GraphNodeBackgroundColor . GetMsAglColor ( ) ,
238- BorderColor = _Settings . GraphNodeBorderColor . GetMsAglColor ( ) ,
239- TextColor = _Settings . GraphNodeTextColor . GetMsAglColor ( )
240- } ;
241- var graph = grapher . CreateGraph ( analyzer . ParserContext , rules . ToList ( ) ) ;
242- graph . LayoutAlgorithmSettings = new SugiyamaLayoutSettings ( ) ;
243- GraphRenderer renderer = new GraphRenderer ( graph ) ;
244- renderer . CalculateLayout ( ) ;
245- graph . EscapeNodesForSvg ( ) ;
246- SvgGraphWriter . Write ( graph , o . SvgFileName , null , null , 4 ) ;
234+ var rules = scanner . GetParserRulesForGrammarParser ( grammar . Parser ) ;
235+ var grapher = new ParseTreeGrapher ( )
236+ {
237+ BackgroundColor = _Settings . GraphNodeBackgroundColor . GetMsAglColor ( ) ,
238+ BorderColor = _Settings . GraphNodeBorderColor . GetMsAglColor ( ) ,
239+ TextColor = _Settings . GraphNodeTextColor . GetMsAglColor ( )
240+ } ;
241+ var graph = grapher . CreateGraph ( analyzer . ParserContext , rules . ToList ( ) ) ;
242+ graph . LayoutAlgorithmSettings = new SugiyamaLayoutSettings ( ) ;
243+ GraphRenderer renderer = new GraphRenderer ( graph ) ;
244+ renderer . CalculateLayout ( ) ;
245+ graph . EscapeNodesForSvg ( ) ;
246+ SvgGraphWriter . Write ( graph , o . SvgFileName , null , null , 4 ) ;
247+ }
248+ }
249+ else
250+ {
251+ if ( options . HasFlag ( ParseOption . Tokens ) )
252+ DisplayTokens ( grammar , data ) ;
253+
254+ if ( showParseTree || writeSvg )
255+ Console . WriteLine ( Resources . GrammarHasNoParserErrorMessage , grammar . GrammarName ) ;
256+ if ( showParseTree )
257+ Console . WriteLine ( Resources . UnableToDisplayParseTree ) ;
258+ if ( writeSvg )
259+ Console . WriteLine ( Resources . SvgWritingAbortedErrorMessage ) ;
247260 }
248- }
249- else
250- {
251- if ( options . HasFlag ( ParseOption . Tokens ) )
252- DisplayTokens ( grammar , data ) ;
253-
254- if ( showParseTree || writeSvg )
255- Console . WriteLine ( Resources . GrammarHasNoParserErrorMessage , grammar . GrammarName ) ;
256- if ( showParseTree )
257- Console . WriteLine ( Resources . UnableToDisplayParseTree ) ;
258- if ( writeSvg )
259- Console . WriteLine ( Resources . SvgWritingAbortedErrorMessage ) ;
260- }
261261
262- if ( loadGui )
263- LoadGui ( data , grammar , o . RuleName ) ;
264- } )
265- . WithNotParsed ( errs => DisplayHelp ( parserResult , errs ) ) ;
262+ if ( loadGui )
263+ LoadGui ( data , grammar , o . RuleName ) ;
264+ } )
265+ . WithNotParsed ( errs => DisplayHelp ( parserResult , errs ) ) ;
266266
267267#if DEBUG
268- Console . WriteLine ( Resources . PressAnyKeyMessage ) ;
269- Console . ReadKey ( ) ;
268+ Console . WriteLine ( Resources . PressAnyKeyMessage ) ;
269+ Console . ReadKey ( ) ;
270270#endif
271- }
272- // ReSharper disable once CatchAllClause
273- catch ( Exception ex )
274- {
275- Console . WriteLine ( ex . Message ) ;
276- Console . WriteLine ( ex . StackTrace ) ;
277- #if DEBUG
278- Console . WriteLine ( Resources . PressAnyKeyMessage ) ;
279- Console . ReadKey ( ) ;
280- #endif
281- }
271+ }
272+ // ReSharper disable once CatchAllClause
273+ catch ( Exception ex )
274+ {
275+ Console . WriteLine ( ex . Message ) ;
276+ Console . WriteLine ( ex . StackTrace ) ;
277+ #if DEBUG
278+ Console . WriteLine ( Resources . PressAnyKeyMessage ) ;
279+ Console . ReadKey ( ) ;
280+ #endif
281+ }
282282 }
283283
284284 private static void HighlightSyntaxInConsole ( int lineOffset , Analyzer analyzer , ISyntaxHighlightingGuide guide )
0 commit comments