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

Change ParseOutput to return a NonTerminal instead of a Node #1187

Merged
merged 25 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5db05e8
First attempt: re-parse leading trivia and advance index accordingly
beta-ziliani Nov 21, 2024
86540f4
Adding nodes in NoMatch
beta-ziliani Nov 25, 2024
a74ea7d
NoMatch with tracking information about trivia and originator non-ter…
beta-ziliani Nov 27, 2024
cf6b964
Missing files
beta-ziliani Nov 27, 2024
3fbefa4
Revert to not carry the trivia in the NoMatch result
beta-ziliani Nov 28, 2024
24aff8c
Revert little change with no semantic difference
beta-ziliani Nov 28, 2024
ecd5062
Fixing comment
beta-ziliani Nov 28, 2024
4113609
revert of unnecessary change
beta-ziliani Nov 28, 2024
7495413
Adding comment
beta-ziliani Dec 10, 2024
4dc2d0b
Adding changeset
beta-ziliani Dec 10, 2024
8983d3c
Merge remote-tracking branch 'origin/main' into beta/841
beta-ziliani Dec 10, 2024
72d4858
fixup
beta-ziliani Dec 11, 2024
26d5e00
Changing parse_result to return a NonTerminalNode instead of a Node
beta-ziliani Dec 11, 2024
160e02e
Generated examples
beta-ziliani Dec 11, 2024
95137a0
Missing files
beta-ziliani Dec 12, 2024
e8c1398
solved merge conflict
beta-ziliani Dec 13, 2024
05d405a
Moving clone to clients
beta-ziliani Dec 19, 2024
9ee0996
Pulling the kind away of nomatch to the parse() function
beta-ziliani Jan 8, 2025
299d966
Changes in generated files
beta-ziliani Jan 8, 2025
3f174c8
Fixing name
beta-ziliani Jan 8, 2025
6a5c889
merging with main
beta-ziliani Jan 8, 2025
1fb766e
Applying suggestions from code review
beta-ziliani Jan 10, 2025
850b5f9
Changing the type of File.tree
beta-ziliani Jan 10, 2025
90d72b7
Adding missing files
beta-ziliani Jan 10, 2025
6615c18
Create young-bottles-beam.md
beta-ziliani Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::BTreeMap;
use std::rc::Rc;

use metaslang_cst::nodes::Node;
use semver::Version;

