10.02.2013 Views

Foundations of Software - LAMP - EPFL

Foundations of Software - LAMP - EPFL

Foundations of Software - LAMP - EPFL

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Result Conversion<br />

The parser P ˆˆ f succeeds iff P succeeds. In that case it returns the<br />

result <strong>of</strong> applying f to the result <strong>of</strong> P .<br />

def ˆˆ [U](f : T ⇒ U) = new Parser[U] {<br />

def apply(in : Input) = Parser.this(in) match {<br />

case Success(x, in1) ⇒ Success(f(x), in1)<br />

case f ⇒ f<br />

}<br />

}<br />

A variant ˆˆˆ takes a value V as right hand side argument.<br />

It returns V if the left hand parser succeeds:<br />

def ˆˆˆ [U](r : U): Parser[U] = ˆˆ (x ⇒ r)<br />

41

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!