Skip to content

Commit

Permalink
Merge branch 'main' into feature/required-label
Browse files Browse the repository at this point in the history
  • Loading branch information
mjoerussell committed Jan 3, 2025
2 parents 819da29 + 3936e23 commit bb853b4
Show file tree
Hide file tree
Showing 70 changed files with 12,551 additions and 2,736 deletions.
227 changes: 112 additions & 115 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ testlang_npm_package = { path = "crates/testlang/outputs/npm/package", version =
#
# External
#
anyhow = { version = "1.0.94", features = ["backtrace", "std"] }
anyhow = { version = "1.0.95", features = ["backtrace", "std"] }
ariadne = { version = "0.2.0" }
# Currently 'bencher' backend API is under development/unstable.
# They recommend always running with the latest CLI version from 'main' until it is stabilized.
Expand All @@ -101,9 +101,9 @@ cargo-xwin = { version = "0.14.2" }
cargo-zigbuild = { version = "0.18.3" }
clap = { version = "4.5.13", features = ["derive", "wrap_help"] }
clap_complete = { version = "4.5.13" }
console = { version = "0.15.8" }
console = { version = "0.15.10" }
derive-new = { version = "0.6.0" }
env_logger = { version = "0.11.5" }
env_logger = { version = "0.11.6" }
iai-callgrind = { version = "0.12.3" }
iai-callgrind-runner = { version = "0.12.3" }
ignore = { version = "0.4.23" }
Expand All @@ -120,25 +120,25 @@ once_cell = { version = "1.20.2" }
paste = { version = "1.0.15" }
proc-macro2 = { version = "1.0.92" }
public-api = { version = "0.37.0" }
quote = { version = "1.0.37" }
quote = { version = "1.0.38" }
rayon = { version = "1.10.0" }
regex = { version = "1.11.1" }
reqwest = { version = "0.12.9", features = ["blocking"] }
rustdoc-json = { version = "0.9.3" }
reqwest = { version = "0.12.12", features = ["blocking"] }
rustdoc-json = { version = "0.9.4" }
semver = { version = "1.0.24", features = ["serde"] }
serde = { version = "1.0.216", features = ["derive", "rc"] }
serde_json = { version = "1.0.133", features = ["preserve_order"] }
serde = { version = "1.0.217", features = ["derive", "rc"] }
serde_json = { version = "1.0.134", features = ["preserve_order"] }
similar-asserts = { version = "1.6.0" }
smallvec = { version = "1.7.0", features = ["union"] }
stack-graphs = { version = "0.13.0" }
stack-graphs = { git = "https://github.com/NomicFoundation/stack-graphs", branch = "nomic" }
string-interner = { version = "0.17.0", features = [
"std",
"inline-more",
"backends",
] }
strum = { version = "0.26.3" }
strum_macros = { version = "0.26.4" }
syn = { version = "2.0.90", features = [
syn = { version = "2.0.93", features = [
"fold",
"full",
"extra-traits",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::fmt::Debug;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::rc::Rc;

use indexmap::{IndexMap, IndexSet};
use infra_utils::paths::PathExtensions;
use proc_macro2::Ident;
use semver::Version;
use syn::parse::ParseStream;
Expand Down Expand Up @@ -100,7 +99,7 @@ impl ParseInputTokens for PathBuf {
fn parse_value(input: ParseStream<'_>, errors: &mut ErrorsCollection) -> Result<Self> {
let value = String::parse_value(input, errors)?;

Ok(Path::repo_path(value))
Ok(PathBuf::from(value))
}
}

Expand Down
14 changes: 14 additions & 0 deletions crates/codegen/language/definition/src/model/built_ins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,37 @@ pub enum BuiltIn {
#[derive_spanned_type(Clone, Debug, ParseInputTokens, WriteOutputTokens)]
pub struct BuiltInFunction {
pub name: String,

#[serde(skip_serializing_if = "Vec::is_empty")]
pub parameters: Vec<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub return_type: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<VersionSpecifier>,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive_spanned_type(Clone, Debug, ParseInputTokens, WriteOutputTokens)]
pub struct BuiltInType {
pub name: String,

#[serde(skip_serializing_if = "Vec::is_empty")]
pub fields: Vec<BuiltInField>,

#[serde(skip_serializing_if = "Vec::is_empty")]
pub functions: Vec<BuiltInFunction>,

#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<VersionSpecifier>,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive_spanned_type(Clone, Debug, ParseInputTokens, WriteOutputTokens)]
pub struct BuiltInField {
pub definition: String,

#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<VersionSpecifier>,
}
3 changes: 2 additions & 1 deletion crates/codegen/language/definition/src/model/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ impl Section {
#[derive_spanned_type(Clone, Debug, ParseInputTokens, WriteOutputTokens)]
pub struct Topic {
pub title: String,
pub notes_file: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub lexical_context: Option<Identifier>,

pub items: Vec<Item>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::model::{Identifier, VersionSpecifier};
pub struct EnumItem {
pub name: Identifier,

#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<VersionSpecifier>,

pub variants: Vec<EnumVariant>,
Expand All @@ -18,5 +19,6 @@ pub struct EnumItem {
pub struct EnumVariant {
pub reference: Identifier,

#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<VersionSpecifier>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use crate::model::{Identifier, VersionSpecifier};
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive_spanned_type(Clone, Debug, ParseInputTokens, WriteOutputTokens)]
pub struct FieldsErrorRecovery {
#[serde(skip_serializing_if = "Option::is_none")]
pub terminator: Option<Identifier>,

#[serde(skip_serializing_if = "Option::is_none")]
pub delimiters: Option<FieldDelimiters>,
}

Expand All @@ -15,12 +18,14 @@ pub struct FieldsErrorRecovery {
pub struct FieldDelimiters {
pub open: Identifier,
pub close: Identifier,

/// How many tokens have to be matched to trigger the error recovery.
/// For ambiguous syntaxes this needs to be set to at least N, where N
/// is the token lookahead required to disambiguate the syntax.
///
/// By default, we assume no lookahead (0) is required to recover from
/// unrecognized body between delimiters, so it's always triggered.
#[serde(skip_serializing_if = "Option::is_none")]
pub terminals_matched_acceptance_threshold: Option<u8>,
}

Expand All @@ -33,6 +38,7 @@ pub enum Field {
Optional {
reference: Identifier,

#[serde(skip_serializing_if = "Option::is_none")]
enabled: Option<VersionSpecifier>,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::model::{Field, FieldsErrorRecovery, Identifier, VersionSpecifier};
pub struct PrecedenceItem {
pub name: Identifier,

#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<VersionSpecifier>,

pub precedence_expressions: Vec<Rc<PrecedenceExpression>>,
Expand All @@ -30,9 +31,12 @@ pub struct PrecedenceExpression {
pub struct PrecedenceOperator {
pub model: OperatorModel,

#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<VersionSpecifier>,

#[serde(skip_serializing_if = "Option::is_none")]
pub error_recovery: Option<FieldsErrorRecovery>,

pub fields: IndexMap<Identifier, Field>,
}

Expand All @@ -50,5 +54,6 @@ pub enum OperatorModel {
pub struct PrimaryExpression {
pub reference: Identifier,

#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<VersionSpecifier>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ pub struct RepeatedItem {
pub name: Identifier,
pub reference: Identifier,

#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<VersionSpecifier>,

#[serde(skip_serializing_if = "Option::is_none")]
pub allow_empty: Option<bool>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ pub struct SeparatedItem {
pub reference: Identifier,
pub separator: Identifier,

#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<VersionSpecifier>,

#[serde(skip_serializing_if = "Option::is_none")]
pub allow_empty: Option<bool>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ use crate::model::{Field, FieldsErrorRecovery, Identifier, VersionSpecifier};
pub struct StructItem {
pub name: Identifier,

#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<VersionSpecifier>,

#[serde(skip_serializing_if = "Option::is_none")]
pub error_recovery: Option<FieldsErrorRecovery>,

pub fields: IndexMap<Identifier, Field>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::model::{Identifier, Scanner, VersionSpecifier};
pub struct FragmentItem {
pub name: Identifier,

#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<VersionSpecifier>,

pub scanner: Scanner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ pub struct KeywordItem {
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive_spanned_type(Clone, Debug, ParseInputTokens, WriteOutputTokens)]
pub struct KeywordDefinition {
#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<VersionSpecifier>,

/// When the keyword is reserved, i.e. can't be used in other position (e.g. as a name)
#[serde(skip_serializing_if = "Option::is_none")]
pub reserved: Option<VersionSpecifier>,
// Underlying keyword scanner (i.e. identifier scanner)

/// Underlying keyword scanner (i.e. identifier scanner)
pub value: KeywordValue,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct TokenItem {
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive_spanned_type(Clone, Debug, ParseInputTokens, WriteOutputTokens)]
pub struct TokenDefinition {
#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<VersionSpecifier>,

pub scanner: Scanner,
Expand Down
8 changes: 2 additions & 6 deletions crates/codegen/language/tests/src/pass/tiny_language.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::path::Path;

use codegen_language_definition::model::{
Field, Item, Language, Scanner, Section, StructItem, TokenDefinition, TokenItem, Topic,
TriviaParser,
};
use infra_utils::paths::PathExtensions;
use semver::Version;

codegen_language_macros::compile!(Language(
Expand Down Expand Up @@ -49,8 +46,8 @@ fn definition() {
tiny::TinyDefinition::create(),
Language {
name: "Tiny".into(),
documentation_dir: Path::repo_path("tiny/docs"),
binding_rules_file: Path::repo_path("tiny/bindings/rules.msgb"),
documentation_dir: "tiny/docs".into(),
binding_rules_file: "tiny/bindings/rules.msgb".into(),
file_extension: Some(".tiny".into()),
root_item: "Foo".into(),
leading_trivia: TriviaParser::Sequence { parsers: [].into() },
Expand All @@ -65,7 +62,6 @@ fn definition() {
title: "Section One".into(),
topics: vec![Topic {
title: "Topic One".into(),
notes_file: None,
lexical_context: None,
items: [
Item::Struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use semver::Version;

use crate::bindings::BindingGraph;
use crate::bindings::BindingGraphBuilder;
use crate::parser::ParserInitializationError;

#[allow(clippy::needless_pass_by_value)]
pub fn add_built_ins(
_binding_graph: &mut BindingGraph,
_binding_graph_builder: &mut BindingGraphBuilder,
_version: Version,
) -> Result<(), ParserInitializationError> {
unreachable!("Built-ins are Solidity-specific")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use semver::Version;

use crate::cst::KindTypes;

pub type BindingGraphBuilder = metaslang_bindings::BindingGraphBuilder<KindTypes>;
pub type BindingGraph = metaslang_bindings::BindingGraph<KindTypes>;
pub type Definition<'a> = metaslang_bindings::Definition<'a, KindTypes>;
pub type Reference<'a> = metaslang_bindings::Reference<'a, KindTypes>;
pub type Definition = metaslang_bindings::Definition<KindTypes>;
pub type Reference = metaslang_bindings::Reference<KindTypes>;
pub type BindingLocation = metaslang_bindings::BindingLocation<KindTypes>;
pub type UserFileLocation = metaslang_bindings::UserFileLocation<KindTypes>;

Expand All @@ -29,8 +30,8 @@ pub enum BindingGraphInitializationError {
pub fn create_with_resolver(
version: Version,
resolver: Rc<dyn PathResolver<KindTypes>>,
) -> Result<BindingGraph, ParserInitializationError> {
let mut binding_graph = BindingGraph::create(
) -> Result<BindingGraphBuilder, BindingGraphInitializationError> {
let mut binding_graph = BindingGraphBuilder::create(
version.clone(),
binding_rules::BINDING_RULES_SOURCE,
resolver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ impl CompilationUnit {
files: self.files.clone(),
};

let mut binding_graph =
let mut builder =
create_with_resolver(self.language_version.clone(), Rc::new(resolver))?;

for (id, file) in &self.files {
binding_graph.add_user_file(id, file.create_tree_cursor());
builder.add_user_file(id, file.create_tree_cursor());
}

Ok(Rc::new(binding_graph))
Ok(builder.build())
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/codegen/runtime/cargo/crate/src/runtime/cst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod terminal_kind;
pub use edge_label::EdgeLabel;
pub(crate) use lexical_context::{IsLexicalContext, LexicalContext, LexicalContextType};
pub use metaslang_cst::kinds::{
EdgeLabelExtensions, NonterminalKindExtensions, TerminalKindExtensions,
EdgeLabelExtensions, NodeKind, NonterminalKindExtensions, TerminalKindExtensions,
};
pub use nonterminal_kind::NonterminalKind;
pub use terminal_kind::TerminalKind;
Expand Down
Loading

0 comments on commit bb853b4

Please sign in to comment.