From c3fc88b703781cdb3526e3b1f5f7e2410907cbce Mon Sep 17 00:00:00 2001 From: GGG KILLER Date: Mon, 14 Sep 2020 18:26:09 -0300 Subject: [PATCH] Remove composable stuff --- GParse/Composable/Alternation.cs | 23 -------- GParse/Composable/GrammarNode.cs | 50 ---------------- GParse/Composable/GrammarNodeListContainer.cs | 49 ---------------- GParse/Composable/Negation.cs | 23 -------- GParse/Composable/NonTerminal.cs | 24 -------- GParse/Composable/Repetition.cs | 32 ---------- GParse/Composable/Sequence.cs | 23 -------- GParse/Composable/Terminal.cs | 24 -------- GParse/Lexing/Composable/CharRangeNode.cs | 32 ---------- .../Composable/ComposableLexerRuleCompiler.cs | 22 ------- .../ComposableLexerRuleInterpreter.cs | 25 -------- .../IComposableLexerRuleCompiler.cs | 19 ------ GParse/Lexing/Composable/PrefixNode.cs | 58 ------------------- 13 files changed, 404 deletions(-) delete mode 100644 GParse/Composable/Alternation.cs delete mode 100644 GParse/Composable/GrammarNode.cs delete mode 100644 GParse/Composable/GrammarNodeListContainer.cs delete mode 100644 GParse/Composable/Negation.cs delete mode 100644 GParse/Composable/NonTerminal.cs delete mode 100644 GParse/Composable/Repetition.cs delete mode 100644 GParse/Composable/Sequence.cs delete mode 100644 GParse/Composable/Terminal.cs delete mode 100644 GParse/Lexing/Composable/CharRangeNode.cs delete mode 100644 GParse/Lexing/Composable/ComposableLexerRuleCompiler.cs delete mode 100644 GParse/Lexing/Composable/ComposableLexerRuleInterpreter.cs delete mode 100644 GParse/Lexing/Composable/IComposableLexerRuleCompiler.cs delete mode 100644 GParse/Lexing/Composable/PrefixNode.cs diff --git a/GParse/Composable/Alternation.cs b/GParse/Composable/Alternation.cs deleted file mode 100644 index a435403..0000000 --- a/GParse/Composable/Alternation.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; - -namespace GParse.Composable -{ - /// - /// Represents an alternation of different possible grammar trees - /// - public class Alternation : GrammarNodeListContainer, T> - { - /// - /// The grammar nodes that compose this alternation - /// - public IReadOnlyList> GrammarNodes => this.grammarNodes; - - /// - /// Initializes an alternation - /// - /// - public Alternation ( params GrammarNode[] grammarNodes ) : base ( grammarNodes ) - { - } - } -} diff --git a/GParse/Composable/GrammarNode.cs b/GParse/Composable/GrammarNode.cs deleted file mode 100644 index 26ee7b2..0000000 --- a/GParse/Composable/GrammarNode.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Collections.Generic; - -namespace GParse.Composable -{ - /// - /// The base class for all grammar nodes - /// - public abstract class GrammarNode - { - /// - /// Creates an alternation node - /// - /// - /// - /// - public static Alternation operator | ( GrammarNode left, GrammarNode right ) - { - var nodes = new List> ( ); - if ( left is Alternation leftAlternation ) - nodes.AddRange ( leftAlternation.GrammarNodes ); - else - nodes.Add ( left ); - if ( right is Alternation rightAlternation ) - nodes.AddRange ( rightAlternation.GrammarNodes ); - else - nodes.Add ( right ); - return new Alternation ( nodes.ToArray ( ) ); - } - - /// - /// Creates a sequence node - /// - /// - /// - /// - public static Sequence operator & ( GrammarNode left, GrammarNode right ) - { - var nodes = new List> ( ); - if ( left is Sequence leftAlternation ) - nodes.AddRange ( leftAlternation.GrammarNodes ); - else - nodes.Add ( left ); - if ( right is Sequence rightAlternation ) - nodes.AddRange ( rightAlternation.GrammarNodes ); - else - nodes.Add ( right ); - return new Sequence ( nodes.ToArray ( ) ); - } - } -} diff --git a/GParse/Composable/GrammarNodeListContainer.cs b/GParse/Composable/GrammarNodeListContainer.cs deleted file mode 100644 index 9ddfb0f..0000000 --- a/GParse/Composable/GrammarNodeListContainer.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Collections.Generic; - -namespace GParse.Composable -{ - /// - /// Represents a node that contains other nodes as it's children - /// - /// - /// - public abstract class GrammarNodeListContainer : GrammarNode - where TNode : GrammarNodeListContainer - { - /// - /// The list of grammar nodes - /// - protected readonly List> grammarNodes; - - /// - /// Initializes a new - /// - /// - protected GrammarNodeListContainer ( GrammarNode[] grammarNodes ) - { - this.grammarNodes = new List> ( grammarNodes ); - } - - /// - /// Appends a node to this container's children list - /// - /// - /// - public virtual TNode AppendNode ( GrammarNode grammarNode ) - { - this.grammarNodes.Add ( grammarNode ); - return ( TNode ) this; - } - - /// - /// Appends a collection of nodes to this container's children list - /// - /// - /// - public virtual TNode AppendNodes ( IEnumerable> grammarNodes ) - { - this.grammarNodes.AddRange ( grammarNodes ); - return ( TNode ) this; - } - } -} diff --git a/GParse/Composable/Negation.cs b/GParse/Composable/Negation.cs deleted file mode 100644 index ddb08ce..0000000 --- a/GParse/Composable/Negation.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace GParse.Composable -{ - /// - /// Represents a negation of a grammar node - /// - /// - public class Negation : GrammarNode - { - /// - /// The grammar node to be negated - /// - public GrammarNode GrammarNode { get; } - - /// - /// Initializes a new grammar node - /// - /// - public Negation ( GrammarNode grammarNode ) - { - this.GrammarNode = grammarNode; - } - } -} \ No newline at end of file diff --git a/GParse/Composable/NonTerminal.cs b/GParse/Composable/NonTerminal.cs deleted file mode 100644 index 0fe0919..0000000 --- a/GParse/Composable/NonTerminal.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; - -namespace GParse.Composable -{ - /// - /// Represents a non-terminal - /// - public class NonTerminal : GrammarNode - { - /// - /// The name of the production this references - /// - public String Name { get; } - - /// - /// Initializes a non-terminal - /// - /// - public NonTerminal ( String name ) - { - this.Name = name; - } - } -} diff --git a/GParse/Composable/Repetition.cs b/GParse/Composable/Repetition.cs deleted file mode 100644 index e25be33..0000000 --- a/GParse/Composable/Repetition.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; - -namespace GParse.Composable -{ - /// - /// Represents a repetition of a grammar node - /// - /// - public class Repetition : GrammarNode - { - /// - /// The grammar node that is to be repeated - /// - public GrammarNode GrammarNode { get; } - - /// - /// The number of repetitions required and permitted. - /// - public (UInt32? Minimum, UInt32? Maximum) Repetitions { get; } - - /// - /// Creates a new repetition node - /// - /// - /// - public Repetition ( GrammarNode grammarNode, (UInt32? Minimum, UInt32? Maximum) repetitions ) - { - this.GrammarNode = grammarNode; - this.Repetitions = repetitions; - } - } -} \ No newline at end of file diff --git a/GParse/Composable/Sequence.cs b/GParse/Composable/Sequence.cs deleted file mode 100644 index ef04ec0..0000000 --- a/GParse/Composable/Sequence.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; - -namespace GParse.Composable -{ - /// - /// Represents a sequence of grammar rules - /// - public class Sequence : GrammarNodeListContainer, T> - { - /// - /// The grammar nodes that compose this sequence - /// - public IReadOnlyList> GrammarNodes => this.grammarNodes; - - /// - /// Initializes a sequence - /// - /// - public Sequence ( params GrammarNode[] grammarNodes ) : base(grammarNodes) - { - } - } -} diff --git a/GParse/Composable/Terminal.cs b/GParse/Composable/Terminal.cs deleted file mode 100644 index b7806c9..0000000 --- a/GParse/Composable/Terminal.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; - -namespace GParse.Composable -{ - /// - /// Represents a terminal - /// - public class Terminal : GrammarNode - { - /// - /// The value of the terminal - /// - public T Value { get; } - - /// - /// Initializes a new terminal - /// - /// - public Terminal ( T value ) - { - this.Value = value; - } - } -} diff --git a/GParse/Lexing/Composable/CharRangeNode.cs b/GParse/Lexing/Composable/CharRangeNode.cs deleted file mode 100644 index 84068fd..0000000 --- a/GParse/Lexing/Composable/CharRangeNode.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using GParse.Composable; - -namespace GParse.Lexing.Composable -{ - /// - /// Represents a grammar node that matches an inclusive range - /// - public class CharRangeNode : GrammarNode - { - /// - /// The first char this range will match - /// - public Char Start { get; } - - /// - /// The last char this range will match - /// - public Char End { get; } - - /// - /// Initializes this character range grammar node - /// - /// The first char this range will match - /// The last char this range will match - public CharRangeNode ( Char start, Char end ) - { - this.Start = start; - this.End = end; - } - } -} \ No newline at end of file diff --git a/GParse/Lexing/Composable/ComposableLexerRuleCompiler.cs b/GParse/Lexing/Composable/ComposableLexerRuleCompiler.cs deleted file mode 100644 index aafeea8..0000000 --- a/GParse/Lexing/Composable/ComposableLexerRuleCompiler.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection.Emit; -using System.Text; -using GParse.Composable; -using GParse.Lexing.Modules; - -namespace GParse.Lexing.Composable -{ - /// - /// A -based lexer rule compiler - /// - /// - public class ComposableLexerRuleCompiler : IComposableLexerRuleCompiler - { - /// - public ILexerModule CompileRule ( GrammarNode grammarNode ) - { - throw new NotImplementedException ( ); - } - } -} diff --git a/GParse/Lexing/Composable/ComposableLexerRuleInterpreter.cs b/GParse/Lexing/Composable/ComposableLexerRuleInterpreter.cs deleted file mode 100644 index 6d9101d..0000000 --- a/GParse/Lexing/Composable/ComposableLexerRuleInterpreter.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using GParse.Composable; -using GParse.IO; -using GParse.Lexing.Modules; - -namespace GParse.Lexing.Composable -{ - internal class ComposableLexerRuleInterpreter : ILexerModule - { - public String Name { get; } - public String Prefix { get; } - private GrammarNode RootNode { get; } - - public ComposableLexerRuleInterpreter ( String name, GrammarNode rootNode ) - { - this.Name = name; - this.Prefix = null!; - this.RootNode = rootNode; - } - - public Boolean CanConsumeNext ( IReadOnlyCodeReader reader ) => throw new NotImplementedException ( ); - - public Token ConsumeNext ( ICodeReader reader, IProgress diagnosticEmitter ) => throw new NotImplementedException ( ); - } -} \ No newline at end of file diff --git a/GParse/Lexing/Composable/IComposableLexerRuleCompiler.cs b/GParse/Lexing/Composable/IComposableLexerRuleCompiler.cs deleted file mode 100644 index 57611d4..0000000 --- a/GParse/Lexing/Composable/IComposableLexerRuleCompiler.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using GParse.Composable; -using GParse.Lexing.Modules; - -namespace GParse.Lexing.Composable -{ - /// - /// The interface for a composable rule compiler - /// - public interface IComposableLexerRuleCompiler - { - /// - /// Compiles a into a . - /// - /// - /// - ILexerModule CompileRule ( GrammarNode grammarNode ); - } -} \ No newline at end of file diff --git a/GParse/Lexing/Composable/PrefixNode.cs b/GParse/Lexing/Composable/PrefixNode.cs deleted file mode 100644 index ea18774..0000000 --- a/GParse/Lexing/Composable/PrefixNode.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Linq; -using GParse.Composable; - -namespace GParse.Lexing.Composable -{ - /// - /// Represents a sequence that defines the prefix of this rule - /// - public class PrefixNode : GrammarNode - { - private static Boolean HasPrefixNodeInTree ( GrammarNode grammarNode ) - { - return grammarNode switch - { - PrefixNode _ => true, - Sequence seq => seq.GrammarNodes.Any ( HasPrefixNodeInTree ), - Alternation alt => alt.GrammarNodes.Any ( HasPrefixNodeInTree ), - Negation neg => HasPrefixNodeInTree ( neg.GrammarNode ), - Repetition rep => HasPrefixNodeInTree ( rep.GrammarNode ), - _ => false, - }; - } - - /// - /// Returns whether a grammar node has a proper - /// - /// - /// - public static Boolean HasProperPrefixSequence ( GrammarNode grammarNode ) - { - return grammarNode switch - { - PrefixNode _ => true, - Sequence seq => seq.GrammarNodes.Count > 0 - && HasProperPrefixSequence ( seq.GrammarNodes[0] ) - && seq.GrammarNodes.Skip ( 1 ).All ( g => !HasProperPrefixSequence ( g ) ), - Alternation alt => alt.GrammarNodes.Count > 0 - && alt.GrammarNodes.All ( HasProperPrefixSequence ), - _ => false, - }; - } - - /// - /// The grammar node that represents the prefix - /// - public GrammarNode GrammarNode { get; } - - /// - /// Initializes a prefix sequence - /// - /// - public PrefixNode ( GrammarNode grammarNode ) - { - this.GrammarNode = grammarNode; - } - } -} \ No newline at end of file