本文整理匯總了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));
}