Beispiel #1
0
        public void AddSugarLexem(IN token, string specialValue)
        {
            if (char.IsLetter(specialValue[0]))
            {
                throw new InvalidLexerException($"bad lexem {specialValue} :  SugarToken lexeme <{token.ToString()}>  can not start with a letter.");
            }
            NodeCallback <GenericToken> callback = (FSMMatch <GenericToken> match) =>
            {
                match.Properties[DerivedToken] = token;
                return(match);
            };

            FSMBuilder.GoTo(start);
            for (int i = 0; i < specialValue.Length; i++)
            {
                FSMBuilder.SafeTransition(specialValue[i]);
            }
            FSMBuilder.End(GenericToken.SugarToken)
            .CallBack(callback);
        }
Beispiel #2
0
        public void AddSugarLexem(IN token, BuildResult <ILexer <IN> > buildResult, string specialValue, bool isLineEnding = false)
        {
            if (char.IsLetter(specialValue[0]))
            {
                buildResult.AddError(new InitializationError(ErrorLevel.FATAL,
                                                             $"bad lexem {specialValue} :  SugarToken lexeme <{token.ToString()}>  can not start with a letter.", ErrorCodes.LEXER_SUGAR_TOKEN_CANNOT_START_WITH_LETTER));
                return;
            }

            NodeCallback <GenericToken> callback = match =>
            {
                match.Properties[DerivedToken] = token;
                return(match);
            };

            FSMBuilder.GoTo(start);
            for (var i = 0; i < specialValue.Length; i++)
            {
                FSMBuilder.SafeTransition(specialValue[i]);
            }
            FSMBuilder.End(GenericToken.SugarToken, isLineEnding)
            .CallBack(callback);
        }