Skip to content

Treat primitive type names as predefined identifiers instead of keywords #817

Description

@pepone

Primitive type names such as bool, int32, and string do not need to be lexer keywords. They can instead be ordinary identifiers bound to predefined types in the global type namespace.

With this model:

module Example

struct string {}

struct Value {
    local: string       // Example::string
    primitive: ::string // Global primitive
}

A module can also share a name with a primitive because modules and types occupy different namespaces:

module int32

struct Value {
    field: int32 // Global primitive
}

Proposed changes

  • Lex primitive names as identifiers rather than dedicated keyword tokens.
  • Predefine primitive types in the AST’s global type namespace.
  • Resolve primitive and user-defined type references through the same scoped lookup.
  • Allow user-defined types to shadow primitives normally.
  • Use the requested symbol category during lookup so that modules and types with the same name can coexist.
  • Continue accepting escaped spellings such as \string for compatibility, but make them equivalent to string.

This should remove the primitive grammar production, immediate primitive patching, and dedicated primitive lookup. Result, Sequence, and Dictionary can remain grammar keywords because they introduce constructed-type syntax.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalslice languageRelated to the Slice language itselfslicecRelated to the 'slicec' crate

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions