本文整理汇总了TypeScript中@masala/parser.C.letter方法的典型用法代码示例。如果您正苦于以下问题:TypeScript C.letter方法的具体用法?TypeScript C.letter怎么用?TypeScript C.letter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@masala/parser.C
的用法示例。
在下文中一共展示了C.letter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
import {Streams, F, C, N} from '@masala/parser'
import {assertEquals, assertArrayEquals, assertTrue} from '../../assert';
const helloParser = C.string("Hello")
.then(C.char(' ').rep())
.then(C.char("'")).drop()
.then(C.letter().rep()) // keeping repeated ascii letters
.then(C.char("'").drop()); // keeping previous letters
const parsing = helloParser.parse(Streams.ofString("Hello 'World'"));
// C.letter.rep() will giv a array of letters
let x = parsing.value.array();
assertArrayEquals(['W','o','r','l','d'], parsing.value.array(), "Hello World joined");
// Note that helloParser will not reach the end of the stream; it will stop at the space after People
const peopleParsing = helloParser.parse(Streams.ofString("Hello 'People' in 2017"));
assertEquals("People", peopleParsing.value.join(''), "Hello People joined");
assertTrue(peopleParsing.offset < "Hello People in 2017".length, "Bad Offset for Hello People");