Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling for Select expressions #33

Open
aaronjanse opened this issue Sep 25, 2021 · 1 comment
Open

Error handling for Select expressions #33

aaronjanse opened this issue Sep 25, 2021 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@aaronjanse
Copy link
Member

The following is a common scenario when editing Nix:

rec {
    foo.bar = 13;
    xyz = foo.; # trailing period was just typed
}

rnix-parser consumes the rest of the file as an error, rather than stopping at the semicolon:

`dump-ast` output
error: unexpected TOKEN_SEMICOLON at 38..41, wanted any of [TOKEN_IDENT]
error: unexpected end of file, wanted any of [TOKEN_IDENT]
error: unexpected end of file, wanted any of [TOKEN_SEMICOLON]
error: unexpected end of file
NODE_ROOT 0..41 {
  NODE_ATTR_SET 0..41 {
    TOKEN_REC("rec") 0..3
    TOKEN_WHITESPACE(" ") 3..4
    TOKEN_CURLY_B_OPEN("{") 4..5
    TOKEN_WHITESPACE("\n    ") 5..10
    NODE_KEY_VALUE 10..23 {
      NODE_KEY 10..17 {
        NODE_IDENT 10..13 {
          TOKEN_IDENT("foo") 10..13
        }
        TOKEN_DOT(".") 13..14
        NODE_IDENT 14..17 {
          TOKEN_IDENT("bar") 14..17
        }
      }
      TOKEN_WHITESPACE(" ") 17..18
      TOKEN_ASSIGN("=") 18..19
      TOKEN_WHITESPACE(" ") 19..20
      NODE_LITERAL 20..22 {
        TOKEN_INTEGER("13") 20..22
      }
      TOKEN_SEMICOLON(";") 22..23
    }
    TOKEN_WHITESPACE("\n    ") 23..28
    NODE_KEY_VALUE 28..41 {
      NODE_KEY 28..31 {
        NODE_IDENT 28..31 {
          TOKEN_IDENT("xyz") 28..31
        }
      }
      TOKEN_WHITESPACE(" ") 31..32
      TOKEN_ASSIGN("=") 32..33
      TOKEN_WHITESPACE(" ") 33..34
      NODE_SELECT 34..41 {
        NODE_IDENT 34..37 {
          TOKEN_IDENT("foo") 34..37
        }
        TOKEN_DOT(".") 37..38
        NODE_ERROR 38..41 {
          TOKEN_SEMICOLON(";") 38..39
          TOKEN_WHITESPACE("\n") 39..40
          TOKEN_CURLY_B_CLOSE("}") 40..41
        }
      }
    }
  }
}

It would be nice if this scenario were handled, since that would allow rnix-lsp to provide autocomplete here.

I'd be happy to create a PR if this (presumably minor) change to rnix-parser is wanted.

@aaronjanse
Copy link
Member Author

aaronjanse commented Sep 25, 2021

I'd be happy to create a PR if this (presumably minor) change to rnix-parser is wanted.

Actually, I don't think I understand rowan well enough to make a PR short-term, but I'd be happy to learn if needed

EDIT: I've made a WIP pull request

@Ma27 Ma27 added the bug Something isn't working label Oct 8, 2021
@Ma27 Ma27 added this to the 0.10.0 milestone Oct 8, 2021
@Ma27 Ma27 modified the milestones: 0.10.0, 0.11.0 Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants