View reason2.re
let rec firstN n l => | |
if (n === 0 || List.length l === 0) { | |
[] | |
} else { | |
let h = List.hd l; | |
let t = List.tl l; | |
List.append [h] (firstN (n - 1) t) | |
}; | |
firstN 2 [1, 2, 3, 4, 5]; /* => list int: [1, 2] */ |
View reason1.re
type result 'a = {mutable list: list 'a}; | |
let firstN (n: int) (l: list 'a) :list 'a => { | |
let result: result 'a = {list: []}; | |
let start = 0; | |
let stop = min (n - 1) (List.length l - 1); | |
for i in start to stop { | |
result.list = List.append result.list [List.nth l i] | |
}; | |
result.list |
View Number System.json
This file has been truncated, but you can view the full file.
View bnf.g4
Star = \* | |
Text = .+ | |
Grammar = Star Star (Star Text Star)* Text Star Star | |
| Star (Star Star Text Star Star)* Text Star |
View parser24.js
const here = between( | |
zeroOrMore(not(string('<here>'))), | |
between( | |
string('<here>'), | |
zeroOrMore(not(string('</here>'))), | |
string('</here>') | |
), | |
always() | |
) | |
View parser24.js
const here = between( | |
zeroOrMore(not(string('<here>'))), | |
between( | |
string('<here>'), | |
zeroOrMore(not(string('</here>'))), | |
string('</here>') | |
), | |
always() | |
) | |
View parser23.js
const between = (l, p, r) => sequence([l, p, r]).map(v => v[1]) |
View parser22.js
const not = parser => | |
new Parser(stream => | |
parser.run(stream) | |
.fold( | |
(value, s) => new Failure('not failed', stream), | |
(value, s) => | |
stream.length > 0 | |
? new Success(stream.head(), stream.move(1)) | |
: new Failure('unexpected end', stream))) |
View parser21.js
const string = str => sequence(str.split('').map(char)) |
View parser20.js
const zeroOrMore = parser => | |
new Parser(stream => | |
parser.run(stream) | |
.fold( | |
(value, s) => zeroOrMore(parser).map(rest => [value].concat(rest)).run(s), | |
(value, s) => new Success([], stream))) |