From 1f677b95446f0c81425ab1be42bf768fed9ee11e Mon Sep 17 00:00:00 2001 From: xushiwei Date: Thu, 26 Dec 2024 08:23:17 +0800 Subject: [PATCH] mini spec ebnf: Types --- doc/spec-mini.md | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/doc/spec-mini.md b/doc/spec-mini.md index a8c73193b..5eb9dbdc0 100644 --- a/doc/spec-mini.md +++ b/doc/spec-mini.md @@ -437,6 +437,19 @@ A variable's value is retrieved by referring to the variable in an [expression]( ## Types +A type determines a set of values together with operations and methods specific to those values. A type may be denoted by a _type name_. A type may also be specified using a type literal, which composes a type from existing types. + +```go +Type = TypeName | TypeLit | "(" Type ")" . +TypeName = identifier | QualifiedIdent . +TypeLit = ArrayType | StructType | PointerType | FunctionType | InterfaceType | + SliceType | MapType . // TODO: check this +``` + +The language [predeclares]() certain type names. Others are introduced with [type declarations](#type-declarations). _Composite types_—array, struct, pointer, function, interface, slice, map—may be constructed using type literals. + +Predeclared types and defined types are called _named types_. An alias denotes a named type if the type given in the alias declaration is a named type. + ### Boolean types A _boolean type_ represents the set of Boolean truth values denoted by the predeclared constants true and false. The predeclared boolean type is `bool`; it is a defined type. @@ -755,7 +768,7 @@ The equality operators == and != apply to operands of comparable types. The orde A comparison of two interface values with identical dynamic types causes a [run-time panic]() if that type is not comparable. This behavior applies not only to direct interface value comparisons but also when comparing arrays of interface values or structs with interface-valued fields. -Slice, map, and function types are not comparable. However, as a special case, a slice, map, or function value may be compared to the predeclared identifier `nil`. Comparison of pointer, channel, and interface values to `nil` is also allowed and follows from the general rules above. +Slice, map, and function types are not comparable. However, as a special case, a slice, map, or function value may be compared to the predeclared identifier `nil`. Comparison of pointer, and interface values to `nil` is also allowed and follows from the general rules above. #### Logical operators @@ -1136,7 +1149,7 @@ a[i] <<= 2 i &^= 1<