-
Notifications
You must be signed in to change notification settings - Fork 323
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
Implement private modules #7840
Implement private modules #7840
Conversation
3b2e5e5
to
08513fe
Compare
lib/rust/parser/src/syntax/tree.rs
Outdated
@@ -951,6 +955,7 @@ pub fn apply_unary_operator<'s>(opr: token::Operator<'s>, rhs: Option<Tree<'s>>) | |||
pub fn to_ast(token: Token) -> Tree { | |||
match token.variant { | |||
token::Variant::Ident(ident) => token.with_variant(ident).into(), | |||
token::Variant::Private(private) => Tree::private(token.with_variant(private)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will never match because the Private
token type is only generated by the macro, which immediately places it in a AST node, so an Item::Token(Token::Private)
is never encountered.
I don't see a need for a token type for private
; if it were a reserved word we could easily identify at lex time and always treat specially then we should give it a token type, but we are taking a contextual keywords approach (because it is a goal that identifiers with special meanings in syntactic constructs can be used as normal identifiers when used outside those constructs).
println!("private_keyword[begin] : Segments={:?}", segments); | ||
let segment = segments.pop().0; | ||
let keyword = into_private(segment.header); | ||
let ret_tree = syntax::Tree::private(keyword); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The body can be handled the same way as in capture_expressions
, and placed in an Option<Tree>
field of the private
node. (I think an optional body is preferable to separate Tree
types for the standalone-private and private-with-expression because we have to assume the user could be halfway through typing something, so a Private
without a body may well be private-with-expression whose expression hasn't been written yet).
|
||
#[test] | ||
#[ignore] | ||
fn private_is_first_statement() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will require changes to the macro resolver--we could add a field to Context::Statement
, like so:
enum Context { Expression, Statement { first: bool } }
The resolver would then keep track of when the first "contentful' line has been encountered in order to construct the first
field. Then we could add a third MacroMap
that is only run in Statement
context with first=true
. Note that there's a rewrite of the macro resolver currently in CI: #7711.
#[rustfmt::skip] | ||
let lines = vec![ | ||
"# Some comment", | ||
"# Other comment", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important also to allow doc-comments. That may be tricky, actually. I'm thinking about how that would work...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just check for Documented
nodes and treat them as non-contentful. They are bodiless during macro resolution because that type of multi-line construct is assembled after macros are run.
# Conflicts: # CHANGELOG.md
Co-authored-by: Jaroslav Tulach <[email protected]>
….com:enso-org/enso into wip/akirathan/7304-Implement-private-modules
if (subModName.getParent().isDefined()) { | ||
return parentModName.item().equals( | ||
subModName.getParent().get().item() | ||
); | ||
} else { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getOrElse
?
} else { | ||
throw new IllegalStateException("unknown exp: " + exp); | ||
} | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this correct? Shouldn't this be return false;
?
Closes #7304
Pull Request Description
Adds the ability to declare a module as private. Modifies the parser to add the
private
keyword as a reserved keyword. All the checks for private modules are implemented as an independent Compiler pass. No checks are done at runtime.Important Notes
private
- a reserved keyword.private
keyword as the first statement are declared as private (Project private)Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.
./run ide build
.