Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing latin plant names with piglet fluent configuration
    primarykey
    data
    text
    <p>I have the following tests.And Classes. Now I just need to find how to write the rules and it seemed so simple ;-). But I'm going nowhere fast. As the tags say, I would like to use and learn piglet for this.</p> <pre><code>Public Class Plant Public Property Genus As String Public Property Species As String Public Property SubSpecies As String Public Property IsHybrid As Boolean End Class Public Class ParserTests &lt;Test&gt; Public Sub IfGenusCanBeFoundWhenOnlyGenusAndSpiecesAreThere() Dim parser = New ParseLatinPlantName Dim result = parser.Parse("Salvia sylvatica") Assert.AreEqual("Salvia", result.Genus) End Sub &lt;Test&gt; Public Sub IfSpeciesCanBeFoundWhenOnlyGenusAndSpiecesAreThere() Dim parser = New ParseLatinPlantName Dim result = parser.Parse("Salvia sylvatica") Assert.AreEqual("sylvatica", result.Species) End Sub &lt;Test&gt; Public Sub IfSubSpeciesCanBeFoundWhenSubSpeciesIsProvided() Dim parser = New ParseLatinPlantName Dim result = parser.Parse("Salvia sylvatica sp. crimsonii") Assert.AreEqual("crimsonii", result.SubSpecies) End Sub &lt;Test&gt; Public Sub IfIsHybridIsTrueWhenxIsInNameCanBeFoundWhenSubSpeciesIsProvided() Dim parser = New ParseLatinPlantName Dim result = parser.Parse("Salvia x jamensis") Assert.IsTrue(result.IsHybrid) End Sub End Class </code></pre> <p>And here is what I tried so far.</p> <pre><code>Public Class ParseLatinPlantName Public Function Parse(ByVal name As String) As Plant Dim config = ParserFactory.Fluent() Dim expr = config.Rule() Dim name1 = config.Expression() name1.ThatMatches("[a-z]+").AndReturns(Function(f) f) Dim space1 = config.Expression() space1.ThatMatches(" ").AndReturns(Function(f) f) expr.IsMadeUp.By(name).As("Genus").Followed.By(name).As("Species").WhenFound(Function(f) New Plant With {.Genus = f.Genus}) Dim parser = config.CreateParser() Dim result = DirectCast(parser.Parse(name), Plant) Return result End Function End Class </code></pre> <p>Update</p> <p>I got the first two tests passing thanks to Randompunter. </p> <pre><code>Public Class ParseLatinPlantName Public Function Parse(ByVal name As String) As Plant Dim config = ParserFactory.Fluent() Dim expr = config.Rule() Dim name1 = config.Expression() name1.ThatMatches("\w+").AndReturns(Function(f) f) expr.IsMadeUp.By(name1).As("Genus") _ .Followed.By(name1).As("Species") _ .WhenFound(Function(f) New Plant With {.Genus = f.Genus, .Species = f.Species}) Dim parser = config.CreateParser() Dim result = DirectCast(parser.Parse(name), Plant) Return result End Function End Class </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload