public void Word_Lexer_State_BuiltIn_Tokens_As_Usual_Words() { string code = "Лев СтрДлина Прав"; var iterator = new SourceCodeIterator(code); var state = new WordLexerState(); iterator.MoveToContent(); var lexem = state.ReadNextLexem(iterator); Assert.True(lexem.Type == LexemType.Identifier); Assert.True(lexem.Content == "Лев"); Assert.True(lexem.Token == Token.NotAToken); iterator.MoveToContent(); lexem = state.ReadNextLexem(iterator); Assert.True(lexem.Type == LexemType.Identifier); Assert.True(lexem.Content == "СтрДлина"); Assert.True(lexem.Token == Token.NotAToken); iterator.MoveToContent(); lexem = state.ReadNextLexem(iterator); Assert.True(lexem.Type == LexemType.Identifier); Assert.True(lexem.Content == "Прав"); Assert.True(lexem.Token == Token.NotAToken); }
public void Identifier_LexerState_Works_Fine() { string code = " \ndddddd-"; var iterator = new SourceCodeIterator(code); var state = new WordLexerState(); iterator.MoveToContent(); var lexem = state.ReadNextLexem(iterator); Assert.True(lexem.Type == LexemType.Identifier); Assert.True(lexem.Content == "dddddd"); }
public override Lexem ReadNextLexem(SourceCodeIterator iterator) { iterator.MoveNext(); if (!iterator.MoveToContent()) { throw CreateExceptionOnCurrentLine(MESSAGE_ANNOTATION_EXPECTED, iterator); } if (!char.IsLetter(iterator.CurrentSymbol)) { throw CreateExceptionOnCurrentLine(MESSAGE_ANNOTATION_EXPECTED, iterator); } var lexem = _wordExtractor.ReadNextLexem(iterator); lexem.Type = LexemType.Annotation; return(lexem); }
public void Word_Literals_Processed_Correctly() { string code; SourceCodeIterator iterator; Lexem lex; WordLexerState state = new WordLexerState(); code = " Истина Ложь Неопределено Null True False Undefined"; iterator = new SourceCodeIterator(code); iterator.MoveToContent(); lex = state.ReadNextLexem(iterator); Assert.Equal(LexemType.BooleanLiteral, lex.Type); Assert.Equal("Истина", lex.Content); iterator.MoveToContent(); lex = state.ReadNextLexem(iterator); Assert.True(lex.Type == LexemType.BooleanLiteral); Assert.Equal("Ложь", lex.Content); iterator.MoveToContent(); lex = state.ReadNextLexem(iterator); Assert.True(lex.Type == LexemType.UndefinedLiteral); Assert.Equal("Неопределено", lex.Content); iterator.MoveToContent(); lex = state.ReadNextLexem(iterator); Assert.True(lex.Type == LexemType.NullLiteral); Assert.Equal("Null", lex.Content); iterator.MoveToContent(); lex = state.ReadNextLexem(iterator); Assert.True(lex.Type == LexemType.BooleanLiteral); Assert.Equal("True", lex.Content); iterator.MoveToContent(); lex = state.ReadNextLexem(iterator); Assert.True(lex.Type == LexemType.BooleanLiteral); Assert.Equal("False", lex.Content); iterator.MoveToContent(); lex = state.ReadNextLexem(iterator); Assert.True(lex.Type == LexemType.UndefinedLiteral); Assert.Equal("Undefined", lex.Content); }