Skip to content

Commit

Permalink
Remove use of :: for namespaces
Browse files Browse the repository at this point in the history
Imports and constant references no longer use "::" to separate modules
from other modules or constants, instead using ".". So instead of this:

    import foo::bar::(A, B)

You now write this:

    import foo.bar.(A, B)

And instead of this:

    errors::FOO

You now write:

    errors.FOO

The use of "." over "::" has a few benefits/reasons:

1. It's not only one character less to type, on standard keyboards it
   also removes the need for using shift
2. It's consistent with method calls and field reads
3. It removes the need for remembering "Oh wait I'm trying to access a
   constant, so I have to use ::"
4. Auto-completion engines now only need to consider "." as a completion
   start character, instead of also having to consider "::"
5. It appears less noisy compared to "::", especially when there are
   many imports grouped together

The syntax for importing symbols from a module remains the same. While I
thought about changing this, I'm not sure yet what approach to take
there, so for the time being this remains the same.

This fixes #545.

Changelog: changed
  • Loading branch information
yorickpeterse committed Jul 20, 2023
1 parent 70728b6 commit 8026b29
Show file tree
Hide file tree
Showing 118 changed files with 1,091 additions and 1,105 deletions.
4 changes: 0 additions & 4 deletions ast/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ pub enum TokenKind {
Case,
Class,
Colon,
ColonColon,
Comma,
Comment,
Constant,
Expand Down Expand Up @@ -195,7 +194,6 @@ impl TokenKind {
TokenKind::Break => "the 'break' keyword",
TokenKind::Class => "the 'class' keyword",
TokenKind::Colon => "a ':'",
TokenKind::ColonColon => "a '::'",
TokenKind::Comma => "a ','",
TokenKind::Comment => "a comment",
TokenKind::Constant => "a constant",
Expand Down Expand Up @@ -807,7 +805,6 @@ impl Lexer {
let start = self.position;
let line = self.line;
let (incr, kind) = match self.next_byte() {
COLON => (2, TokenKind::ColonColon),
EQUAL => (2, TokenKind::Replace),
_ => (1, TokenKind::Colon),
};
Expand Down Expand Up @@ -1928,7 +1925,6 @@ mod tests {
#[test]
fn test_lexer_colon() {
assert_token!(":", Colon, ":", 1..=1, 1..=1);
assert_token!("::", ColonColon, "::", 1..=1, 1..=2);
assert_token!(":=", Replace, ":=", 1..=1, 1..=2);
}

Expand Down
Loading

0 comments on commit 8026b29

Please sign in to comment.