本文整理汇总了TypeScript中@masala/parser.C类的典型用法代码示例。如果您正苦于以下问题:TypeScript C类的具体用法?TypeScript C怎么用?TypeScript C使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了C类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: combinator
function combinator() {
return C.letters()
.then(C.char(' '))
.then(C.lowerCase().rep())
.then(C.char(' '))
.then(C.notString('romane').rep())
.then(F.eos());
}
示例2: blank
function blank(){
return C.char(' ').rep().thenReturns(' ');
}
示例3: optAlternative
function optAlternative() {
return C.string('xyz').opt()
}
示例4: emptyTry
function emptyTry() {
return F.try(C.string('xyz'));
}
示例5:
const separator = () => C.string('---');
示例6: assertEquals
import {Streams, F, C, N} from '@masala/parser'
import {assertEquals, assertFalse, assertTrue} from '../../assert';
let response = C.char('a').rep().parse(Streams.ofString('aaaa'));
assertEquals(response.value.join(''), 'aaaa' );
assertEquals(response.offset, 4 )
assertTrue(response.isAccepted());
assertTrue(response.isConsumed());
// Partially accepted
response = C.char('a').rep().parse(Streams.ofString('aabb'));
assertEquals(response.value.join(''), 'aa' );
assertEquals(response.offset, 2 )
assertTrue(response.isAccepted());
assertFalse(response.isConsumed());
示例7: anyOperation
function anyOperation() {
return C.string('*').thenReturns(MULT)
.or(C.string('+').thenReturns(PLUS));
}
示例8: day
function day() {
return C.stringIn(['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY']);
}
示例9:
import {assertEquals, assertTrue} from '../../assert';
import {Streams, F, C, N} from '@masala/parser'
let stream= Streams.ofString('|4.6|');
const floorCombinator = C.char('|').drop()
.then(N.numberLiteral()) // we have ['|',4.6], we keep 4.6
.then(C.char('|').drop()) // we have [4.6, '|'], we keep 4.6
.map(x =>Math.floor(x));
// Parsec needs a stream of characters
let parsing = floorCombinator.parse(stream);
assertEquals( 4, parsing.value, 'Floor parsing');
示例10: B
/**
* There is recursion, and we call A with lazy. We send PARAMETERS to A
* within an array
*/
function B(aVal) {
return C.char('B').map(bVal=> aVal.join('')+'-'+bVal).or(F.lazy(A, ['a']));
}