Ejemplo n.º 1
0
        /// <summary>
        /// Handles construction of the elements yielded by the
        /// <see cref="ParserBuilder"/> with the <paramref name="input"/>
        /// provided.
        /// </summary>
        /// <param name="input">The <see cref="Tuple{T1, T2, T3}"/> which provides the
        /// <see cref="ParserCompiler"/>, <see cref="TokenSymbolBuilder"/> and
        /// <see cref="IIntermediateAssembly"/> necessary to perform the operation.</param>
        /// <returns>A <see cref="Tuple{T1, T2, T3}"/> which yields the
        /// <see cref="IIntermediateInterfaceType"/>, <see cref="IIntermediateClassType"/>
        /// for the result parser of the language, and
        /// <see cref="LexerBuilder"/> of the language which denotes the class
        /// and interface of the tokenizer.</returns>
        public Tuple <IIntermediateInterfaceType, IIntermediateClassType, LexerBuilder> Build(Tuple <ParserCompiler, TokenSymbolBuilder, IIntermediateAssembly, RegularLanguageDFAState> input)
        {
            this.compiler            = input.Item1;
            this._tokenSymbolBuilder = input.Item2;
            this._assembly           = input.Item3;
            this._identityManager    = (IIntermediateCliManager)this._assembly.IdentityManager;
            this._parserInterface    = _assembly.DefaultNamespace.Parts.Add().Interfaces.Add("I{0}", compiler.Source.Options.ParserName);
            this._parserClass        = _assembly.DefaultNamespace.Parts.Add().Classes.Add(compiler.Source.Options.ParserName);
            this._parserClass.Assembly.ScopeCoercions.Add("System.Linq");

            this._genericSymbolStreamBuilder = new GenericSymbolStreamBuilder();
            this._symbolStreamBuilder        = new SymbolStreamBuilder();
            this._lexerBuilder                = new LexerBuilder();
            this._parserClass.AccessLevel     = AccessLevelModifiers.Internal;
            this._parserInterface.AccessLevel = AccessLevelModifiers.Public;
            this._lexerCore                                 = input.Item4;
            this._parserState                               = this._parserClass.Fields.Add(new TypedName("_state", _assembly.IdentityManager.ObtainTypeReference(RuntimeCoreType.Int32)));
            this._parserState.AccessLevel                   = AccessLevelModifiers.Private;
            this._parserStateProp                           = this._parserInterface.Properties.Add(new TypedName("State", this._parserState.FieldType), true, false);
            this._parserStatePropImpl                       = this._parserClass.Properties.Add(new TypedName("State", this._parserState.FieldType), true, true);
            this._parserStatePropImpl.AccessLevel           = AccessLevelModifiers.Public;
            this._parserStatePropImpl.SetMethod.AccessLevel = AccessLevelModifiers.Private;
            this._parserStatePropImpl.GetMethod.Return(this._parserState.GetReference());
            this._parserStatePropImpl.SetMethod.Assign(this._parserState.GetReference(), this._parserStatePropImpl.SetMethod.ValueParameter.GetReference());
            this._parserClass.ImplementedInterfaces.ImplementInterfaceQuick(this._parserInterface);
            return(Tuple.Create(this.ParserInterface, this.ParserClass, this._lexerBuilder));
        }
Ejemplo n.º 2
0
        public Tuple <IIntermediateClassType, IIntermediateInterfaceType> Build(Tuple <ParserCompiler, RuleSymbolBuilder, IIntermediateAssembly> input)
        {
            this.compiler     = input.Item1;
            this.commonSymbol = input.Item2;
            this.assembly     = input.Item3;
            INamespaceDeclaration targetSpace;
            var targetSpaceName = TypeSystemIdentifiers.GetDeclarationIdentifier(string.Format("{0}.Cst", this.assembly.DefaultNamespace.FullName));

            if (!assembly.Namespaces.PathExists(targetSpaceName.Name))
            {
                targetSpace = this.assembly.DefaultNamespace.Namespaces.Add("Cst");
            }
            else
            {
                targetSpace = this.assembly.DefaultNamespace.Namespaces[targetSpaceName];
            }
            var mutableTargetSpace = (IIntermediateNamespaceDeclaration)targetSpace;

            this.resultInterface         = mutableTargetSpace.Parts.Add().Interfaces.Add("I{0}Rule", compiler.Source.Options.AssemblyName);
            this.resultClass             = mutableTargetSpace.Parts.Add().Classes.Add("{0}RuleBase", compiler.Source.Options.AssemblyName);
            this.resultClass.AccessLevel = AccessLevelModifiers.Internal;
            this.resultClass.ImplementedInterfaces.ImplementInterfaceQuick(resultInterface);
            this.resultInterface.AccessLevel = AccessLevelModifiers.Public;
            this.interfaceContext            = this.BuildContext();
            this.interfaceParent             = this.BuildParent();
            this.classContextField           = this.BuildClassContextField();
            this.classParentField            = this.BuildClassParentField();
            this.classContext = BuildClassContext();
            this.classParent  = BuildClassParent();
            this.resultClass.SpecialModifier = SpecialClassModifier.Abstract;
            return(Tuple.Create(resultClass, resultInterface));
        }
Ejemplo n.º 3
0
        public IIntermediateInterfaceType Build(Tuple <ParserCompiler, GrammarVocabularyModelBuilder, IIntermediateAssembly> input)
        {
            this.compiler        = input.Item1;
            this.grammarModel    = input.Item2;
            this.initialAssembly = input.Item3;

            var result = initialAssembly.DefaultNamespace.Parts.Add().Interfaces.Add("I{0}Symbol", this.compiler.Source.Options.AssemblyName);

            this.startTokenIndex        = BuildStartTokenIndex(result);
            this.tokenCount             = result.Properties.Add(new TypedName("TokenCount", RuntimeCoreType.Int32, initialAssembly.IdentityManager, initialAssembly), true, false);
            this.identity               = result.Properties.Add(new TypedName("Identity", grammarModel.IdentityEnum), true, false);
            this.length                 = result.Properties.Add(new TypedName("Length", RuntimeCoreType.Int32, initialAssembly.IdentityManager, initialAssembly), true, false);
            this.tokenCount.SummaryText = string.Format("Returns the @s:Int32; value denoting the number of tokens consumed by the @s:{0};", result.Name);
            this.identity.SummaryText   = string.Format("Returns the @s:{0}; value denoting the identity represented by the @s:{1};", grammarModel.IdentityEnum.Name, result.Name);
            this.identity.RemarksText   = string.Format("Yields @s:{0}.None; when the symbol represents a @s:I{1}ProjectionContext;.", grammarModel.IdentityEnum.Name, this.compiler.Source.Options.AssemblyName);
            this.length.SummaryText     = string.Format("Returns the @s:UInt64; value which denotes the length, in characters, represented by the @s:{0};.", result.Name);
            result.AccessLevel          = AccessLevelModifiers.Public;
            this.result                 = result;
            return(result);
        }
Ejemplo n.º 4
0
 private void CreateLength()
 {
     this._length = this.ICharStreamSegment.Properties.Add(new TypedName("Length", RuntimeCoreType.Int32, this._identityManager), true, false);
 }