本文整理汇总了TypeScript中@masala/parser.C.string方法的典型用法代码示例。如果您正苦于以下问题:TypeScript C.string方法的具体用法?TypeScript C.string怎么用?TypeScript C.string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@masala/parser.C
的用法示例。
在下文中一共展示了C.string方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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");
示例2: optAlternative
function optAlternative() {
return C.string('xyz').opt()
}
示例3: combinator
function combinator() {
return F.startWith('hello: ')
.then(F.moveUntil('brown'))
.then(C.string('brown'))
.then(F.dropTo('dog'))
}
示例4: emptyTry
function emptyTry() {
return F.try(C.string('xyz'));
}
示例5:
const separator = () => C.string('---');
示例6: plusOperation
function plusOperation() {
return C.string('+').thenReturns(PLUS)
}
示例7: andOperation
function andOperation() {
return C.string('*').thenReturns(MULT)
}
示例8: anyOperation
function anyOperation() {
return C.string('*').thenReturns(MULT)
.or(C.string('+').thenReturns(PLUS));
}