WIP on enum generation and solving generated errors.
This commit is contained in:
parent
434df5642a
commit
44f6ab10af
@ -1,4 +1,10 @@
|
|||||||
use crate::spec::{BooleanBuild, BuildSpec, ChildSpec, EnumBuildSpec, EnumRule, LeafEnumBuildSpec, LeafEnumRule, LeafEnumRuleBuild, LeafEnumRuleBuildChild, LeafStructBuildSpec, LeafStructChild, LeafStructChildType, SingleBooleanChildToBuild, SingleChild, SingleChildToBuild, SingleLiteralChildToBuild, SingleTypeChildToBuild, SkipChild, StructBuildSpec, VecChild, VecChildToBuild, VecTypeChildToBuild};
|
use crate::spec::{
|
||||||
|
BooleanBuild, BuildSpec, ChildSpec, EnumBuildSpec, EnumRule, LeafEnumBuildSpec, LeafEnumRule,
|
||||||
|
LeafEnumRuleBuild, LeafEnumRuleBuildChild, LeafStructBuildSpec, LeafStructChild,
|
||||||
|
LeafStructChildType, SingleBooleanChildToBuild, SingleChild, SingleChildToBuild,
|
||||||
|
SingleLiteralChildToBuild, SingleTypeChildToBuild, SkipChild, StructBuildSpec, VecChild,
|
||||||
|
VecChildToBuild, VecTypeChildToBuild,
|
||||||
|
};
|
||||||
use crate::util::make_build_fn_name;
|
use crate::util::make_build_fn_name;
|
||||||
use convert_case::{Case, Casing};
|
use convert_case::{Case, Casing};
|
||||||
use yaml_rust2::{Yaml, YamlLoader};
|
use yaml_rust2::{Yaml, YamlLoader};
|
||||||
@ -218,15 +224,13 @@ fn get_enum_rules(rule_specs: &Yaml) -> Vec<EnumRule> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_leaf_struct_child_specs(children: &Yaml) -> Vec<LeafStructChild> {
|
fn get_leaf_struct_child_specs(children: &Yaml) -> Vec<LeafStructChild> {
|
||||||
children.as_vec()
|
children
|
||||||
|
.as_vec()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|child_spec| {
|
.map(|child_spec| {
|
||||||
let (name, hash) = unwrap_single_member_hash(child_spec);
|
let (name, hash) = unwrap_single_member_hash(child_spec);
|
||||||
LeafStructChild::new(
|
LeafStructChild::new(&name, LeafStructChildType::String)
|
||||||
&name,
|
|
||||||
LeafStructChildType::String
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,13 +9,13 @@ mod util;
|
|||||||
|
|
||||||
use crate::enum_build_fn::make_enum_build_fn;
|
use crate::enum_build_fn::make_enum_build_fn;
|
||||||
use crate::leaf_enum_build_fn::make_leaf_enum_build_fn;
|
use crate::leaf_enum_build_fn::make_leaf_enum_build_fn;
|
||||||
|
use crate::leaf_struct_build_fn::make_leaf_struct_build_fn;
|
||||||
use crate::struct_build_fn::make_struct_build_fn;
|
use crate::struct_build_fn::make_struct_build_fn;
|
||||||
use crate::type_gen::make_type;
|
use crate::type_gen::make_type;
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use spec::BuildSpec;
|
use spec::BuildSpec;
|
||||||
use syn::File;
|
use syn::File;
|
||||||
use crate::leaf_struct_build_fn::make_leaf_struct_build_fn;
|
|
||||||
|
|
||||||
fn debug_built_spec(build_spec: &BuildSpec, token_stream: &TokenStream) {
|
fn debug_built_spec(build_spec: &BuildSpec, token_stream: &TokenStream) {
|
||||||
println!("*** BuildSpec ***");
|
println!("*** BuildSpec ***");
|
||||||
|
|||||||
@ -518,7 +518,7 @@ impl LeafStructChild {
|
|||||||
pub fn new(name: &str, r#type: LeafStructChildType) -> Self {
|
pub fn new(name: &str, r#type: LeafStructChildType) -> Self {
|
||||||
Self {
|
Self {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
r#type
|
r#type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,10 +2,9 @@ use crate::spec::{
|
|||||||
BooleanBuild, ChildSpec, SingleBooleanChildToBuild, SingleChildToBuild,
|
BooleanBuild, ChildSpec, SingleBooleanChildToBuild, SingleChildToBuild,
|
||||||
SingleLiteralChildToBuild, SingleTypeChildToBuild, StructBuildSpec, VecChild, VecChildToBuild,
|
SingleLiteralChildToBuild, SingleTypeChildToBuild, StructBuildSpec, VecChild, VecChildToBuild,
|
||||||
};
|
};
|
||||||
use convert_case::{Case, Casing};
|
use crate::util::make_build_pair;
|
||||||
use proc_macro2::{Ident, TokenStream};
|
use proc_macro2::{Ident, TokenStream};
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
use crate::util::make_build_pair;
|
|
||||||
|
|
||||||
fn make_vec_child_holder(vec_child: &VecChild) -> TokenStream {
|
fn make_vec_child_holder(vec_child: &VecChild) -> TokenStream {
|
||||||
let (child_ident, child_type_ident) = match vec_child.build() {
|
let (child_ident, child_type_ident) = match vec_child.build() {
|
||||||
|
|||||||
@ -102,6 +102,25 @@ fn handle_single_type_child(
|
|||||||
#child_ident: Box<#child_type_ident>
|
#child_ident: Box<#child_type_ident>
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if single_type_child.optional() {
|
||||||
|
accessors.push(quote! {
|
||||||
|
pub fn #child_ident(&self) -> Option<&#child_type_ident> {
|
||||||
|
if let Some(#child_ident) = &self.#child_ident {
|
||||||
|
Some(#child_ident.as_ref())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn #child_ident_mut(&mut self) -> Option<&mut #child_type_ident> {
|
||||||
|
if let Some(#child_ident) = &mut self.#child_ident {
|
||||||
|
Some(#child_ident.as_mut())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
accessors.push(quote! {
|
accessors.push(quote! {
|
||||||
pub fn #child_ident(&self) -> &#child_type_ident {
|
pub fn #child_ident(&self) -> &#child_type_ident {
|
||||||
self.#child_ident.as_ref()
|
self.#child_ident.as_ref()
|
||||||
@ -111,6 +130,7 @@ fn handle_single_type_child(
|
|||||||
self.#child_ident.as_mut()
|
self.#child_ident.as_mut()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_single_boolean_child(
|
fn handle_single_boolean_child(
|
||||||
|
|||||||
@ -5,6 +5,8 @@ pub mod node {
|
|||||||
pub mod build {
|
pub mod build {
|
||||||
//noinspection RsUnusedImport
|
//noinspection RsUnusedImport
|
||||||
use crate::parser::Rule;
|
use crate::parser::Rule;
|
||||||
|
//noinspection RsUnusedImport
|
||||||
|
use crate::ast::node::*;
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/src/ast/build.rs"));
|
include!(concat!(env!("OUT_DIR"), "/src/ast/build.rs"));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,14 +4,12 @@ pub struct DmModule {
|
|||||||
|
|
||||||
pub enum NamespaceVisibility {
|
pub enum NamespaceVisibility {
|
||||||
Public,
|
Public,
|
||||||
Partial {
|
Partial { visible_to_fqns: Vec<String> },
|
||||||
visible_to_fqns: Vec<String>
|
Private,
|
||||||
},
|
|
||||||
Private
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DmNamespace {
|
pub struct DmNamespace {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub dependencies: Vec<String>,
|
pub dependencies: Vec<String>,
|
||||||
pub visibility: NamespaceVisibility
|
pub visibility: NamespaceVisibility,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -415,10 +415,14 @@ InterfaceDefaultOperatorFunction:
|
|||||||
|
|
||||||
# Function Bodies
|
# Function Bodies
|
||||||
FunctionBody:
|
FunctionBody:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- FunctionAliasBody
|
- FunctionAliasBody:
|
||||||
- FunctionEqualsBody
|
child: true
|
||||||
- FunctionBlockBody
|
- FunctionEqualsBody:
|
||||||
|
child: true
|
||||||
|
- FunctionBlockBody:
|
||||||
|
child: true
|
||||||
FunctionEqualsBody:
|
FunctionEqualsBody:
|
||||||
children:
|
children:
|
||||||
- expression
|
- expression
|
||||||
@ -460,14 +464,22 @@ Member:
|
|||||||
|
|
||||||
# Statements
|
# Statements
|
||||||
Statement:
|
Statement:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- VariableDeclaration
|
- VariableDeclaration:
|
||||||
- AssignmentStatement
|
child: true
|
||||||
- ExpressionStatement
|
- AssignmentStatement:
|
||||||
- UseStatement
|
child: true
|
||||||
- IfStatement
|
- ExpressionStatement:
|
||||||
- WhileStatement
|
child: true
|
||||||
- ForStatement
|
- UseStatement:
|
||||||
|
child: true
|
||||||
|
- IfStatement:
|
||||||
|
child: true
|
||||||
|
- WhileStatement:
|
||||||
|
child: true
|
||||||
|
- ForStatement:
|
||||||
|
child: true
|
||||||
VariableDeclaration:
|
VariableDeclaration:
|
||||||
children:
|
children:
|
||||||
- let_kw:
|
- let_kw:
|
||||||
@ -701,17 +713,23 @@ ObjectIndex:
|
|||||||
children:
|
children:
|
||||||
- expression
|
- expression
|
||||||
PrimaryExpression:
|
PrimaryExpression:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- Literal
|
- Literal:
|
||||||
- FullyQualifiedName
|
child: true
|
||||||
- Closure
|
- FullyQualifiedName:
|
||||||
- ParenthesizedExpression
|
child: true
|
||||||
|
- Closure:
|
||||||
|
child: true
|
||||||
|
- ParenthesizedExpression:
|
||||||
|
child: true
|
||||||
ParenthesizedExpression:
|
ParenthesizedExpression:
|
||||||
children:
|
children:
|
||||||
- expression
|
- expression
|
||||||
|
|
||||||
# Calls
|
# Calls
|
||||||
Call:
|
Call:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- ParenthesesCall
|
- ParenthesesCall
|
||||||
- NonParenthesesCall
|
- NonParenthesesCall
|
||||||
@ -762,38 +780,46 @@ ClosureParameter:
|
|||||||
|
|
||||||
# Literals
|
# Literals
|
||||||
Literal:
|
Literal:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- NumberLiteral
|
- NumberLiteral:
|
||||||
- StringLiteral
|
child: true
|
||||||
- BooleanLiteral
|
- StringLiteral:
|
||||||
|
child: true
|
||||||
|
- BooleanLiteral:
|
||||||
|
child: true
|
||||||
NumberLiteral:
|
NumberLiteral:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- DoubleLiteral
|
- DoubleLiteral:
|
||||||
- LongLiteral
|
child: true
|
||||||
- IntLiteral
|
- LongLiteral:
|
||||||
|
child: true
|
||||||
|
- IntLiteral:
|
||||||
|
child: true
|
||||||
IntLiteral:
|
IntLiteral:
|
||||||
children:
|
children:
|
||||||
- number_base
|
- number_base
|
||||||
- literal:
|
|
||||||
build:
|
|
||||||
type: i32
|
|
||||||
LongLiteral:
|
LongLiteral:
|
||||||
children:
|
children:
|
||||||
- number_base
|
- number_base
|
||||||
- literal:
|
|
||||||
build:
|
|
||||||
type: i64
|
|
||||||
DoubleLiteral:
|
DoubleLiteral:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
type: f64
|
type: f64
|
||||||
NumberBase:
|
NumberBase:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- BinaryBase
|
- BinaryBase:
|
||||||
- HexadecimalBase
|
child: true
|
||||||
- DecimalBase
|
- HexadecimalBase:
|
||||||
|
child: true
|
||||||
|
- DecimalBase:
|
||||||
|
child: true
|
||||||
DecimalBase:
|
DecimalBase:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
@ -802,6 +828,7 @@ BinaryBase:
|
|||||||
children:
|
children:
|
||||||
- binary_digits
|
- binary_digits
|
||||||
BinaryDigits:
|
BinaryDigits:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
@ -810,15 +837,20 @@ HexadecimalBase:
|
|||||||
children:
|
children:
|
||||||
- hexadecimal_digits
|
- hexadecimal_digits
|
||||||
HexadecimalDigits:
|
HexadecimalDigits:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
type: string
|
type: string
|
||||||
StringLiteral:
|
StringLiteral:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- SingleQuoteString
|
- SingleQuoteString:
|
||||||
- DoubleQuoteString
|
child: true
|
||||||
- BacktickString
|
- DoubleQuoteString:
|
||||||
|
child: true
|
||||||
|
- BacktickString:
|
||||||
|
child: true
|
||||||
SingleQuoteString:
|
SingleQuoteString:
|
||||||
children:
|
children:
|
||||||
- string_inner:
|
- string_inner:
|
||||||
@ -832,11 +864,13 @@ DoubleQuoteString:
|
|||||||
rule: DStringExpression
|
rule: DStringExpression
|
||||||
vec: true
|
vec: true
|
||||||
StringInner:
|
StringInner:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
type: string
|
type: string
|
||||||
DStringInner:
|
DStringInner:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
@ -853,11 +887,13 @@ BacktickString:
|
|||||||
rule: DStringExpression
|
rule: DStringExpression
|
||||||
vec: true
|
vec: true
|
||||||
BacktickInner:
|
BacktickInner:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
type: string
|
type: string
|
||||||
BooleanLiteral:
|
BooleanLiteral:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
|
|||||||
@ -5,7 +5,11 @@ pub struct IndentWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl IndentWriter {
|
impl IndentWriter {
|
||||||
pub fn new(start_level: usize, indent_string: &str, out: Box<dyn std::io::Write>) -> IndentWriter {
|
pub fn new(
|
||||||
|
start_level: usize,
|
||||||
|
indent_string: &str,
|
||||||
|
out: Box<dyn std::io::Write>,
|
||||||
|
) -> IndentWriter {
|
||||||
IndentWriter {
|
IndentWriter {
|
||||||
indent_level: start_level,
|
indent_level: start_level,
|
||||||
indent_string: indent_string.to_string(),
|
indent_string: indent_string.to_string(),
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum DvmConstant {
|
pub enum DvmConstant {
|
||||||
String(String),
|
String(String),
|
||||||
Array(DvmConstantArray)
|
Array(DvmConstantArray),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -13,5 +13,5 @@ pub enum DvmConstantArray {
|
|||||||
USizes(Vec<usize>),
|
USizes(Vec<usize>),
|
||||||
Booleans(Vec<bool>),
|
Booleans(Vec<bool>),
|
||||||
Strings(Vec<String>),
|
Strings(Vec<String>),
|
||||||
Arrays(Vec<DvmConstantArray>)
|
Arrays(Vec<DvmConstantArray>),
|
||||||
}
|
}
|
||||||
@ -111,8 +111,8 @@ pub enum Instruction {
|
|||||||
},
|
},
|
||||||
Return,
|
Return,
|
||||||
DumpState {
|
DumpState {
|
||||||
message: String
|
message: String,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|||||||
@ -10,7 +10,7 @@ impl SourceCodeLocation {
|
|||||||
SourceCodeLocation {
|
SourceCodeLocation {
|
||||||
source_file_name: source_file_name.to_string(),
|
source_file_name: source_file_name.to_string(),
|
||||||
line,
|
line,
|
||||||
col
|
col,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,5 +11,5 @@ pub enum DvmType {
|
|||||||
// Other
|
// Other
|
||||||
Object,
|
Object,
|
||||||
Array,
|
Array,
|
||||||
ConstantPointer
|
ConstantPointer,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user