Feat/node insertion#17
Conversation
| GreenNode::new(kind, children) | ||
| } | ||
|
|
||
| pub fn gen_attr_set(attr_pairs: Vec<(String, String)>) -> GreenNode{ |
There was a problem hiding this comment.
| pub fn gen_attr_set(attr_pairs: Vec<(String, String)>) -> GreenNode{ | |
| pub fn gen_attr_set(attr_pairs: &[(String, String)]) -> GreenNode{ |
There was a problem hiding this comment.
I'm trying to do this, and running into issues here. It looks like there's not an easy way to convert from a vector to an array..
|
Input generation works, and I've added in a nixpkgs_fmt pass to make sure things look nice. I've added a couple of tests as well. Code quality is poor; lots of unused imports, dead code, etc. A bunch of the processing done in main.rs does not belong. Inputs_utils needs to be split out into something more modular that matches with the rest of the style. Not ready to merge, but getting there. I also think that a bunch of the functions in utils.rs and input_utils.rs morally speaking belong in rnix. I'm just filling in the gaps done by TODOs. I was hoping for more discussion on the issue I opened there... |
|
Also, inputs need to be (1) checked, and (2) there should be some sort of type generation. Ideally, we should support other types of flake inputs that covers the entire spec. Path/git/, enabling submodules, revisions, etc. Essentially, everything specified here. I think I'd prefer to do these in separate PRs though. The scaffolding here can define the basis for further work. |
| let kind = NixLanguage::kind_to_raw(NODE_KEY_VALUE); | ||
| let assign_kind = NixLanguage::kind_to_raw(TOKEN_ASSIGN); | ||
| let whitespace_kind = NixLanguage::kind_to_raw(TOKEN_WHITESPACE); | ||
| let semicolon_kind = NixLanguage::kind_to_raw(TOKEN_SEMICOLON); | ||
| let children = vec![ | ||
| NodeOrToken::Node(key), | ||
| NodeOrToken::Token(GreenToken::new(whitespace_kind, " ")), | ||
| NodeOrToken::Token(GreenToken::new(assign_kind, "=")), | ||
| NodeOrToken::Token(GreenToken::new(whitespace_kind, " ")), | ||
| NodeOrToken::Node(value), | ||
| NodeOrToken::Token(GreenToken::new(semicolon_kind, ";")), | ||
| NodeOrToken::Token(GreenToken::new(whitespace_kind, "\n")), | ||
| ]; |
There was a problem hiding this comment.
| let kind = NixLanguage::kind_to_raw(NODE_KEY_VALUE); | |
| let assign_kind = NixLanguage::kind_to_raw(TOKEN_ASSIGN); | |
| let whitespace_kind = NixLanguage::kind_to_raw(TOKEN_WHITESPACE); | |
| let semicolon_kind = NixLanguage::kind_to_raw(TOKEN_SEMICOLON); | |
| let children = vec![ | |
| NodeOrToken::Node(key), | |
| NodeOrToken::Token(GreenToken::new(whitespace_kind, " ")), | |
| NodeOrToken::Token(GreenToken::new(assign_kind, "=")), | |
| NodeOrToken::Token(GreenToken::new(whitespace_kind, " ")), | |
| NodeOrToken::Node(value), | |
| NodeOrToken::Token(GreenToken::new(semicolon_kind, ";")), | |
| NodeOrToken::Token(GreenToken::new(whitespace_kind, "\n")), | |
| ]; | |
| use NixLanguage::kind_to_raw; | |
| use NodeOrToken::{Node, Token}; | |
| let kind = kind_to_raw(NODE_KEY_VALUE); | |
| let assign_kind = kind_to_raw(TOKEN_ASSIGN); | |
| let whitespace_kind = kind_to_raw(TOKEN_WHITESPACE); | |
| let semicolon_kind = kind_to_raw(TOKEN_SEMICOLON); | |
| let children = vec![ | |
| Node(key), | |
| Token(GreenToken::new(whitespace_kind, " ")), | |
| Token(GreenToken::new(assign_kind, "=")), | |
| Token(GreenToken::new(whitespace_kind, " ")), | |
| Node(value), | |
| Token(GreenToken::new(semicolon_kind, ";")), | |
| Token(GreenToken::new(whitespace_kind, "\n")), | |
| ]; |
There was a problem hiding this comment.
Can't import NixLanguage::kind_to_raw. Not sure why....
There was a problem hiding this comment.
Oh... (that might be the case because the method is defined in a trait impl)
Maybe create a small wrapper for it then:
#[inline(always)]
fn kind_to_raw(x: rnix::SyntaxKind) -> rowan::SyntaxKind {
NixLanguage::kind_to_raw(x)
}| use rowan::{api::SyntaxNode, GreenNode, GreenNodeBuilder, GreenToken, Language, NodeOrToken}; | ||
| use std::string::ToString; | ||
| use NodeOrToken::{Node, Token}; |
There was a problem hiding this comment.
| use rowan::{api::SyntaxNode, GreenNode, GreenNodeBuilder, GreenToken, Language, NodeOrToken}; | |
| use std::string::ToString; | |
| use NodeOrToken::{Node, Token}; | |
| use rowan::{api::SyntaxNode, GreenNode, GreenNodeBuilder, GreenToken, Language, NodeOrToken::{self, Node, Token}}; | |
| use std::string::ToString; |
| let close_curly_kind = NixLanguage::kind_to_raw(TOKEN_CURLY_B_CLOSE); | ||
| let attr_set_kind = NixLanguage::kind_to_raw(NODE_ATTR_SET); | ||
| let whitespace_kind = NixLanguage::kind_to_raw(TOKEN_WHITESPACE); | ||
| let mut token_vec = Vec::new(); |
There was a problem hiding this comment.
suggestion: replace the complete following stuff with this:
let mut token_vec = Vec::new();
let mut tokens = vec![
Token(GreenToken::new(open_curly_kind, "{")),
Token(GreenToken::new(whitespace_kind, "\n")),
];
tokens.extend(attr_pairs
.into_iter()
.map(move |(k, v)| Node(new_key_value(k, v))));
tokens.push(Token(GreenToken::new(close_curly_kind, "}")));| let kind: rowan::SyntaxKind = NixLanguage::kind_to_raw(NODE_STRING); | ||
| node.start_node(kind); | ||
| let start_string_kind: rowan::SyntaxKind = NixLanguage::kind_to_raw(TOKEN_STRING_START); | ||
| node.token(start_string_kind, "\""); | ||
| let string_content: rowan::SyntaxKind = NixLanguage::kind_to_raw(TOKEN_STRING_CONTENT); | ||
| node.token(string_content, &item.val.to_string()); | ||
| let end_string_kind: rowan::SyntaxKind = NixLanguage::kind_to_raw(TOKEN_STRING_END); | ||
| node.token(end_string_kind, "\""); |
There was a problem hiding this comment.
| let kind: rowan::SyntaxKind = NixLanguage::kind_to_raw(NODE_STRING); | |
| node.start_node(kind); | |
| let start_string_kind: rowan::SyntaxKind = NixLanguage::kind_to_raw(TOKEN_STRING_START); | |
| node.token(start_string_kind, "\""); | |
| let string_content: rowan::SyntaxKind = NixLanguage::kind_to_raw(TOKEN_STRING_CONTENT); | |
| node.token(string_content, &item.val.to_string()); | |
| let end_string_kind: rowan::SyntaxKind = NixLanguage::kind_to_raw(TOKEN_STRING_END); | |
| node.token(end_string_kind, "\""); | |
| node.start_node(NixLanguage::kind_to_raw(NODE_STRING)); | |
| node.token(NixLanguage::kind_to_raw(TOKEN_STRING_START), "\""); | |
| node.token(NixLanguage::kind_to_raw(TOKEN_STRING_CONTENT), &item.val.to_string()); | |
| node.token(NixLanguage::kind_to_raw(TOKEN_STRING_END), "\""); |
| pub(crate) struct Key { | ||
| val: SmlStr, | ||
| } |
There was a problem hiding this comment.
I think a simple newtype struct would be a better fit, unless you intend to add more fields.
| pub(crate) struct Key { | |
| val: SmlStr, | |
| } | |
| pub(crate) struct Key(SmlStr); |
|
@zseri sorry I haven't pulled in your changes yet. I think that in order for this to work in a scalable manner (we'd like to pull in some sort of evaluation mechanism so we can meaningfully make edits and check their correctness), the IR needs to be a bit more flushed out. Going to focus on that for a bit then cleanup in the input code. In essence we're making our own IR here. I think it should at a higher level than the output of the parser, and we should have some sort of mechanism to switch between IR and GreenNodes. We'll parse the structure into this higher level IR, make changes based on user request, then push down to GreenNodes again. |
fogti
left a comment
There was a problem hiding this comment.
I would suggest splitting the EDSL-like + conversion between that and rnix, rowan into a separate crate (maybe rnix-ddhir), so we can lay out a cleaner interface for it rather sooner than later.
| String, | ||
| Function, | ||
| List(Box<NixType>), | ||
| AttrSet(Vec<Box<NixType>>), |
There was a problem hiding this comment.
how is this AttrSet type decl supposed to work?
| Str(SmlStr), | ||
| } | ||
|
|
||
| trait NixValue {} |
There was a problem hiding this comment.
why not model all possible values here (including rather opaque stuff like function calls)? Maybe it would be a good idea to put this into a separate crate.
| let kind: rowan::SyntaxKind = NixLanguage::kind_to_raw(NODE_KEY); | ||
| #[derive(Debug, Clone, Eq, PartialEq, Default)] | ||
| pub(crate) struct NixAttrSet<T: Into<GreenNode> + Clone> { | ||
| kvs: Vec<NixKeyValue<T>>, |
There was a problem hiding this comment.
why don't we use something like the indexmap crate here?
fogti
left a comment
There was a problem hiding this comment.
necessary because of the removal of the SmlStr newtype
| @@ -0,0 +1,269 @@ | |||
| use crate::parser::utils::{string_to_node, NixNode}; | |||
| use crate::SmlStr; | |||
There was a problem hiding this comment.
| use crate::SmlStr; | |
| use smol_str::SmolStr; |
|
|
||
| #[derive(Debug, Clone, Eq, PartialEq, Default)] | ||
| pub(crate) struct NixKey { | ||
| pub val: SmlStr, |
There was a problem hiding this comment.
| pub val: SmlStr, | |
| pub val: SmolStr, |
|
|
||
| #[derive(Debug, Clone, Eq, PartialEq, Default)] | ||
| pub(crate) struct NixStringLiteral { | ||
| pub val: SmlStr, |
There was a problem hiding this comment.
| pub val: SmlStr, | |
| pub val: SmolStr, |
| //Key(SmlStr), | ||
| //StringLiteral(SmlStr), |
There was a problem hiding this comment.
| //Key(SmlStr), | |
| //StringLiteral(SmlStr), | |
| //Key(SmolStr), | |
| //StringLiteral(SmolStr), |
| //let mut inputs = Vec::new(); | ||
| //if let Some(s) = item.url { | ||
| //inputs.push(( | ||
| //SyntaxStructure::Key(SmlStr::new_inline("url")).into(), |
There was a problem hiding this comment.
| //SyntaxStructure::Key(SmlStr::new_inline("url")).into(), | |
| //SyntaxStructure::Key(SmolStr::new_inline("url")).into(), |
| #[display("{0}")] | ||
| Bool(bool), | ||
| #[display("{0}")] | ||
| Other(SmlStr), |
There was a problem hiding this comment.
??? maybe rebase necessary ???
| @@ -0,0 +1,21 @@ | |||
| use crate::SmlStr; | |||
There was a problem hiding this comment.
| use crate::SmlStr; | |
| use smol_str::SmolStr; |
| enum NixPrimitive { | ||
| Bool(bool), | ||
| Int(i64), | ||
| Str(SmlStr), |
There was a problem hiding this comment.
| Str(SmlStr), | |
| Str(SmolStr), |
| //let mut inputs_gn = Vec::<Box<dyn>>::new() | ||
| //if let Some(url) = input.url { | ||
| //inputs_gn.push(( | ||
| //NixKey{val: SmlStr::new_inline("url")}.into(), |
There was a problem hiding this comment.
| //NixKey{val: SmlStr::new_inline("url")}.into(), | |
| //NixKey{val: SmolStr::new_inline("url")}.into(), |
| //let url_gn: GreenNode = url.into(); | ||
| //} | ||
| //if let Some(is_flake) = input.is_flake { | ||
| //inputs_gn.push(NixKey{val: SmlStr::new_inline("flake")}.into(), ); |
There was a problem hiding this comment.
| //inputs_gn.push(NixKey{val: SmlStr::new_inline("flake")}.into(), ); | |
| //inputs_gn.push(NixKey{val: SmolStr::new_inline("flake")}.into(), ); |
This is a draft PR for AST node insertion. Objectives:
Inputtype and attribute set&strinstead ofStringResolves #18 and #14 .