protected override ISyntaxParser <IN, OUT> BuildSyntaxParser(ParserConfiguration <IN, OUT> conf, ParserType parserType, string rootRule) { ISyntaxParser <IN, OUT> parser = null; switch (parserType) { case ParserType.LL_RECURSIVE_DESCENT: { parser = new RecursiveDescentSyntaxParser <IN, OUT>(conf, rootRule); break; } case ParserType.EBNF_LL_RECURSIVE_DESCENT: { parser = new EBNFRecursiveDescentSyntaxParser <IN, OUT>(conf, rootRule); break; } default: { parser = null; break; } } return(parser); }
/// <summary> /// 设置语法分析器 /// <para>只有在分析线程完成分析工作且要赋的值不为null时才会更改此属性</para> /// </summary> /// <param name="syntaxParser"></param> public void SetSyntaxParser(ISyntaxParser <TEnumTokenType, TEnumVType, TTreeNodeValue> syntaxParser) { if (syntaxParser != null && this.m_SourceCodeWatchdog.NotDealtCount() == 0) { m_SyntaxParser = syntaxParser; } }
/// <summary> /// Initializes a new instance of the <see cref="TextProcessor" /> class. /// </summary> public TextProcessor(ISyntaxParser syntaxParser, IExpressionScorer expressionScorer, ITextSplitter textSplitter = null) { SyntaxParser = syntaxParser ?? throw new ArgumentNullException(nameof(syntaxParser)); ExpressionScorer = expressionScorer ?? throw new ArgumentNullException(nameof(expressionScorer)); TextSplitter = textSplitter; CommandProcessors = new List <ICommandProcessor>(); TextPreprocessors = new List <ITextPreprocessor>(); }
public GeneratorViewModel(IOutputGenerator generator, ISyntaxParser syntaxParser) { _generator = generator; SyntaxParser = syntaxParser; LinesPerRecord = 1; Delimiter = @"[\s]+"; }
/// <summary> /// Initializes a new instance of the <see cref="TextcMessageReceiverBuilder"/> class. /// </summary> /// <param name="clientBuilder">The client builder.</param> /// <param name="outputProcessor">The output processor.</param> /// <param name="syntaxParser">The syntax parser.</param> /// <param name="expressionScorer">The expression scorer.</param> /// <param name="cultureProvider">The culture provider.</param> public TextcMessageReceiverBuilder( MessagingHubClientBuilder clientBuilder, IOutputProcessor outputProcessor = null, ISyntaxParser syntaxParser = null, IExpressionScorer expressionScorer = null, ICultureProvider cultureProvider = null) : this(clientBuilder.Build(), outputProcessor, syntaxParser, expressionScorer, cultureProvider) { }
/// <summary> /// Sets the text parser that will be used to parse the query string, it cannot /// be <c>null</c>. /// </summary> /// <param name="syntaxParser">the text parser that will be used to parse the query string</param> /// <seealso cref="SyntaxParser"/> /// <seealso cref="ISyntaxParser"/> public virtual void SetSyntaxParser(ISyntaxParser syntaxParser) { if (syntaxParser == null) { throw new ArgumentException("textParser should not be null!"); } this.syntaxParser = syntaxParser; }
/// <summary> /// Defines a syntax parser to be used by the instance of <see cref="TextProcessor"/> for the current <see cref="TextcMessageReceiver"/>. /// </summary> /// <param name="syntaxParser">The syntax parser instance.</param> /// <returns></returns> public TextcMessageReceiverBuilder WithSyntaxParser(ISyntaxParser syntaxParser) { if (syntaxParser == null) { throw new ArgumentNullException(nameof(syntaxParser)); } _syntaxParser = syntaxParser; return(this); }
public override BuildResult <Parser <IN, OUT> > BuildParser(object parserInstance, ParserType parserType, string rootRule) { RuleParser <IN> ruleparser = new RuleParser <IN>(); ParserBuilder <EbnfToken, GrammarNode <IN> > builder = new ParserBuilder <EbnfToken, GrammarNode <IN> >(); Parser <EbnfToken, GrammarNode <IN> > grammarParser = builder.BuildParser(ruleparser, ParserType.LL_RECURSIVE_DESCENT, "rule").Result; BuildResult <Parser <IN, OUT> > result = new BuildResult <Parser <IN, OUT> >(); ParserConfiguration <IN, OUT> configuration = null; try { configuration = ExtractEbnfParserConfiguration(parserInstance.GetType(), grammarParser); configuration.StartingRule = rootRule; } catch (Exception e) { result.AddError(new ParserInitializationError(ErrorLevel.ERROR, e.Message)); return(result); } ISyntaxParser <IN, OUT> syntaxParser = BuildSyntaxParser(configuration, parserType, rootRule); SyntaxTreeVisitor <IN, OUT> visitor = null; if (parserType == ParserType.LL_RECURSIVE_DESCENT) { new SyntaxTreeVisitor <IN, OUT>(configuration, parserInstance); } else if (parserType == ParserType.EBNF_LL_RECURSIVE_DESCENT) { visitor = new EBNFSyntaxTreeVisitor <IN, OUT>(configuration, parserInstance); } Parser <IN, OUT> parser = new Parser <IN, OUT>(syntaxParser, visitor); parser.Configuration = configuration; var lexerResult = BuildLexer(); if (lexerResult.IsError) { result.AddErrors(lexerResult.Errors); } else { parser.Lexer = lexerResult.Result; } parser.Instance = parserInstance; result.Result = parser; return(result); }
/// <summary> /// Creates a query parser helper object using the specified configuration, /// text parser, processor and builder. /// </summary> /// <param name="queryConfigHandler">the query configuration handler that will be initially set to this helper</param> /// <param name="syntaxParser">the text parser that will be initially set to this helper</param> /// <param name="processor">the query processor that will be initially set to this helper</param> /// <param name="builder">the query builder that will be initially set to this helper</param> /// <seealso cref="IQueryNodeProcessor"/> /// <seealso cref="ISyntaxParser"/> /// <seealso cref="IQueryBuilder{TQuery}"/> /// <seealso cref="Config.QueryConfigHandler"/> public QueryParserHelper(QueryConfigHandler queryConfigHandler, ISyntaxParser syntaxParser, IQueryNodeProcessor processor, IQueryBuilder <TQuery> builder) { this.syntaxParser = syntaxParser; this.config = queryConfigHandler; this.processor = processor; this.builder = builder; if (processor != null) { processor.SetQueryConfigHandler(queryConfigHandler); } }
/// <summary> /// 调用本候选式函数包含的所有委托 /// </summary> /// <param name="treeNode"></param> /// <param name="parser"></param> /// <returns></returns> public SyntaxTree <TEnumTokenType, TEnumVType, TTreeNodeValue> Call( SyntaxTree <TEnumTokenType, TEnumVType, TTreeNodeValue> treeNode, ISyntaxParser <TEnumTokenType, TEnumVType, TTreeNodeValue> parser) { if (this.m_CandidateFunc != null) { var result = this.m_CandidateFunc(treeNode, parser); return(result); } else { return(null); } }
/// <summary> /// Initializes a new instance of the <see cref="TextProcessor" /> class. /// </summary> public TextProcessor(ISyntaxParser syntaxParser, IExpressionScorer expressionScorer) { if (syntaxParser == null) throw new ArgumentNullException(nameof(syntaxParser)); if (expressionScorer == null) throw new ArgumentNullException(nameof(expressionScorer)); SyntaxParser = syntaxParser; ExpressionScorer = expressionScorer; _commandProcessors = new List<ICommandProcessor>(); _textPreprocessors = new List<ITextPreprocessor>(); _synchronizationToken = new SynchronizationToken(); CommandProcessors = new SynchronizedCollectionWrapper<ICommandProcessor>(_commandProcessors, _synchronizationToken); TextPreprocessors = new SynchronizedCollectionWrapper<ITextPreprocessor>(_textPreprocessors, _synchronizationToken); }
/// <summary> /// Initializes a new instance of the <see cref="TextcMessageReceiverBuilder"/> class. /// </summary> /// <param name="sender">The sender.</param> /// <param name="outputProcessor">The output processor.</param> /// <param name="syntaxParser">The syntax parser.</param> /// <param name="expressionScorer">The expression scorer.</param> /// <param name="cultureProvider">The culture provider.</param> public TextcMessageReceiverBuilder( IMessagingHubSender sender, IOutputProcessor outputProcessor = null, ISyntaxParser syntaxParser = null, IExpressionScorer expressionScorer = null, ICultureProvider cultureProvider = null) { _sender = sender; _outputProcessor = outputProcessor ?? new MessageOutputProcessor(sender); _syntaxParser = syntaxParser ?? new SyntaxParser(); _expressionScorer = expressionScorer ?? new RatioExpressionScorer(); _cultureProvider = cultureProvider ?? new DefaultCultureProvider(CultureInfo.InvariantCulture); _commandProcessorFactories = new List <Func <IOutputProcessor, ICommandProcessor> >(); _textPrePreprocessors = new List <ITextPreprocessor>(); }
/// <summary> /// Builds a parser (lexer, syntax parser and syntax tree visitor) according to a parser definition instance /// </summary> /// <typeparam name="IN"></typeparam> /// <param name="parserInstance"> a parser definition instance , containing /// [Reduction] methods for grammar rules /// <param name="parserType">a ParserType enum value stating the analyser type (LR, LL ...) for now only LL recurive descent parser available </param> /// <param name="rootRule">the name of the root non terminal of the grammar</param> /// <returns></returns> public virtual BuildResult <Parser <IN, OUT> > BuildParser(object parserInstance, ParserType parserType, string rootRule) { Parser <IN, OUT> parser = null; BuildResult <Parser <IN, OUT> > result = new BuildResult <Parser <IN, OUT> >(); if (parserType == ParserType.LL_RECURSIVE_DESCENT) { ParserConfiguration <IN, OUT> configuration = ExtractParserConfiguration(parserInstance.GetType()); configuration.StartingRule = rootRule; ISyntaxParser <IN, OUT> syntaxParser = BuildSyntaxParser(configuration, parserType, rootRule); SyntaxTreeVisitor <IN, OUT> visitor = new SyntaxTreeVisitor <IN, OUT>(configuration, parserInstance); parser = new Parser <IN, OUT>(syntaxParser, visitor); var lexerResult = BuildLexer(); parser.Lexer = lexerResult.Result; if (lexerResult.IsError) { result.AddErrors(lexerResult.Errors); } parser.Instance = parserInstance; parser.Configuration = configuration; result.Result = parser; } else if (parserType == ParserType.EBNF_LL_RECURSIVE_DESCENT) { EBNFParserBuilder <IN, OUT> builder = new EBNFParserBuilder <IN, OUT>(); result = builder.BuildParser(parserInstance, ParserType.EBNF_LL_RECURSIVE_DESCENT, rootRule); } parser = result.Result; if (!result.IsError) { var expressionResult = parser.BuildExpressionParser(result, rootRule); if (expressionResult.IsError) { result.AddErrors(expressionResult.Errors); } result.Result.Configuration = expressionResult.Result; result = CheckParser(result); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="TextProcessor" /> class. /// </summary> public TextProcessor(ISyntaxParser syntaxParser, IExpressionScorer expressionScorer) { if (syntaxParser == null) { throw new ArgumentNullException(nameof(syntaxParser)); } if (expressionScorer == null) { throw new ArgumentNullException(nameof(expressionScorer)); } SyntaxParser = syntaxParser; ExpressionScorer = expressionScorer; _commandProcessors = new List <ICommandProcessor>(); _textPreprocessors = new List <ITextPreprocessor>(); _synchronizationToken = new SynchronizationToken(); CommandProcessors = new SynchronizedCollectionWrapper <ICommandProcessor>(_commandProcessors, _synchronizationToken); TextPreprocessors = new SynchronizedCollectionWrapper <ITextPreprocessor>(_textPreprocessors, _synchronizationToken); }
public TemplateEvaluator(ICSharpEvaluator evaluator, ISyntaxParser syntaxParser) { _evaluator = evaluator; _syntaxParser = syntaxParser; }
public SlidingTextProcessor(ISyntaxParser syntaxParser, IExpressionScorer expressionScorer, ITextSplitter textSplitter = null) : base(syntaxParser, expressionScorer, textSplitter) { }
public Parser(ISyntaxParser <IN, OUT> syntaxParser, SyntaxTreeVisitor <IN, OUT> visitor) { SyntaxParser = syntaxParser; Visitor = visitor; }
/// <summary> /// Sets the text parser that will be used to parse the query string, it cannot /// be <c>null</c>. /// </summary> /// <param name="syntaxParser">the text parser that will be used to parse the query string</param> /// <seealso cref="SyntaxParser"/> /// <seealso cref="ISyntaxParser"/> public virtual void SetSyntaxParser(ISyntaxParser syntaxParser) { this.syntaxParser = syntaxParser ?? throw new ArgumentNullException(nameof(syntaxParser), "textParser should not be null!"); }
/// <summary>Initializes a new instance</summary> public DectectorTextC(ISyntaxParser syntaxParser) { SyntaxParser = syntaxParser ?? throw new ArgumentNullException(nameof(syntaxParser)); CommandProcessors = new List <ICommandProcessor>(); }
/// <summary> /// Sets the text parser that will be used to parse the query string, it cannot /// be <c>null</c>. /// </summary> /// <param name="syntaxParser">the text parser that will be used to parse the query string</param> /// <seealso cref="SyntaxParser"/> /// <seealso cref="ISyntaxParser"/> public virtual void SetSyntaxParser(ISyntaxParser syntaxParser) { this.syntaxParser = syntaxParser ?? throw new ArgumentNullException(nameof(syntaxParser), "textParser should not be null!"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentNullException (.NET convention) }