Nine days before the scheduled launch, they chose Laika for her gentle disposition and natural beauty. The mission was too dangerous to risk a human life, so the Soviets decided to train a stray dog to be Russia’s first cosmonaut. That’s when Soviet Premier Nikita Khrushchev insisted that his scientists perform a second test-this time to determine if a living being could survive the journey to the stars. Just a month earlier, on October 4, 1957, the Soviet Union-Cold War nemesis of the United States-launched into orbit history’s first satellite, Sputnik 1. Laika’s unlikely journey was borne out of the race to prove that human spaceflight was possible. No small feat for a stray that only days before had been fighting for scraps on the streets of Moscow! And when her spaceship pierced the Earth’s atmosphere, she became the first creature in history to make it to outer space. Inside was a diminutive, 14-pound, black and white dog named Laika. digit ).On November 3, 1957, a tiny capsule rocketed into space. While evalMap maps to an Either where a Left result will cause the parser to fail,Ĭollect applies a partial function and causes the parser to fail if the function is not defined for the result. Potentially causing the parser to fail if they are not met: def evalMap ( f : T => Either ): Parser ĭef collect ( f : PartialFunction ): Parser The API also offers methods that allow to check pre-conditions on the result, In many real-world scenarios parsers are used to build up a form of AST of the parsed input.Īll concrete parsers in Laika do this, the ones of text markup, HOCON and CSS all produce a model representing the input.įirst there is the classic map: def map ( f : T => U ): Parser Or String ~ String in case of concatenation and Seq in case of repetition. Producing Results Īll of our preceding examples defined lower-level text parsers that produce a String result While the max constraint will always succeed and simply ignore subsequent repetitions. When using the min constraint the parser will fail when it does not reach the specified minimum number of repetitions, The above reads between 1 to 4 hexadecimal digits. The number of repetitions can be further constrained: someOf ( CharGroup. This parser's behaviour is identical to the previous one. This pattern is so common that there is also a shortcut for repeating with a separator: someOf ( CharGroup. Of a comma followed by another sequence of characters. The above reads a non-empty sequence of alphanumerical characters followed by zero or more repetitions Where the second will only be invoked if the first parser fails: ( " \" " ~> anyBut ( '"' ) someOf ( CharGroup. Two parsers can be defined to be tried as alternatives, The result of this parser will be String as the first and last result will be ignored. The ~> combinator ignores the left result, someOf ( range ( 'a', 'z' )) " When some of the results are known for example. In many cases we are only interested in one of the results of a concatenation, This is encapsulated in the single abstract method of the Parser trait: trait Parser The Parser Trait Ī parser instance is invoked at a particular offset into an input and performs the following tasks:ġ) produce a result or fail with a message If some users voice an interest in using it without Laika's other features. The library is currently part of the laika-core artifact, but has the potential to become a separate micro-lib, Parsing of text markup which is a multi-pass process and providing a maximum of flexibility for user provided It's to a large degree a general purpose parser library for character input,īut also has a few aspects tailored for Laika's main requirements: The decision was based on the goal to find the sweet spot between ease of use, flexibility and performance. Since the 0.8 release in 2018 Laika comes with its own parser combinator library. Source for this page Laika's Parser Combinators
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |