public static IDLMemberAnnotationArray ToAnnotationArray(this IDLParserToken p) { var a = new IDLMemberAnnotationArray(); a.Symbols.Item1 = p.AssertSymbol("["); // multiple constructors a.Symbols.Item2 = p.UntilSelected( pp => { if (pp.Text == "]") { return(pp); } if (a.Items.Count > 0) { pp = pp.AssertSymbol(","); } var Constructor = new IDLMemberAnnotation { Keyword = pp.SkipTo(), //.AssertName("Constructor"), }; Constructor.Keyword.SkipTo().With( Item1 => { if (Item1.Text != "(") { return; } Constructor.ParameterSymbols.Item1 = Item1; ToParameters(Constructor.Parameters, Constructor.ParameterSymbols); } ); a.Items.Add(Constructor); return(Constructor.Terminator.SkipTo()); } ).AssertSymbol("]"); return(a); }
public static IDLMemberAnnotationArray ToAnnotationArray(this IDLParserToken p) { var a = new IDLMemberAnnotationArray(); a.Symbols.Item1 = p.AssertSymbol("["); // multiple constructors a.Symbols.Item2 = p.UntilSelected( pp => { if (pp.Text == "]") return pp; if (a.Items.Count > 0) { pp = pp.AssertSymbol(","); } var Constructor = new IDLMemberAnnotation { Keyword = pp.SkipTo(), //.AssertName("Constructor"), }; Constructor.Keyword.SkipTo().With( Item1 => { if (Item1.Text != "(") return; Constructor.ParameterSymbols.Item1 = Item1; ToParameters(Constructor.Parameters, Constructor.ParameterSymbols); } ); a.Items.Add(Constructor); return Constructor.Terminator.SkipTo(); } ).AssertSymbol("]"); return a; }
public static IDLModule ToModule(IDLParserToken source) { // what are we looking at? // at first we are looking at zero length empty token var GlobalModule = new IDLModule(); var ScanModuleMember = default(Func<IDLParserToken, IDLModule, IDLParserToken>); ScanModuleMember = (p, module) => { if (p == null) return p; #region module if (p.Text == "module") { // nested modules? var NestedModule = new IDLModule(); module.NestedModules.Add(NestedModule); NestedModule.Keyword = p; NestedModule.Name = p.SkipTo().AssertName(); NestedModule.ModuleBody.Item1 = NestedModule.Name.SkipTo().AssertSymbol("{"); NestedModule.ModuleBody.Item2 = NestedModule.ModuleBody.Item1.SkipTo().UntilSelected( pp => { if (pp.Text == "}") return pp; return ScanModuleMember(pp, NestedModule); } ).AssertSymbol("}"); return NestedModule.ModuleBody.Item2.SkipTo(); } #endregion #region typedef if (p.Text == "typedef") { var typedef = new IDLTypeDefinition { DeclaringModule = module, Keyword = p, Type = p.SkipTo().ToTypeReference() }; typedef.Name = typedef.Type.Terminator.SkipTo().AssertName(); typedef.Terminator = typedef.Name.SkipTo().AssertSymbol(";"); module.TypeDefinitions.Add(typedef); p = typedef.Terminator.SkipTo(); return p; } #endregion #region Constructors var AnnotationArray = new IDLMemberAnnotationArray(); if (p.Text == "[") { AnnotationArray = p.ToAnnotationArray(); p = AnnotationArray.Symbols.Item2.SkipTo(); } #endregion #region static var KeywordStatic = default(IDLParserToken); if (p.Text == "static") { KeywordStatic = p; p = p.SkipTo(); } #endregion #region interface if (p.Text == "interface") { var i = ToInterface(p); // where are we rendering the IL? i.KeywordStatic = KeywordStatic; i.Members.AddRange(AnnotationArray.Items); module.Interfaces.Add(i); p = i.Terminator.SkipTo(); return p; } #endregion return p; }; // we expect module or later an interface... var EOF = source.SkipTo().UntilSelected( p => { return ScanModuleMember(p, GlobalModule); } ); // retry? //Debugger.Break(); // typedef? // interface? // end of body? return GlobalModule; }
public static IDLModule ToModule(IDLParserToken source) { // what are we looking at? // at first we are looking at zero length empty token var GlobalModule = new IDLModule(); var ScanModuleMember = default(Func <IDLParserToken, IDLModule, IDLParserToken>); ScanModuleMember = (p, module) => { if (p == null) { return(p); } #region module if (p.Text == "module") { // nested modules? var NestedModule = new IDLModule(); module.NestedModules.Add(NestedModule); NestedModule.Keyword = p; NestedModule.Name = p.SkipTo().AssertName(); NestedModule.ModuleBody.Item1 = NestedModule.Name.SkipTo().AssertSymbol("{"); NestedModule.ModuleBody.Item2 = NestedModule.ModuleBody.Item1.SkipTo().UntilSelected( pp => { if (pp.Text == "}") { return(pp); } return(ScanModuleMember(pp, NestedModule)); } ).AssertSymbol("}"); return(NestedModule.ModuleBody.Item2.SkipTo()); } #endregion #region typedef if (p.Text == "typedef") { var typedef = new IDLTypeDefinition { DeclaringModule = module, Keyword = p, Type = p.SkipTo().ToTypeReference() }; typedef.Name = typedef.Type.Terminator.SkipTo().AssertName(); typedef.Terminator = typedef.Name.SkipTo().AssertSymbol(";"); module.TypeDefinitions.Add(typedef); p = typedef.Terminator.SkipTo(); return(p); } #endregion #region Constructors var AnnotationArray = new IDLMemberAnnotationArray(); if (p.Text == "[") { AnnotationArray = p.ToAnnotationArray(); p = AnnotationArray.Symbols.Item2.SkipTo(); } #endregion #region static var KeywordStatic = default(IDLParserToken); if (p.Text == "static") { KeywordStatic = p; p = p.SkipTo(); } #endregion #region interface if (p.Text == "interface") { var i = ToInterface(p); // where are we rendering the IL? i.KeywordStatic = KeywordStatic; i.Members.AddRange(AnnotationArray.Items); module.Interfaces.Add(i); p = i.Terminator.SkipTo(); return(p); } #endregion return(p); }; // we expect module or later an interface... var EOF = source.SkipTo().UntilSelected( p => { return(ScanModuleMember(p, GlobalModule)); } ); // retry? //Debugger.Break(); // typedef? // interface? // end of body? return(GlobalModule); }