move tokens to compiler module
This commit is contained in:
parent
faac093116
commit
9b7a85da99
1 changed files with 50 additions and 46 deletions
|
@ -1,6 +1,7 @@
|
||||||
@startuml "bliplib class diagram"
|
@startuml "bliplib class diagram"
|
||||||
|
|
||||||
left to right direction
|
left to right direction
|
||||||
|
skinparam linetype ortho
|
||||||
|
|
||||||
package std {
|
package std {
|
||||||
interface From<T> {
|
interface From<T> {
|
||||||
|
@ -18,6 +19,29 @@ package fasteval {
|
||||||
|
|
||||||
package parser {
|
package parser {
|
||||||
interface TokenParser<I>
|
interface TokenParser<I>
|
||||||
|
struct ParserParametters<'n, 's, 'v, I: Input + Clone + nom::Compare<I>, C: Into<char>> {
|
||||||
|
+notes: &'n [I]
|
||||||
|
+slopes: &'s HashMap<I, VariableChange>
|
||||||
|
+variables: &'v [C]
|
||||||
|
}
|
||||||
|
struct Parser<'i, 'n, 's, 'v, I: Input + Clone, C: Into<char>> {
|
||||||
|
-input: &'i I
|
||||||
|
-parametters: ParserParametters<'n, 's, 'v, I, C>
|
||||||
|
+parse_all(): Result<Vec<Box<dyn Token>>, nom::Error<nom_locate::LocatedSpan<&'i I>>>
|
||||||
|
}
|
||||||
|
struct ParserBuilder<'i, 'n, 's, 'v, I: Input + Clone, C: Into<char>> {
|
||||||
|
-input: Option<&'i I>
|
||||||
|
-notes: Option<&'n [I]>
|
||||||
|
-slopes: Option<&'s HashMap<I, VariableChange>>
|
||||||
|
-variables: Option<&'v [C]>
|
||||||
|
+input(self, input: &'i I): Self
|
||||||
|
+notes(self, notes: &'n [I]): Self
|
||||||
|
+slopes(self, slopes: &'s HashMap<I, VariableChange>): Self
|
||||||
|
+variables(self, variables: &'v [C]): Self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
package compiler {
|
||||||
interface Token {
|
interface Token {
|
||||||
-apply(&self, context: Context): Context
|
-apply(&self, context: Context): Context
|
||||||
}
|
}
|
||||||
|
@ -50,49 +74,6 @@ package parser {
|
||||||
+each_frame: VariableChange
|
+each_frame: VariableChange
|
||||||
-parser<'n, 's, 'v, I: Input + Clone + nom::Compare<I>, C: Into<char>>(parametters: ParserParametters<'n, 's, 'v, I, C>): impl TokenParser<I>
|
-parser<'n, 's, 'v, I: Input + Clone + nom::Compare<I>, C: Into<char>>(parametters: ParserParametters<'n, 's, 'v, I, C>): impl TokenParser<I>
|
||||||
}
|
}
|
||||||
Silence ..|> Token
|
|
||||||
Marker ..|> Token
|
|
||||||
Note ..|> Token
|
|
||||||
VariableChange ..|> Token
|
|
||||||
Loop ..|> Token
|
|
||||||
Tuplet ..|> Token
|
|
||||||
Slope ..|> Token
|
|
||||||
Silence --> TokenParser
|
|
||||||
Marker --> TokenParser
|
|
||||||
Note --> TokenParser
|
|
||||||
VariableChange --> TokenParser
|
|
||||||
Loop --> TokenParser
|
|
||||||
Tuplet --> TokenParser
|
|
||||||
Slope --> TokenParser
|
|
||||||
struct ParserParametters<'n, 's, 'v, I: Input + Clone + nom::Compare<I>, C: Into<char>> {
|
|
||||||
+notes: &'n [I]
|
|
||||||
+slopes: &'s HashMap<I, VariableChange>
|
|
||||||
+variables: &'v [C]
|
|
||||||
}
|
|
||||||
Loop --> ParserParametters
|
|
||||||
Tuplet --> ParserParametters
|
|
||||||
Slope --> ParserParametters
|
|
||||||
struct Parser<'i, 'n, 's, 'v, I: Input + Clone, C: Into<char>> {
|
|
||||||
-input: &'i I
|
|
||||||
-parametters: ParserParametters<'n, 's, 'v, I, C>
|
|
||||||
+parse_all(): Result<Vec<Box<dyn Token>>, nom::Error<nom_locate::LocatedSpan<&'i I>>>
|
|
||||||
}
|
|
||||||
struct ParserBuilder<'i, 'n, 's, 'v, I: Input + Clone, C: Into<char>> {
|
|
||||||
-input: Option<&'i I>
|
|
||||||
-notes: Option<&'n [I]>
|
|
||||||
-slopes: Option<&'s HashMap<I, VariableChange>>
|
|
||||||
-variables: Option<&'v [C]>
|
|
||||||
+input(self, input: &'i I): Self
|
|
||||||
+notes(self, notes: &'n [I]): Self
|
|
||||||
+slopes(self, slopes: &'s HashMap<I, VariableChange>): Self
|
|
||||||
+variables(self, variables: &'v [C]): Self
|
|
||||||
}
|
|
||||||
Token --> Parser
|
|
||||||
Parser --> VariableChange
|
|
||||||
ParserBuilder --> VariableChange
|
|
||||||
}
|
|
||||||
|
|
||||||
package compiler {
|
|
||||||
struct Context {
|
struct Context {
|
||||||
+result: Vec<f64>
|
+result: Vec<f64>
|
||||||
+variables: HashMap<char, f64>
|
+variables: HashMap<char, f64>
|
||||||
|
@ -103,6 +84,29 @@ package compiler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compiler.Silence ..|> Token
|
||||||
|
compiler.Marker ..|> Token
|
||||||
|
compiler.Note ..|> Token
|
||||||
|
compiler.VariableChange ..|> Token
|
||||||
|
compiler.Loop ..|> Token
|
||||||
|
compiler.Tuplet ..|> Token
|
||||||
|
compiler.Slope ..|> Token
|
||||||
|
compiler.Token --> parser.Parser
|
||||||
|
parser.Parser --> VariableChange
|
||||||
|
parser.ParserBuilder --> VariableChange
|
||||||
|
|
||||||
|
compiler.Loop --> ParserParametters
|
||||||
|
compiler.Tuplet --> ParserParametters
|
||||||
|
compiler.Slope --> ParserParametters
|
||||||
|
|
||||||
|
compiler.Silence --> TokenParser
|
||||||
|
compiler.Marker --> TokenParser
|
||||||
|
compiler.Note --> TokenParser
|
||||||
|
compiler.VariableChange --> TokenParser
|
||||||
|
compiler.Loop --> TokenParser
|
||||||
|
compiler.Tuplet --> TokenParser
|
||||||
|
compiler.Slope --> TokenParser
|
||||||
|
|
||||||
interface "From<ParserBuilder>" as from_parserbuilder
|
interface "From<ParserBuilder>" as from_parserbuilder
|
||||||
interface "nom::Parser<nom_locate::LocatedSpan<&'i I>>" as nomparser_locatedspan
|
interface "nom::Parser<nom_locate::LocatedSpan<&'i I>>" as nomparser_locatedspan
|
||||||
|
|
||||||
|
@ -114,9 +118,9 @@ parser.Parser --> nomparser_locatedspan
|
||||||
parser.Parser ..|> from_parserbuilder
|
parser.Parser ..|> from_parserbuilder
|
||||||
parser.TokenParser --|> nomparser_locatedspan: Output = Self, Error = nom::Err<nom::Error<nom_locate::LocatedSpan<&'i I>
|
parser.TokenParser --|> nomparser_locatedspan: Output = Self, Error = nom::Err<nom::Error<nom_locate::LocatedSpan<&'i I>
|
||||||
nomparser_locatedspan ..|> parser.TokenParser: for any T
|
nomparser_locatedspan ..|> parser.TokenParser: for any T
|
||||||
parser.Slope --> parser.VariableChange
|
compiler.Slope --> compiler.VariableChange
|
||||||
parser.Token --> compiler.Context
|
compiler.Token --> compiler.Context
|
||||||
VariableChange --> Instruction
|
compiler.VariableChange --> Instruction
|
||||||
Context --> Instruction
|
Context --> Instruction
|
||||||
|
|
||||||
@enduml
|
@enduml
|
Loading…
Add table
Add a link
Reference in a new issue