Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
TokenFilter.cs
Go to the documentation of this file.
1 #region License
2 /* **********************************************************************************
3  * Copyright (c) Roman Ivantsov
4  * This source code is subject to terms and conditions of the MIT License
5  * for Irony. A copy of the license can be found in the License.txt file
6  * at the root of this distribution.
7  * By using this source code in any fashion, you are agreeing to be bound by the terms of the
8  * MIT License.
9  * You must not remove this notice from this software.
10  * **********************************************************************************/
11 #endregion
12 
13 using System;
14 using System.Collections.Generic;
15 using System.Text;
16 
17 namespace Irony.Parsing {
18 
19  #region Comments
20  // Token filter is a token preprocessor that operates on a token stream between scanner and parser:
21  // scanner -> (token filters)-> parser
22  // Token stream from scanner output is fed into a chain of token filters that add/remove/modify tokens
23  // in the stream before it gets to the parser. Some tasks that come up in scanning and parsing are best
24  // handled by such an intermediate processor. Examples:
25  // * Macro expansion
26  // * Conditional compilation clauses
27  // * Handling commented-out blocks. Scheme allows commenting out entire blocks of code using "#;" prefix followed by
28  // well-formed datum. This type of comments cannot be handled by scanner as it requires parser-like processing
29  // of the stream to locate the end of the block. At the same time parser is not a good place to handle this either,
30  // as it would require defining optional "commented block" element everywhere in the grammar.
31  // Token filter is an ideal place for implementing this task - after scanning but before parsing.
32  // * Assembling doc-comment blocks (XML doc lines in c#) from individual comment lines
33  // and attaching it to the next content token, and later sticking it to the parsed node.
34  // * Handling newlines, indents and unindents for languages like Python.
35  // Tracking this information directly in the scanner makes things really messy, and it does not fit well
36  // into general-purpose scanner. Token filter can handle it easily. In this case the scanner
37  // handles the new-line character and indentations as whitespace and simply ignores it.
38  // The CodeOutlineFilter re-creates new-line and indent tokens by analyzing
39  // the line/column properties of the incoming tokens, and inserts them into its output.
40  #endregion
41  public class TokenFilter {
42 
44  yield break;
45  }
46 
47  public virtual void Reset() {
48  }
49  protected internal virtual void OnSetSourceLocation(SourceLocation location) {
50  }
51  }//class
52 
53  public class TokenFilterList : List<TokenFilter> { }
54 
55 }//namespace
virtual void Reset()
Definition: TokenFilter.cs:47
virtual IEnumerable< Token > BeginFiltering(ParsingContext context, IEnumerable< Token > tokens)
Definition: TokenFilter.cs:43