當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript C.char方法代碼示例

本文整理匯總了TypeScript中@masala/parser.C.char方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript C.char方法的具體用法?TypeScript C.char怎麽用?TypeScript C.char使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@masala/parser.C的用法示例。


在下文中一共展示了C.char方法的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());
}
開發者ID:d-plaindoux,項目名稱:parsec,代碼行數:8,代碼來源:letter-letterAs.ts

示例2: a

function a(){
    return C.char('a');
}
開發者ID:d-plaindoux,項目名稱:parsec,代碼行數:3,代碼來源:nop-any-eos.ts

示例3:

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");

開發者ID:d-plaindoux,項目名稱:parsec,代碼行數:24,代碼來源:hello-something.ts

示例4: blank

function blank(){
    return C.char(' ').rep().thenReturns(' ');
}
開發者ID:d-plaindoux,項目名稱:parsec,代碼行數:3,代碼來源:try-with-no-or.ts

示例5: 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());
開發者ID:d-plaindoux,項目名稱:parsec,代碼行數:16,代碼來源:response.ts

示例6: assertArrayEquals

import {C, F, Streams} from '@masala/parser'


import{assertArrayEquals, assertEquals, assertTrue} from './assert';

let stream = Streams.ofString('ab');
let parser = C.char('a');
let arrayParser = parser.then(C.char('b'));
let parsing = arrayParser.parse(stream);

assertArrayEquals(['a', 'b'], parsing.value) ; //compiling, types are almost OK


parser = C.char('a');

let charParsing = parser.parse(Streams.ofString('a'));
let charParsingValue = charParsing.value;
assertTrue(charParsingValue === 'a');


let singleParsing = parser.parse(stream);
assertTrue( 'a' === singleParsing.value); //compiling, types are almost OK


parser = C.char('a');
singleParsing = parser.parse(stream);
assertEquals( 'a' , singleParsing.value); //compiling, types are almost OK
開發者ID:d-plaindoux,項目名稱:parsec,代碼行數:27,代碼來源:test.ts

示例7: assertEquals

import {Streams, F, C, N} from '@masala/parser'
import {assertEquals} from '../../assert';


/**
 * Created by Nicolas Zozol on 05/11/2017.
 */
const stream = Streams.ofString('abc');
const charsParser = C.char('a')
    .then(C.char('b'))
    .then(C.char('c'))
    .then(F.eos().drop()); // End Of Stream ; droping its value, just checking it's here
let charsParsing = charsParser.parse(stream);
assertEquals('abc', charsParsing.value.join(''), 'Chars parsing');

開發者ID:d-plaindoux,項目名稱:parsec,代碼行數:14,代碼來源:chars.ts

示例8:

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');

開發者ID:d-plaindoux,項目名稱:parsec,代碼行數:16,代碼來源:floor.ts

示例9: A

/**
 * A gives its VALUE to B using flatMap
 */
function A(char){
    return C.char(char.toUpperCase()).rep().flatMap(B);
}
開發者ID:d-plaindoux,項目名稱:parsec,代碼行數:6,代碼來源:transmission.ts

示例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']));
}
開發者ID:d-plaindoux,項目名稱:parsec,代碼行數:7,代碼來源:transmission.ts


注:本文中的@masala/parser.C.char方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。