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

Add language support for NAMESPACE & .Rbuildignore #1221

Merged
merged 1 commit into from
Nov 23, 2022

Conversation

nx10
Copy link
Contributor

@nx10 nx10 commented Oct 12, 2022

Edit: not sure if "language support" is the right terminology. Maybe "syntax highlighting grammars and configurations" would be correct.

What problem did you solve?

This PR adds language support for NAMESPACE and .Rbuildignore R package files according to the specification:

Screenshots

image

image

Note

(I am currently participating in the hacktoberfest. If you like this PR consider to tag it with hacktoberfest-accepted .)

@renkun-ken
Copy link
Member

Thanks for working on this?

Looks like NAMESPACE file is more like R syntax, just like the following:

where both do some R version checking.

Is there a reason we don't just use R syntax and extend a bit if helpful?

@nx10
Copy link
Contributor Author

nx10 commented Oct 12, 2022

Thanks for working on this?

Looks like NAMESPACE file is more like R syntax, just like the following:

where both do some R version checking.

Is there a reason we don't just use R syntax and extend a bit if helpful?

Interesting, the documentation does mention version checks, I wonder if general R code is allowed in these files.
I will see if I can link with the R grammar for everything that is not an import/export directive.

As for the use-case: I find myself looking at NAMESPACE files solely to figure out what symbols a package imports and exports, which I tried to simplify with this. I realize that this is subjective so it's perfectly fine if you don't want to merge this feature.

The problem with extending the R grammar is that the NAMESPACE directives are legal symbols in R:

> S3method
Error: object 'S3method' not found
> S3method <- "asd"
> S3method 
[1] "asd"
> import
Error: object 'import' not found
> import <- 12
> import
[1] 12

so it would be wrong to highlight them differently in R code files.

@renkun-ken
Copy link
Member

renkun-ken commented Oct 13, 2022

It seems that most functions in baseenv are allowed at compile time. We might need to add highlighting for if else, string literal and simple function calls.

I tried something like the following and it works, but anything like utils::capture.output won't work with an error raised.

export(fun1)
export(fun2)
export(fun3)

if (findInterval(1, c(0, 1)) >= 1) {
  export(fun4)
}

parseNamespaceFile() is called on package installation to parse NAMESPACE file.

Copy link
Member

@renkun-ken renkun-ken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge this first and revisit if we need further improvements.

@renkun-ken renkun-ken merged commit b3e107e into REditorSupport:master Nov 23, 2022
@nx10
Copy link
Contributor Author

nx10 commented Nov 23, 2022

Thanks! It's not easy to to fall back to the R grammer for everything but specific functions as the grammar is "hungry" and once a scope starts (i.e. with {, () it will completely take over. I am pretty sure there is a way to do it but I could not find it in the short time I tried.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants