/// <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)); }
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)); }
private void BuildCullAmbiguitiesCore(ParserCompiler compiler, ParserBuilder parserBuilder, IIntermediateCliManager identityManager) { bool lexicallyAmbiguousModel = compiler._GrammarSymbols.AmbiguousSymbols.Count() > 0; if (!lexicallyAmbiguousModel) { return; } this._cullAmbiguities = this._getValidSyntaxMethodInternalImpl .Parent .Methods .Add( new TypedName("CullAmbiguitiesFrom", compiler.LexicalSymbolModel.ValidSymbols), new TypedNameSeries( new TypedName("unambiguousSource", compiler.LexicalSymbolModel.ValidSymbols))); var allAmbiguities = compiler.LexicalSymbolModel.GenerateSymbolstoreVariation(new GrammarVocabulary(compiler.GrammarSymbols, compiler._GrammarSymbols.AmbiguousSymbols.ToArray()), "AllAmbiguities", string.Format("Returns a @s:{0}; value that represents all ambiguous identities.", compiler.LexicalSymbolModel.ValidSymbols.Name)); allAmbiguities.Name = "AllAmbiguities"; this._AllAmbiguitiesField = allAmbiguities; _cullAmbiguities.AccessLevel = AccessLevelModifiers.Public; }
private void CreateLengthImpl() { this._lengthImpl = this.CharStreamSegment.Properties.Add(new TypedName("Length", RuntimeCoreType.Int32, this._identityManager), true, false); this.LengthImpl.GetMethod.Return(this._EndPositionImpl.Subtract(this._StartPositionImpl)); }