private static IDLInterface ToInterface(IDLParserToken p) { var i = new IDLInterface { Keyword = p, Name = p.SkipTo().AssertName() }; var ppp = i.Name.SkipTo().UntilSelected( pp => { // what if javascript library wants to use nested types? // tested by: X:\jsc.svn\examples\javascript\WebGLCannonPhysicsEngine\WebGLCannonPhysicsEngine\Application.cs while (pp.Text == ".") { var NameFragment = pp.SkipTo().AssertName(); i.Name = new[] { i.Name, pp, NameFragment }.Combine(); pp = i.Name.SkipTo(); } #region BaseType if (pp.Text == ":") { i.BaseType = pp.SkipTo().AssertName(); pp = i.BaseType.SkipTo(); while (pp.Text == ".") { var NameFragment = pp.SkipTo().AssertName(); i.BaseType = new[] { i.BaseType, pp, NameFragment }.Combine(); pp = i.Name.SkipTo(); } } #endregion // tested by? #region generic definition if (pp.Text == "<") { i.GenericDefinitionParameterSymbols.Item1 = pp; i.GenericDefinitionParameterSymbols.Item2 = i.GenericDefinitionParameterSymbols.Item1.UntilSelected( ipp => { if (ipp.Text != ">") { if (i.GenericDefinitionParameters.Count > 0) { ipp.AssertSymbol(","); } var rr = ToTypeReference(ipp.SkipTo()); i.GenericDefinitionParameters.Add(rr); return rr.Terminator.SkipTo(); } return ipp; } ).AssertSymbol(">"); pp = i.GenericDefinitionParameterSymbols.Item2.SkipTo(); } #endregion return pp; } ); if (ppp.Text == ";") { // interface done without body, non members, perhaps only primary constructor? i.Terminator = ppp; } else { #region InterfaceBody i.InterfaceBody.Item1 = ppp.AssertSymbol("{"); i.InterfaceBody.Item2 = i.InterfaceBody.Item1.SkipTo().UntilSelected( pp => { if (pp.Text == "}") return pp; // used by? #region const if (pp.Text == "const") { // can we also initiaize optional params? var Constant = new IDLMemberConstant { Keyword = pp, Type = pp.SkipTo().ToTypeReference(), }; Constant.Name = Constant.Type.Terminator.SkipTo().AssertName(); Constant.KeywordAssignment = Constant.Name.SkipTo().AssertSymbol("="); Constant.Value = Constant.KeywordAssignment.SkipTo().ToNumericLiteral(); Constant.Terminator = Constant.Value.Terminator.SkipTo().AssertSymbol(";"); // 0x00 ? i.Members.Add(Constant); return Constant.Terminator.SkipTo(); } #endregion var KeywordReadOnly = default(IDLParserToken); var KeywordDeleter = default(IDLParserToken); var Keyword_stringifier = default(IDLParserToken); // keywords may be in any order, retry for now... for (int xi = 0; xi < 3; xi++) { #region readonly if (pp.Text == "readonly") { KeywordReadOnly = pp; pp = pp.SkipTo(); } #endregion #region deleter if (pp.Text == "deleter") { KeywordDeleter = pp; pp = pp.SkipTo(); } #endregion #region stringifier if (pp.Text == "stringifier") { Keyword_stringifier = pp; pp = pp.SkipTo(); } #endregion } #region AnnotationArray var AnnotationArray = default(IDLMemberAnnotationArray); if (pp.Text == "[") { AnnotationArray = pp.ToAnnotationArray(); pp = AnnotationArray.Symbols.Item2.SkipTo(); } #endregion #region async var KeywordAsync = default(IDLParserToken); if (pp.Text == "async") { KeywordAsync = pp; pp = pp.SkipTo(); } #endregion #region event var KeywordEvent = default(IDLParserToken); if (pp.Text == "event") { KeywordEvent = pp; pp = pp.SkipTo(); } #endregion #region static var KeywordStatic = default(IDLParserToken); if (pp.Text == "static") { KeywordStatic = pp; pp = pp.SkipTo(); } #endregion #region extension var KeywordExtension = default(IDLParserToken); if (pp.Text == "extension") { KeywordExtension = pp; pp = pp.SkipTo(); } #endregion #region attribute if (pp.Text == "attribute") { var Keyword = pp; if (pp.SkipTo().Text == "[") { AnnotationArray = pp.SkipTo().ToAnnotationArray(); pp = AnnotationArray.Symbols.Item2; } var a = new IDLMemberAttribute { KeywordEvent = KeywordEvent, KeywordStatic = KeywordStatic, KeywordReadOnly = KeywordReadOnly, Keyword = Keyword, Annotations = AnnotationArray, Type = ToTypeReference(pp.SkipTo()), }; a.Name = a.Type.Terminator.SkipTo(); a.Terminator = a.Name.SkipTo().AssertSymbol(";"); i.Members.Add(a); return a.Terminator.SkipTo(); } #endregion #region omittable var __omittable = default(IDLParserToken); if (pp.Text == "omittable") { __omittable = pp; pp = pp.SkipTo(); } #endregion #region getter var KeywordGetter = default(IDLParserToken); if (pp.Text == "getter") { KeywordGetter = pp; pp = pp.SkipTo(); } #endregion #region setter var KeywordSetter = default(IDLParserToken); if (pp.Text == "setter") { KeywordSetter = pp; pp = pp.SkipTo(); } #endregion #region creator var KeywordCreator = default(IDLParserToken); if (pp.Text == "creator") { KeywordCreator = pp; pp = pp.SkipTo(); } #endregion // method!! var Method = ToMemberMethod( pp, KeywordGetter, KeywordSetter, KeywordDeleter, KeywordStatic, KeywordAsync, KeywordExtension ); i.Members.Add(Method); return Method.Terminator.SkipTo(); } ).AssertSymbol("}"); #endregion i.Terminator = i.InterfaceBody.Item2.SkipTo(); if (i.Terminator == null) { i.Terminator = (IDLParserToken.Literal)";"; i.Terminator.IsSymbol = true; } i.Terminator.AssertSymbol(";"); } return i; }
private static IDLInterface ToInterface(IDLParserToken p) { var i = new IDLInterface { Keyword = p, Name = p.SkipTo().AssertName() }; var ppp = i.Name.SkipTo().UntilSelected( pp => { // what if javascript library wants to use nested types? // tested by: X:\jsc.svn\examples\javascript\WebGLCannonPhysicsEngine\WebGLCannonPhysicsEngine\Application.cs while (pp.Text == ".") { var NameFragment = pp.SkipTo().AssertName(); i.Name = new[] { i.Name, pp, NameFragment }.Combine(); pp = i.Name.SkipTo(); } #region BaseType if (pp.Text == ":") { i.BaseType = pp.SkipTo().AssertName(); pp = i.BaseType.SkipTo(); while (pp.Text == ".") { var NameFragment = pp.SkipTo().AssertName(); i.BaseType = new[] { i.BaseType, pp, NameFragment }.Combine(); pp = i.Name.SkipTo(); } } #endregion // tested by? #region generic definition if (pp.Text == "<") { i.GenericDefinitionParameterSymbols.Item1 = pp; i.GenericDefinitionParameterSymbols.Item2 = i.GenericDefinitionParameterSymbols.Item1.UntilSelected( ipp => { if (ipp.Text != ">") { if (i.GenericDefinitionParameters.Count > 0) { ipp.AssertSymbol(","); } var rr = ToTypeReference(ipp.SkipTo()); i.GenericDefinitionParameters.Add(rr); return(rr.Terminator.SkipTo()); } return(ipp); } ).AssertSymbol(">"); pp = i.GenericDefinitionParameterSymbols.Item2.SkipTo(); } #endregion return(pp); } ); if (ppp.Text == ";") { // interface done without body, non members, perhaps only primary constructor? i.Terminator = ppp; } else { #region InterfaceBody i.InterfaceBody.Item1 = ppp.AssertSymbol("{"); i.InterfaceBody.Item2 = i.InterfaceBody.Item1.SkipTo().UntilSelected( pp => { if (pp.Text == "}") { return(pp); } // used by? #region const if (pp.Text == "const") { // can we also initiaize optional params? var Constant = new IDLMemberConstant { Keyword = pp, Type = pp.SkipTo().ToTypeReference(), }; Constant.Name = Constant.Type.Terminator.SkipTo().AssertName(); Constant.KeywordAssignment = Constant.Name.SkipTo().AssertSymbol("="); Constant.Value = Constant.KeywordAssignment.SkipTo().ToNumericLiteral(); Constant.Terminator = Constant.Value.Terminator.SkipTo().AssertSymbol(";"); // 0x00 ? i.Members.Add(Constant); return(Constant.Terminator.SkipTo()); } #endregion var KeywordReadOnly = default(IDLParserToken); var KeywordDeleter = default(IDLParserToken); var Keyword_stringifier = default(IDLParserToken); // keywords may be in any order, retry for now... for (int xi = 0; xi < 3; xi++) { #region readonly if (pp.Text == "readonly") { KeywordReadOnly = pp; pp = pp.SkipTo(); } #endregion #region deleter if (pp.Text == "deleter") { KeywordDeleter = pp; pp = pp.SkipTo(); } #endregion #region stringifier if (pp.Text == "stringifier") { Keyword_stringifier = pp; pp = pp.SkipTo(); } #endregion } #region AnnotationArray var AnnotationArray = default(IDLMemberAnnotationArray); if (pp.Text == "[") { AnnotationArray = pp.ToAnnotationArray(); pp = AnnotationArray.Symbols.Item2.SkipTo(); } #endregion #region async var KeywordAsync = default(IDLParserToken); if (pp.Text == "async") { KeywordAsync = pp; pp = pp.SkipTo(); } #endregion #region event var KeywordEvent = default(IDLParserToken); if (pp.Text == "event") { KeywordEvent = pp; pp = pp.SkipTo(); } #endregion #region static var KeywordStatic = default(IDLParserToken); if (pp.Text == "static") { KeywordStatic = pp; pp = pp.SkipTo(); } #endregion #region extension var KeywordExtension = default(IDLParserToken); if (pp.Text == "extension") { KeywordExtension = pp; pp = pp.SkipTo(); } #endregion #region attribute if (pp.Text == "attribute") { var Keyword = pp; if (pp.SkipTo().Text == "[") { AnnotationArray = pp.SkipTo().ToAnnotationArray(); pp = AnnotationArray.Symbols.Item2; } var a = new IDLMemberAttribute { KeywordEvent = KeywordEvent, KeywordStatic = KeywordStatic, KeywordReadOnly = KeywordReadOnly, Keyword = Keyword, Annotations = AnnotationArray, Type = ToTypeReference(pp.SkipTo()), }; a.Name = a.Type.Terminator.SkipTo(); a.Terminator = a.Name.SkipTo().AssertSymbol(";"); i.Members.Add(a); return(a.Terminator.SkipTo()); } #endregion #region omittable var __omittable = default(IDLParserToken); if (pp.Text == "omittable") { __omittable = pp; pp = pp.SkipTo(); } #endregion #region getter var KeywordGetter = default(IDLParserToken); if (pp.Text == "getter") { KeywordGetter = pp; pp = pp.SkipTo(); } #endregion #region setter var KeywordSetter = default(IDLParserToken); if (pp.Text == "setter") { KeywordSetter = pp; pp = pp.SkipTo(); } #endregion #region creator var KeywordCreator = default(IDLParserToken); if (pp.Text == "creator") { KeywordCreator = pp; pp = pp.SkipTo(); } #endregion // method!! var Method = ToMemberMethod( pp, KeywordGetter, KeywordSetter, KeywordDeleter, KeywordStatic, KeywordAsync, KeywordExtension ); i.Members.Add(Method); return(Method.Terminator.SkipTo()); } ).AssertSymbol("}"); #endregion i.Terminator = i.InterfaceBody.Item2.SkipTo(); if (i.Terminator == null) { i.Terminator = (IDLParserToken.Literal) ";"; i.Terminator.IsSymbol = true; } i.Terminator.AssertSymbol(";"); } return(i); }