use crate::compilation::{CompilationUnit, File};
Expand Down Expand Up @@ -43,7 +44,10 @@ impl InternalCompilationBuilder {

let import_paths = self.imports.extract(parse_output.create_tree_cursor());

let file = File::new(id.clone(), parse_output.tree().clone());
let file = File::new(
OmarTawfik marked this conversation as resolved.
Show resolved Hide resolved
id.clone(),
Node::Nonterminal(Rc::clone(parse_output.tree())),
);
self.files.insert(id, file);

AddFileResponse { import_paths }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use crate::parser::ParseError;

#[derive(Clone, Debug, PartialEq)]
pub struct ParseOutput {
pub(crate) parse_tree: Rc<NonterminalNode>,
pub(crate) tree: Rc<NonterminalNode>,
pub(crate) errors: Vec<ParseError>,
}

impl ParseOutput {
pub fn tree(&self) -> &Rc<NonterminalNode> {
&self.parse_tree
&self.tree
}

pub fn errors(&self) -> &Vec<ParseError> {
Expand All @@ -24,6 +24,6 @@ impl ParseOutput {

/// Creates a cursor that starts at the root of the parse tree.
pub fn create_tree_cursor(&self) -> Cursor {
Rc::clone(&self.parse_tree).cursor_with_offset(TextIndex::ZERO)
Rc::clone(&self.tree).cursor_with_offset(TextIndex::ZERO)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ where
let node = Node::terminal(kind, input.to_string());
trivia_nodes.push(Edge::anonymous(node));
ParseOutput {
parse_tree: Rc::new(NonterminalNode::new(expected, trivia_nodes)),
tree: Rc::new(NonterminalNode::new(expected, trivia_nodes)),
OmarTawfik marked this conversation as resolved.
Show resolved Hide resolved
errors: vec![ParseError::new(
start..start + input.into(),
no_match.expected_terminals,
Expand Down Expand Up @@ -153,17 +153,17 @@ where
));

ParseOutput {
parse_tree: Rc::new(NonterminalNode::new(topmost_node.kind, new_children)),
tree: Rc::new(NonterminalNode::new(topmost_node.kind, new_children)),
errors,
}
} else {
let parse_tree = topmost_node;
let tree = topmost_node;
let errors = stream.into_errors();

// Sanity check: Make sure that succesful parse is equivalent to not having any invalid nodes
debug_assert_eq!(
errors.is_empty(),
Rc::clone(&parse_tree)
Rc::clone(&tree)
.cursor_with_offset(TextIndex::ZERO)
.remaining_nodes()
.all(|edge| edge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::rc::Rc;
use crate::wasm_crate::utils::{define_wrapper, FromFFI, IntoFFI};

mod ffi {
pub use crate::wasm_crate::bindings::exports::nomic_foundation::slang::cst::{
pub use crate::wasm_crate::bindgen::exports::nomic_foundation::slang::cst::{
Cursor, NonterminalNode, TextRange,
};
pub use crate::wasm_crate::bindgen::exports::nomic_foundation::slang::parser::{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ pub fn add_built_ins(
let parser = Parser::create(version)?;
let parse_output = parser.parse(Parser::ROOT_KIND, source);

let built_ins_cursor = transform(parse_output.tree()).cursor_with_offset(TextIndex::ZERO);
let built_ins_cursor = transform(&Node::Nonterminal(Rc::clone(parse_output.tree())))
.cursor_with_offset(TextIndex::ZERO);

binding_graph.add_system_file("built_ins.sol", built_ins_cursor);
Ok(())
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 9 additions & 29 deletions crates/solidity/outputs/cargo/tests/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
use std::rc::Rc;
use std::sync::Arc;

use anyhow::Result;
use semver::Version;
use slang_solidity::bindings::{self, Bindings};
use slang_solidity::cst::{Node, TextIndex};
use slang_solidity::parser::Parser;
use slang_solidity::transform_built_ins_node;

use crate::resolver::TestsPathResolver;

pub fn create_bindings(version: &Version) -> Result<Bindings> {
let parser = Parser::create(version.clone())?;
let mut bindings =
bindings::create_with_resolver(version.clone(), Arc::new(TestsPathResolver {}));

let built_ins_parse_output = parser.parse(Parser::ROOT_KIND, bindings::get_built_ins(version));
assert!(
built_ins_parse_output.is_valid(),
"built-ins parse without errors"
);

let built_ins_cursor =
transform_built_ins_node(&Node::Nonterminal(Rc::clone(built_ins_parse_output.tree())))
.cursor_with_offset(TextIndex::ZERO);

bindings.add_system_file("built_ins.sol", built_ins_cursor);
Ok(bindings)
use slang_solidity::bindings::{BindingGraph, Definition};

pub fn lookup_definition_by_name<'a>(
binding_graph: &'a BindingGraph,
name: &str,
) -> Option<Definition<'a>> {
binding_graph
.all_definitions()
.find(|definition| definition.get_cursor().node().unparse() == name)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions crates/solidity/testing/sanctuary/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::cmp::min;
use std::path::Path;
use std::rc::Rc;
use std::sync::Arc;

use anyhow::Result;
use infra_utils::paths::PathExtensions;
use itertools::Itertools;
use metaslang_bindings::PathResolver;
use semver::Version;
use slang_solidity::bindings::Bindings;
use slang_solidity::cst::{Cursor, Node, NonterminalKind, TextIndex, TextRange};
use slang_solidity::bindings;
use slang_solidity::bindings::BindingGraph;
use slang_solidity::cst::{Cursor, KindTypes, NonterminalKind, TextRange};
use slang_solidity::diagnostic::{Diagnostic, Severity};
use slang_solidity::parser::{ParseOutput, Parser};
use slang_solidity::utils::LanguageFacts;
Expand Down Expand Up @@ -215,15 +215,7 @@ fn create_bindings(
Rc::new(SingleFileResolver {
source_id: source_id.into(),
}),
);
let parser = Parser::create(version.clone())?;
let built_ins_output = parser.parse(
NonterminalKind::SourceUnit,
bindings::get_built_ins(version),
);
let built_ins_tree = built_ins_output.tree();
let built_ins_cursor = transform_built_ins_node(&Node::Nonterminal(Rc::clone(built_ins_tree)))
.cursor_with_offset(TextIndex::ZERO);
)?;

binding_graph.add_user_file(source_id, output.create_tree_cursor());

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.