📄 cs-parser.jay
字号:
Lexer.doc_state = XmlCommentState.Allowed; } ;opt_error_modifier : /* empty */ | modifiers { int m = (int) $1; int i = 1; while (m != 0){ if ((i & m) != 0){ Report.Error (1585, lexer.Location, "Member modifier `{0}' must precede the member type and name", Modifiers.Name (i)); } m &= ~i; i = i << 1; } } ;method_header : opt_attributes opt_modifiers type namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS { MemberName name = (MemberName) $4; Method method = new Method (current_class, (Expression) $3, (int) $2, false, name, (Parameters) $6, (Attributes) $1); current_local_parameters = (Parameters) $6; if (RootContext.Documentation != null) method.DocComment = Lexer.consume_doc_comment (); $$ = method; } | opt_attributes opt_modifiers VOID namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS { MemberName name = (MemberName) $4; Method method = new Method (current_class, TypeManager.system_void_expr, (int) $2, false, name, (Parameters) $6, (Attributes) $1); current_local_parameters = (Parameters) $6; if (RootContext.Documentation != null) method.DocComment = Lexer.consume_doc_comment (); $$ = method; } | opt_attributes opt_modifiers type modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS { MemberName name = (MemberName) $5; Report.Error (1585, name.Location, "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4)); Method method = new Method (current_class, TypeManager.system_void_expr, 0, false, name, (Parameters) $7, (Attributes) $1); current_local_parameters = (Parameters) $7; if (RootContext.Documentation != null) method.DocComment = Lexer.consume_doc_comment (); $$ = null; } ;method_body : block | SEMICOLON { $$ = null; } ;opt_formal_parameter_list : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; } | formal_parameter_list ;formal_parameter_list : fixed_parameters { ArrayList pars_list = (ArrayList) $1; Parameter [] pars = new Parameter [pars_list.Count]; pars_list.CopyTo (pars); $$ = new Parameters (pars, null); } | fixed_parameters COMMA parameter_array { ArrayList pars_list = (ArrayList) $1; Parameter [] pars = new Parameter [pars_list.Count]; pars_list.CopyTo (pars); $$ = new Parameters (pars, (Parameter) $3); } | fixed_parameters COMMA ARGLIST { ArrayList pars_list = (ArrayList) $1; Parameter [] pars = new Parameter [pars_list.Count]; pars_list.CopyTo (pars); $$ = new Parameters (pars, true); } | parameter_array COMMA fixed_parameters { if ($1 != null) Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list"); $$ = null; } | ARGLIST COMMA fixed_parameters { Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list"); $$ = null; } | parameter_array { $$ = new Parameters (null, (Parameter) $1); } | ARGLIST { $$ = new Parameters (null, true); } ;fixed_parameters : fixed_parameter { ArrayList pars = new ArrayList (4); pars.Add ($1); $$ = pars; } | fixed_parameters COMMA fixed_parameter { ArrayList pars = (ArrayList) $1; pars.Add ($3); $$ = $1; } ;fixed_parameter : opt_attributes opt_parameter_modifier type IDENTIFIER { LocatedToken lt = (LocatedToken) $4; $$ = new Parameter ((Expression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location); } | opt_attributes opt_parameter_modifier type IDENTIFIER OPEN_BRACKET CLOSE_BRACKET { LocatedToken lt = (LocatedToken) $4; Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name"); $$ = null; } | opt_attributes opt_parameter_modifier type { Report.Error (1001, GetLocation ($3), "Identifier expected"); $$ = null; } | opt_attributes opt_parameter_modifier type error { CheckIdentifierToken (yyToken, GetLocation ($4)); $$ = null; } | opt_attributes opt_parameter_modifier type IDENTIFIER ASSIGN constant_expression { LocatedToken lt = (LocatedToken) $4; Report.Error (241, lt.Location, "Default parameter specifiers are not permitted"); $$ = null; } ;opt_parameter_modifier : /* empty */ { $$ = Parameter.Modifier.NONE; } | parameter_modifier ;parameter_modifier : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; } | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; } ;parameter_array : opt_attributes PARAMS type IDENTIFIER { LocatedToken lt = (LocatedToken) $4; $$ = new Parameter ((Expression) $3, lt.Value, Parameter.Modifier.PARAMS, (Attributes) $1, lt.Location); note ("type must be a single-dimension array type"); } | opt_attributes PARAMS parameter_modifier type IDENTIFIER { Report.Error (1611, (Location) $2, "The params parameter cannot be declared as ref or out"); $$ = null; } | opt_attributes PARAMS type error { CheckIdentifierToken (yyToken, GetLocation ($4)); $$ = null; } ;property_declaration : opt_attributes opt_modifiers type namespace_or_type_name { if (RootContext.Documentation != null) tmpComment = Lexer.consume_doc_comment (); } OPEN_BRACE { implicit_value_parameter_type = (Expression) $3; lexer.PropertyParsing = true; } accessor_declarations { lexer.PropertyParsing = false; has_get = has_set = false; } CLOSE_BRACE { if ($8 == null) break; Property prop; Pair pair = (Pair) $8; Accessor get_block = (Accessor) pair.First; Accessor set_block = (Accessor) pair.Second; MemberName name = (MemberName) $4; prop = new Property (current_class, (Expression) $3, (int) $2, false, name, (Attributes) $1, get_block, set_block); current_container.AddProperty (prop); implicit_value_parameter_type = null; if (RootContext.Documentation != null) prop.DocComment = ConsumeStoredComment (); } ;accessor_declarations : get_accessor_declaration { $$ = new Pair ($1, null); } | get_accessor_declaration accessor_declarations { Pair pair = (Pair) $2; pair.First = $1; $$ = pair; } | set_accessor_declaration { $$ = new Pair (null, $1); } | set_accessor_declaration accessor_declarations { Pair pair = (Pair) $2; pair.Second = $1; $$ = pair; } | error { Report.Error (1014, GetLocation ($1), "A get or set accessor expected"); $$ = null; } ;get_accessor_declaration : opt_attributes opt_modifiers GET { // If this is not the case, then current_local_parameters has already // been set in indexer_declaration if (parsing_indexer == false) current_local_parameters = null; else current_local_parameters = indexer_parameters; lexer.PropertyParsing = false; iterator_container = SimpleIteratorContainer.GetSimple (); } accessor_body { if (has_get) { Report.Error (1007, (Location) $3, "Property accessor already defined"); break; } Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3); has_get = true; current_local_parameters = null; lexer.PropertyParsing = true; if (SimpleIteratorContainer.Simple.Yields) accessor.SetYields (); iterator_container = null; if (RootContext.Documentation != null) if (Lexer.doc_state == XmlCommentState.Error) Lexer.doc_state = XmlCommentState.NotAllowed; $$ = accessor; } ;set_accessor_declaration : opt_attributes opt_modifiers SET { Parameter [] args; Parameter implicit_value_parameter = new Parameter ( implicit_value_parameter_type, "value", Parameter.Modifier.NONE, null, (Location) $3); if (parsing_indexer == false) { args = new Parameter [1]; args [0] = implicit_value_parameter; current_local_parameters = new Parameters (args, null); } else { Parameter [] fpars = indexer_parameters.FixedParameters; if (fpars != null){ int count = fpars.Length; args = new Parameter [count + 1]; fpars.CopyTo (args, 0); args [count] = implicit_value_parameter; } else args = null; current_local_parameters = new Parameters ( args, indexer_parameters.ArrayParameter); } lexer.PropertyParsing = false; iterator_container = SimpleIteratorContainer.GetSimple (); } accessor_body { if (has_set) { Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined"); break; } Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3); has_set = true; current_local_parameters = null; lexer.PropertyParsing = true; if (SimpleIteratorContainer.Simple.Yields) accessor.SetYields (); iterator_container = null; if (RootContext.Documentation != null && Lexer.doc_state == XmlCommentState.Error) Lexer.doc_state = XmlCommentState.NotAllowed; $$ = accessor; } ;accessor_body : block | SEMICOLON { $$ = null; } ;interface_declaration : opt_attributes opt_modifiers opt_partial INTERFACE member_name { MemberName name = MakeName ((MemberName) $5); if ($3 != null) { ClassPart part = PartialContainer.CreatePart ( current_namespace, current_class, name, (int) $2, (Attributes) $1, Kind.Interface, (Location) $3); current_container = part.PartialContainer; current_class = part; } else { current_class = new Interface ( current_namespace, current_class, name, (int) $2, (Attributes) $1); current_container.AddInterface (current_class); current_container = current_class; RootContext.Tree.RecordDecl (current_namespace.NS, name, current_class); } } opt_class_base { current_class.Bases = (ArrayList) $7; if (RootContext.Documentation != null) { current_class.DocComment = Lexer.consume_doc_comment (); Lexer.doc_state = XmlCommentState.Allowed; } } interface_body { if (RootContext.Documentation != null) Lexer.doc_state = XmlCommentState.Allowed; } opt_semicolon { $$ = pop_current_class (); } | opt_attributes opt_modifiers opt_partial INTERFACE error { CheckIdentifierToken (yyToken, GetLocation ($5)); } ;interface_body : OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE ;opt_interface_member_declarations : /* empty */ | interface_member_declarations ;interface_member_declarations : interface_member_declaration | interface_member_declarations interface_member_declaration ;interface_member_declaration : interface_method_declaration { if ($1 == null) break; Method m = (Method) $1; if (m.IsExplicitImpl) Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct", m.GetSignatureForError ()); current_container.AddMethod (m); if (RootContext.Documentation != null) Lexer.doc_state = XmlCommentState.Allowed; } | interface_property_declaration { if ($1 == null) break; Property p = (Property) $1; if (p.IsExplicitImpl) Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct", p.GetSignatureForError ()); current_container.AddProperty (p); if (RootContext.Documentation != null) Lexer.doc_state = XmlCommentState.Allowed; } | interface_event_declaration { if ($1 != null){ Event e = (Event) $1; if (e.IsExplicitImpl) Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct", e.GetSignatureForError ()); current_container.AddEvent (e); } if (RootContext.Documentation != null) Lexer.doc_state = XmlCommentState.Allowed; } | interface_indexer_declaration { if ($1 == null) break; Indexer i = (Indexer) $1; if (i.IsExplicitImpl) Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct", i.GetSignatureForError ()); current_container.AddIndexer (i); if (RootContext.Documentation != null) Lexer.doc_state = XmlCommentState.Allowed; } | delegate_declaration
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -