normalizer

package
v2.8.3+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2019 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Annotations = []Mapping{}/* 123 elements not displayed */
View Source
var Code = []CodeTransformer{
	positioner.FromLineCol(),
}
View Source
var Native = Transformers([][]Transformer{
	{
		ResponseMetadata{
			TopLevelIsRootNode: false,
		},
	},
	{Mappings(Annotations...)},
	{RolesDedup()},
}...)
View Source
var Normalize = Transformers([][]Transformer{
	{Mappings(Normalizers...)},
}...)
View Source
var Normalizers = []Mapping{

	Map(
		Part("_", Fields{
			{Name: uast.KeyType, Op: String("Name")},
			{Name: uast.KeyPos, Op: Var("pos_")},
			{Name: "id", Op: Var("id")},
			{Name: "noops_previous", Optional: "np_opt", Op: Var("noops_previous")},
			{Name: "noops_sameline", Optional: "ns_opt", Op: Var("noops_sameline")},
		}),
		Part("_", Fields{
			{Name: uast.KeyType, Op: String("BoxedName")},
			{Name: "boxed_value", Op: UASTType(uast.Identifier{}, Obj{
				uast.KeyPos: Var("pos_"),
				"Name":      Var("id"),
			})},
			{Name: "noops_previous", Optional: "np_opt", Op: Var("noops_previous")},
			{Name: "noops_sameline", Optional: "ns_opt", Op: Var("noops_sameline")},
		}),
	),

	Map(
		Part("_", Fields{
			{Name: uast.KeyType, Op: String("BoolLiteral")},
			{Name: uast.KeyPos, Op: Var("pos_")},
			{Name: "value", Op: Var("lv")},
			{Name: "noops_previous", Optional: "np_opt", Op: Var("noops_previous")},
			{Name: "noops_sameline", Optional: "ns_opt", Op: Var("noops_sameline")},
		}),
		Part("_", Fields{
			{Name: uast.KeyType, Op: String("BoxedBoolLiteral")},
			{Name: "boxed_value", Op: UASTType(uast.Bool{}, Obj{
				uast.KeyPos: Var("pos_"),
				"Value":     Var("lv"),
			})},
			{Name: "noops_previous", Optional: "np_opt", Op: Var("noops_previous")},
			{Name: "noops_sameline", Optional: "ns_opt", Op: Var("noops_sameline")},
		}),
	),

	Map(
		Part("_", Fields{
			{Name: uast.KeyType, Op: String("Attribute")},
			{Name: uast.KeyPos, Op: Var("pos_")},
			{Name: "attr", Op: Var("aname")},

			{Name: "ctx", Op: Any()},
			{Name: "noops_previous", Optional: "np_opt", Op: Var("noops_previous")},
			{Name: "noops_sameline", Optional: "ns_opt", Op: Var("noops_sameline")},
		}),
		Part("_", Fields{
			{Name: uast.KeyType, Op: String("BoxedAttribute")},
			{Name: "boxed_value", Op: UASTType(uast.Identifier{}, Obj{
				uast.KeyPos: Var("pos_"),
				"Name":      Var("aname"),
			})},
			{Name: "noops_previous", Optional: "np_opt", Op: Var("noops_previous")},
			{Name: "noops_sameline", Optional: "ns_opt", Op: Var("noops_sameline")},
		}),
	),

	mapStr("Bytes"),
	mapStr("Str"),
	mapStr("StringLiteral"),

	MapSemantic("NoopLine", uast.Comment{}, MapObj(
		Obj{
			"noop_line": CommentTextTrimmed([2]string{"#", ""}, "comm"),
		},
		CommentNode(false, "comm", nil),
	)),

	MapSemantic("NoopSameLine", uast.Comment{}, MapObj(
		Obj{
			"s": CommentText([2]string{"#", ""}, "comm"),
		},
		CommentNode(false, "comm", nil),
	)),

	Map(Obj{
		uast.KeyType: String("NoopSameLine"),
		uast.KeyPos:  Any(),
		"s":          String(""),
	}, Is(nil)),
	Map(Obj{
		uast.KeyType: String("SameLineNoops"),
		uast.KeyPos:  Any(),
		"noop_lines": Check(All(Is(nil)), Any()),
	}, Is(nil)),

	AnnotateType("keyword", MapObj(
		Fields{
			{Name: "arg", Op: Var("name")},

			{Name: "noops_previous", Drop: true, Op: Any()},
			{Name: "noops_sameline", Drop: true, Op: Any()},
		},
		Fields{
			{Name: "arg",
				Op: UASTType(uast.Identifier{}, Obj{
					"Name": Var("name"),
				})},
		}),
		role.Name),

	MapSemantic("arg", uast.Argument{}, MapObj(
		Fields{
			{Name: uast.KeyToken, Op: Var("name")},
			{Name: "default", Optional: "opt_def", Op: Var("init")},

			{Name: "ctx", Optional: "opt_ctx", Op: Any()},

			{Name: "noops_previous", Drop: true, Op: Any()},
			{Name: "noops_sameline", Drop: true, Op: Any()},

			{Name: "annotation", Optional: "ann_opt", Op: Any()},
		},
		Fields{
			{Name: "Name", Op: identifierWithPos("name")},
			{Name: "Init", Optional: "opt_def", Op: Var("init")},
		},
	)),

	MapSemantic("kwonly_arg", uast.Argument{}, MapObj(
		Fields{
			{Name: uast.KeyToken, Op: Var("name")},
			{Name: "default", Op: Var("init")},

			{Name: "noops_previous", Drop: true, Op: Any()},
			{Name: "noops_sameline", Drop: true, Op: Any()},

			{Name: "annotation", Op: Any()},
		},
		Obj{
			"Init": Var("init"),
			"Name": identifierWithPos("name"),
		},
	)),

	MapSemantic("vararg", uast.Argument{}, MapObj(
		Fields{
			{Name: uast.KeyToken, Op: Var("name")},

			{Name: "noops_previous", Drop: true, Op: Any()},
			{Name: "noops_sameline", Drop: true, Op: Any()},

			{Name: "annotation", Op: Any()},
		},
		Obj{
			"Name":     identifierWithPos("name"),
			"Variadic": Bool(true),
		},
	)),

	MapSemantic("kwarg", uast.Argument{}, MapObj(
		Fields{
			{Name: uast.KeyToken, Op: Var("name")},

			{Name: "noops_previous", Drop: true, Op: Any()},
			{Name: "noops_sameline", Drop: true, Op: Any()},

			{Name: "annotation", Op: Any()},
		},
		Obj{
			"Name":        identifierWithPos("name"),
			"MapVariadic": Bool(true),
		},
	)),

	funcDefMap("FunctionDef", false),
	funcDefMap("AsyncFunctionDef", true),

	AnnotateType("Import", MapObj(
		Obj{
			"names": Each("vals", Var("name")),
		},
		Obj{
			"names": Each("vals", UASTType(uast.RuntimeImport{},
				Obj{
					"Path": Var("name"),
				})),
		},
	), role.Import, role.Declaration, role.Statement),

	MapSemantic("alias", uast.Alias{}, MapObj(
		Obj{
			"name": Var("name"),
			"asname": Cases("case_alias",
				Check(Is(nil), Var("nilalias")),
				Check(Not(Is(nil)), Var("alias")),
			),
		},
		CasesObj("case_alias",
			Obj{
				"Name": UASTType(uast.Identifier{}, Obj{
					"Name": Var("name"),
				}),
			},
			Objs{
				{"Node": Obj{}},
				{
					"Node": UASTType(uast.Identifier{},
						Obj{
							"Name": Var("alias"),
						}),
				}},
		))),

	MapSemantic("ImportFrom", uast.RuntimeImport{}, MapObj(
		Fields{
			{Name: "names", Op: Arr(
				Obj{
					uast.KeyType: String("uast:Alias"),
					uast.KeyPos:  Var("pos"),
					"Name": Obj{
						uast.KeyType: String("uast:Identifier"),
						"Name":       String("*"),
					},
					"Node": Obj{},
				},
			)},
			{Name: "level", Op: Var("level")},
			{Name: "module", Op: Var("module")},

			{Name: "noops_previous", Drop: true, Op: Any()},
			{Name: "noops_sameline", Drop: true, Op: Any()},
		},
		Obj{
			"All": Bool(true),
			"Path": UASTType(uast.Identifier{}, Obj{
				"Name": OpPrependPath{

					numLevel: Var("level"),
					path:     Var("module"),
					joined:   Var("joined"),
					prefix:   "../",
				},
			}),
		},
	)),

	MapSemantic("ImportFrom", uast.RuntimeImport{}, MapObj(
		Fields{
			{Name: "names", Op: Var("names")},
			{Name: "module", Op: Var("module")},
			{Name: "level", Op: Var("level")},

			{Name: "noops_previous", Drop: true, Op: Any()},
			{Name: "noops_sameline", Drop: true, Op: Any()},
		},
		Obj{
			"Names": Var("names"),
			"Path": UASTType(uast.Identifier{}, Obj{
				"Name": OpPrependPath{
					numLevel: Var("level"),
					path:     Var("module"),
					joined:   Var("joined"),
					prefix:   "../",
				},
			}),
		},
	)),
}
View Source
var Preprocess = Transformers([][]Transformer{
	{Mappings(Preprocessors...)},
}...)
View Source
var PreprocessCode = []CodeTransformer{}
View Source
var Preprocessors = []Mapping{
	ObjectToNode{
		InternalTypeKey: "ast_type",
		LineKey:         "lineno",
		ColumnKey:       "col_offset",
		EndLineKey:      "end_lineno",
		EndColumnKey:    "end_col_offset",
	}.Mapping(),
}
View Source
var Transforms = driver.Transforms{
	Namespace:      "python",
	Preprocess:     Preprocess,
	PreprocessCode: PreprocessCode,
	Normalize:      Normalize,
	Annotations:    Native,
	Code:           Code,
}

Functions

This section is empty.

Types

type OpLevelDotsNumConv added in v1.3.2

type OpLevelDotsNumConv struct {
	// contains filtered or unexported fields
}

func (OpLevelDotsNumConv) Check added in v1.3.2

func (op OpLevelDotsNumConv) Check(st *State, n nodes.Node) (bool, error)

func (OpLevelDotsNumConv) Construct added in v1.3.2

func (op OpLevelDotsNumConv) Construct(st *State, n nodes.Node) (nodes.Node, error)

func (OpLevelDotsNumConv) Kinds added in v1.3.2

func (op OpLevelDotsNumConv) Kinds() nodes.Kind

type OpPrependPath added in v1.3.2

type OpPrependPath struct {
	// contains filtered or unexported fields
}

FIXME: not reversible

func (OpPrependPath) Check added in v1.3.2

func (op OpPrependPath) Check(st *State, n nodes.Node) (bool, error)

func (OpPrependPath) Construct added in v1.3.2

func (op OpPrependPath) Construct(st *State, n nodes.Node) (nodes.Node, error)

func (OpPrependPath) Kinds added in v1.3.2

func (op OpPrependPath) Kinds() nodes.Kind

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL