UNPKG

pip-services4-expressions-node

Version:

Tokenizers, parsers and expression calculators in Node.js / ES2017

39 lines (35 loc) 1.58 kB
/** @module tokenizers */ import { ICommentState } from '../ICommentState'; import { Token } from '../Token'; import { TokenType } from '../TokenType'; import { ITokenizer } from '../ITokenizer'; import { IScanner } from '../../io/IScanner'; import { CharValidator } from '../utilities/CharValidator'; /** * A CommentState object returns a comment from a scanner. */ export class GenericCommentState implements ICommentState { protected readonly LF: number = '\r'.charCodeAt(0); protected readonly CR: number = '\n'.charCodeAt(0); /** * Either delegate to a comment-handling state, or return a token with just a slash in it. * @param scanner A textual string to be tokenized. * @param tokenizer A tokenizer class that controls the process. * @returns The next token from the top of the stream. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars public nextToken(scanner: IScanner, tokenizer: ITokenizer): Token { const line = scanner.peekLine(); const column = scanner.peekColumn(); let tokenValue = ""; let nextSymbol: number; for (nextSymbol = scanner.read(); !CharValidator.isEof(nextSymbol) && nextSymbol != this.CR && nextSymbol != this.LF; nextSymbol = scanner.read()) { tokenValue = tokenValue + String.fromCharCode(nextSymbol); } if (!CharValidator.isEof(nextSymbol)) { scanner.unread(); } return new Token(TokenType.Comment, tokenValue, line, column); } }