Skip to content

Commit

Permalink
~~~~ squash 650 changes ~~~~
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok authored and OmarTawfik committed Nov 24, 2023
1 parent 898b311 commit 23efa90
Show file tree
Hide file tree
Showing 97 changed files with 11,044 additions and 4,061 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ fn collect_trivia<'l>(parser: &'l TriviaParser, acc: &mut Vec<&'l Identifier>) {
collect_trivia(parser, acc);
}
}
TriviaParser::ZeroOrMore { parser } | TriviaParser::Optional { parser } => {
TriviaParser::OneOrMore { parser }
| TriviaParser::ZeroOrMore { parser }
| TriviaParser::Optional { parser } => {
collect_trivia(parser, acc);
}
TriviaParser::Trivia { trivia } => {
acc.push(trivia);
}
TriviaParser::EndOfInput => {}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ fn check_precedence(analysis: &mut Analysis, item: &PrecedenceItem, enablement:
let enablement = update_enablement(analysis, &enablement, &enabled);

for precedence_expression in precedence_expressions {
let PrecedenceExpression { name: _, operators } = &**precedence_expression;
let PrecedenceExpression {
name: _,
rule_name: _,
operators,
} = &**precedence_expression;

for operator in operators {
let PrecedenceOperator {
Expand Down Expand Up @@ -262,13 +266,14 @@ fn check_trivia_parser(analysis: &mut Analysis, parser: &TriviaParser, enablemen
check_trivia_parser(analysis, parser, &enablement);
}
}
TriviaParser::ZeroOrMore { parser } | TriviaParser::Optional { parser } => {
TriviaParser::OneOrMore { parser }
| TriviaParser::ZeroOrMore { parser }
| TriviaParser::Optional { parser } => {
check_trivia_parser(analysis, parser, &enablement);
}
TriviaParser::Trivia { trivia } => {
check_reference(analysis, None, trivia, &enablement, ReferenceFilter::Trivia);
}
TriviaParser::EndOfInput => {}
};
}

Expand Down
72 changes: 46 additions & 26 deletions crates/codegen/language/definition/src/model/types.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
pub use self::wrapper::*;
pub use indexmap::{IndexMap, IndexSet};

/// We want to generate all Spanned types in a single module.
/// Unfortunately, module-level (inner) attribute macros are not supported yet:
/// This is why we put the attribute on a wrapper module containing all of them, then re-export its inner contents.
/// More information: https://github.com/rust-lang/rust/issues/54726
#[codegen_language_internal_macros::derive_internals]
mod wrapper {
use super::{IndexMap, IndexSet};

use crate::model::Identifier;
use indexmap::{IndexMap, IndexSet};
use semver::Version;
use serde::Serialize;
use std::{path::PathBuf, rc::Rc};
Expand Down Expand Up @@ -61,7 +63,23 @@ mod wrapper {
Fragment { item: FragmentItem },
}

#[derive(Debug, Eq, PartialEq, Serialize)]
impl Item {
pub fn name(&self) -> &Identifier {
match self {
Item::Struct { item } => &item.name,
Item::Enum { item } => &item.name,
Item::Repeated { item } => &item.name,
Item::Separated { item } => &item.name,
Item::Precedence { item } => &item.name,
Item::Trivia { item } => &item.name,
Item::Keyword { item } => &item.name,
Item::Token { item } => &item.name,
Item::Fragment { item } => &item.name,
}
}
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct StructItem {
pub name: Identifier,

Expand All @@ -71,7 +89,7 @@ mod wrapper {
pub fields: IndexMap<Identifier, Field>,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct EnumItem {
pub name: Identifier,

Expand All @@ -80,7 +98,7 @@ mod wrapper {
pub variants: Vec<EnumVariant>,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct EnumVariant {
pub name: Identifier,

Expand All @@ -89,7 +107,7 @@ mod wrapper {
pub reference: Identifier,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct RepeatedItem {
pub name: Identifier,
pub repeated: Identifier,
Expand All @@ -99,7 +117,7 @@ mod wrapper {
pub allow_empty: Option<bool>,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct SeparatedItem {
pub name: Identifier,
pub separated: Identifier,
Expand All @@ -110,7 +128,7 @@ mod wrapper {
pub allow_empty: Option<bool>,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct PrecedenceItem {
pub name: Identifier,

Expand All @@ -120,14 +138,16 @@ mod wrapper {
pub primary_expressions: Vec<PrimaryExpression>,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct PrecedenceExpression {
pub name: Identifier,
// TODO(#638): Remove this, once we adapt the DSL v1 codegen model to the new v2 definition.
pub rule_name: Identifier,

pub operators: Vec<PrecedenceOperator>,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct PrecedenceOperator {
pub model: OperatorModel,

Expand All @@ -137,34 +157,34 @@ mod wrapper {
pub fields: IndexMap<Identifier, Field>,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
pub enum OperatorModel {
Prefix,
Postfix,
BinaryLeftAssociative,
BinaryRightAssociative,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct PrimaryExpression {
pub expression: Identifier,

pub enabled: Option<VersionSpecifier>,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct FieldsErrorRecovery {
pub terminator: Option<Identifier>,
pub delimiters: Option<FieldDelimiters>,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct FieldDelimiters {
pub open: Identifier,
pub close: Identifier,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub enum Field {
Required {
kind: FieldKind,
Expand All @@ -176,22 +196,22 @@ mod wrapper {
},
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub enum FieldKind {
NonTerminal { item: Identifier },
Terminal { items: IndexSet<Identifier> },
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub enum TriviaParser {
Sequence { parsers: Vec<TriviaParser> },
Choice { parsers: Vec<TriviaParser> },

ZeroOrMore { parser: Box<TriviaParser> },
Optional { parser: Box<TriviaParser> },
OneOrMore { parser: Box<TriviaParser> },
ZeroOrMore { parser: Box<TriviaParser> },

Trivia { trivia: Identifier },
EndOfInput,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
Expand All @@ -201,45 +221,45 @@ mod wrapper {
pub scanner: Scanner,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct KeywordItem {
pub name: Identifier,
pub identifier: Identifier,

pub definitions: Vec<KeywordDefinition>,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct KeywordDefinition {
pub enabled: Option<VersionSpecifier>,
pub reserved: Option<VersionSpecifier>,

pub value: KeywordValue,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub enum KeywordValue {
Sequence { values: Vec<KeywordValue> },
Optional { value: Box<KeywordValue> },
Choice { values: Vec<KeywordValue> },
Atom { atom: String },
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct TokenItem {
pub name: Identifier,

pub definitions: Vec<TokenDefinition>,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct TokenDefinition {
pub enabled: Option<VersionSpecifier>,

pub scanner: Scanner,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct FragmentItem {
pub name: Identifier,

Expand All @@ -248,7 +268,7 @@ mod wrapper {
pub scanner: Scanner,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub enum Scanner {
Sequence {
scanners: Vec<Scanner>,
Expand Down Expand Up @@ -284,7 +304,7 @@ mod wrapper {
},
}

#[derive(Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub enum VersionSpecifier {
Never,
From { from: Version },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ codegen_language_macros::compile!(Language(
Precedence(
name = Bar,
precedence_expressions = [
PrecedenceExpression(name = Expression1, operators = []),
PrecedenceExpression(name = Expression2, operators = []),
PrecedenceExpression(name = Expression1, operators = [])
PrecedenceExpression(name = Expression1, rule_name = X, operators = []),
PrecedenceExpression(name = Expression2, rule_name = X, operators = []),
PrecedenceExpression(name = Expression1, rule_name = X, operators = [])
],
primary_expressions = [PrimaryExpression(expression = Baz)]
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: An expression with the name 'Expression1' already exists.
--> src/fail/definitions/duplicate_expression_name/test.rs:19:53
|
19 | PrecedenceExpression(name = Expression1, operators = [])
19 | PrecedenceExpression(name = Expression1, rule_name = X, operators = [])
| ^^^^^^^^^^^
Loading

0 comments on commit 23efa90

Please sign in to comment.