def p_fieldsetdef_simple(p): r"""fieldsetdef : modifiers FIELDSET NAME typedef SEMICOLON""" items = [] if p[4]: ancprop = ast.YASDLProperty('ancestors', p[4]) ancprop.lineno = p.lineno(2) ancprop.colno = lex.find_column_by_lexpos(p.lexpos(2)) items.append(ancprop) fs = p[0] = ast.YASDLFieldSet(p[3], items) fs.lineno = p.lineno(2) fs.colno = lex.find_column_by_lexpos(p.lexpos(2)) fs.modifiers[:] = p[1]
def p_fielddef_simple(p): r"""fielddef : modifiers FIELD NAME typedef fieldprops""" items = p[5] if p[4]: ancprop = ast.YASDLProperty('ancestors', p[4]) ancprop.lineno = p.lineno(2) ancprop.colno = lex.find_column_by_lexpos(p.lexpos(2)) items.append(ancprop) f = p[0] = ast.YASDLField(p[3], items) f.lineno = p.lineno(2) f.colno = lex.find_column_by_lexpos(p.lexpos(2)) f.modifiers[:] = p[1]
def p_fieldsetdef_complex(p): r"""fieldsetdef : modifiers FIELDSET NAME typedef LBRACE fsitems RBRACE """ items = p[6] if p[4]: ancprop = ast.YASDLProperty('ancestors', p[4]) ancprop.lineno = p.lineno(2) ancprop.colno = lex.find_column_by_lexpos(p.lexpos(2)) items.append(ancprop) p[0] = ast.YASDLFieldSet(p[3], items) p[0].lineno = p.lineno(2) p[0].colno = lex.find_column_by_lexpos(p.lexpos(2)) p[0].modifiers[:] = p[1]
def p_schema_package_name(p): r"""schema_name : NAME DOT schema_name""" p[0] = ast.dotted_name(p[1] + "." + p[3]) p[0].lineno = p.lineno(1) p[0].colno = lex.find_column_by_lexpos(p.lexpos(1)) p[0].min_classes = None p[0].absolute = False
def p_dotted_name_dotted_name(p): r"""simple_dotted_name : NAME DOT simple_dotted_name""" p[0] = ast.dotted_name(p[1] + "." + p[3]) p[0].lineno = p.lineno(1) p[0].colno = lex.find_column_by_lexpos(p.lexpos(1)) p[0].min_classes = p[3].min_classes p[0].absolute = False
def p_schema_simple_name(p): r"""schema_name : NAME""" p[0] = ast.dotted_name(p[1]) p[0].lineno = p.lineno(1) p[0].colno = lex.find_column_by_lexpos(p.lexpos(1)) p[0].min_classes = None p[0].absolute = False
def p_use(p): r"""use : USE NAME SEMICOLON | REQUIRE NAME SEMICOLON""" use = ast.YASDLUse(p[2]) if p[1] == 'require': use.modifiers.append('required') use.lineno = p.lineno(1) use.colno = lex.find_column_by_lexpos(p.lexpos(1)) p[0] = [use]
def p_fielddef_ref(p): r"""fielddef : modifiers FIELD NAME typedef ARROW imp_name fieldprops""" items = p[7] if p[4]: ancprop = ast.YASDLProperty('ancestors', p[4]) ancprop.lineno = p.lineno(2) ancprop.colno = lex.find_column_by_lexpos(p.lexpos(2)) items.append(ancprop) if p[6]: refprop = ast.YASDLProperty('references', [p[6]]) refprop.lineno = p[6].lineno # This is a real hack - need colum position of a symbol instead of a token. refprop.colno = p.slice[6].value.colno #refprop.colno = lex.find_column_by_lexpos(p.lexpos(6)) items.append(refprop) p[0] = ast.YASDLField(p[3], items) # Add identifier type here??? p[0].lineno = p.lineno(2) p[0].colno = lex.find_column_by_lexpos(p.lexpos(2)) p[0].modifiers[:] = p[1]
def p_dotted_name_name(p): r"""simple_dotted_name : NAME min_classes""" p[0] = ast.dotted_name(p[1]) p[0].lineno = p.lineno(1) p[0].colno = lex.find_column_by_lexpos(p.lexpos(1)) if p[2]: p[0].min_classes = set(p[2]) else: p[0].min_classes = None p[0].absolute = False
def p_use_as(p): r"""use : USE schema_name AS NAME SEMICOLON | REQUIRE schema_name AS NAME SEMICOLON | USE STRING AS NAME SEMICOLON | REQUIRE STRING AS NAME SEMICOLON """ use = ast.YASDLUse(p[2], p[4]) if p[1] == 'require': use.modifiers.append('required') use.lineno = p.lineno(1) use.colno = lex.find_column_by_lexpos(p.lexpos(1)) p[0] = [use]
def p_deletion(p): r"""deletion : DELETE NAME SEMICOLON""" p[0] = ast.YASDLDeletion(p[2]) p[0].lineno = p.lineno(1) p[0].colno = lex.find_column_by_lexpos(p.lexpos(1))
def p_yasd(p): r"""yasd : SCHEMA schema_name LBRACE uses defs RBRACE """ p[0] = ast.YASDLSchema(p[2], p[4], p[5]) p[0].lineno = p.lineno(1) p[0].colno = lex.find_column_by_lexpos(p.lexpos(1))
def p_idxfield_desc(p): r"""idxfield : MINUS dotted_name""" p[0] = p[2] p[0].direction = "desc" p[0].lineno = p.lineno(1) p[0].colno = lex.find_column_by_lexpos(p.lexpos(1))
def p_simpleprop_fields(p): r"""simpleprop : FIELDS idxfields SEMICOLON""" p[0] = ast.YASDLProperty(p[1], p[2]) p[0].lineno = p.lineno(1) p[0].colno = lex.find_column_by_lexpos(p.lexpos(1))
def p_simpleprop_one(p): r"""simpleprop : NAME propvalues SEMICOLON""" p[0] = ast.YASDLProperty(p[1], p[2]) p[0].lineno = p.lineno(1) p[0].colno = lex.find_column_by_lexpos(p.lexpos(1))
def p_dotted_name_absolute_1(p): r"""dotted_name : SCHEMA DOT simple_dotted_name""" p[0] = p[3] p[0].lineno = p.lineno(1) p[0].colno = lex.find_column_by_lexpos(p.lexpos(1)) p[0].absolute = True
def p_indexdef_simple(p): r"""indexdef : INDEX NAME indexprops""" items = p[3] i = p[0] = ast.YASDLIndex(p[2], items) i.lineno = p.lineno(1) i.colno = lex.find_column_by_lexpos(p.lexpos(1))
def p_constraintdef(p): r"""indexdef : CONSTRAINT NAME LBRACE constraintitems RBRACE """ items = p[4] p[0] = ast.YASDLConstraint(p[2], items) p[0].lineno = p.lineno(1) p[0].colno = lex.find_column_by_lexpos(p.lexpos(1))
def p_indexdef(p): r"""indexdef : INDEX NAME LBRACE idxitems RBRACE """ items = p[4] p[0] = ast.YASDLIndex(p[2], items) p[0].lineno = p.lineno(1) p[0].colno = lex.find_column_by_lexpos(p.lexpos(1))