Changeset ab91a87e0efb…
by Hao Lian <hao@fogcreek.com>
Changes to 8 files · Browse files at ab91a87e0efb Diff from another changeset...
|
|
|
@@ -0,0 +1,20 @@ +
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "babybearparser", "babybearparser\babybearparser.fsproj", "{233F7421-5047-42ED-B364-555A50258027}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {233F7421-5047-42ED-B364-555A50258027}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {233F7421-5047-42ED-B364-555A50258027}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {233F7421-5047-42ED-B364-555A50258027}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {233F7421-5047-42ED-B364-555A50258027}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
|
|
@@ -0,0 +1,16 @@ + <?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
+ </startup>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
+ <bindingRedirect oldVersion="2.3.5.0" newVersion="4.3.0.0" />
+ <bindingRedirect oldVersion="2.0.0.0" newVersion="4.3.0.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
\ No newline at end of file |
|
@@ -0,0 +1,60 @@ + module babybearparser.Parser
+
+open FParsec.CharParsers
+open FParsec.Primitives
+open System
+
+type Keyword = Word of string | Phrase of string
+ with
+ override this.ToString() =
+ match this with
+ | Word s -> String.Format("Word<{0}>", s)
+ | Phrase s -> String.Format("Phrase<{0}>", s)
+
+type Filter =
+ | Author of string
+ | Date of DateTime * DateTime
+ | File of string
+ | Project of string
+ | Repo of string
+
+type Atom = KeywordAtom of Keyword | FilterAtom of Filter
+ with
+ override this.ToString() =
+ match this with
+ | KeywordAtom k -> String.Format("KeywordAtom<{0}>", k)
+ | FilterAtom f -> String.Format("FilterAtom<{0}>", f)
+
+exception ParseError of string
+
+let pipeline (f, a) = f a
+
+let word = many1Satisfy <| fun c -> c <> ' '
+let phraseEscape = pchar '\\' >>. pchar '"'
+let phraseInnard = phraseEscape <|> noneOf "\""
+let phraseInnards = manyChars phraseInnard
+let phrase = between (pchar '"') (pchar '"') phraseInnards
+let keyword = (phrase |>> Phrase) <|> (word |>> Word)
+
+let filterName = ["author"; "file"; "project"; "repo"] |> Seq.map pstring |> choice
+let findFilter = function
+ | "author" -> Author
+ | "file" -> File
+ | "project" -> Project
+ | "repo" -> Repo
+ | _ -> raise <| Exception "Invalid filter name"
+
+let filter =
+ (filterName |>> findFilter)
+ .>> (pchar ':')
+ .>>. (phrase <|> word)
+ |>> pipeline
+
+let atom = (filter |>> FilterAtom) <|> (keyword |>> KeywordAtom)
+let spaces = many1Satisfy <| fun c -> c = ' '
+let atoms = sepBy atom spaces
+let parse input =
+ match run atoms input with
+ | Success (x, _, _) -> x
+ | Failure (x, _, _) -> raise <| ParseError x
+
|
|
@@ -0,0 +1,6 @@ + module babybearparser.Program
+
+[<EntryPoint>]
+let main argv =
+ printfn "%A" argv
+ 0
|
|
@@ -0,0 +1,66 @@ + module babybearparser.Testing
+
+open FParsec
+open Microsoft.VisualStudio.TestTools.UnitTesting
+open System
+
+open babybearparser.Parser
+
+let equals actual expected = Assert.AreEqual (expected, actual)
+let throws<'a when 'a :> exn> (f: unit -> unit) =
+ try
+ f(); Assert.Fail ("throws: no exception thrown of type: " + typedefof<'a>.Name)
+ with
+ | :? 'a -> ()
+
+[<TestClass>]
+type public Tests () =
+ (* Tests that testing works *)
+ [<TestMethod>]
+ member this.TestsWorking() =
+ equals 1 1
+
+ [<TestMethod>]
+ member this.TestsKeywords() =
+ equals (parse "foo bar") [KeywordAtom <| Word "foo"; KeywordAtom <| Word "bar"]
+
+ [<TestMethod>]
+ member this.TestsEmpty() =
+ equals (List.length <| parse "") 0
+
+ [<TestMethod>]
+ member this.TestsPhrase() =
+ equals (parse "\"foo \\\" bar\"") [KeywordAtom <| Phrase "foo \" bar"]
+
+ [<TestMethod>]
+ member this.TestsPhraseAndKeyword() =
+ equals (parse "\"foo bar\" boo") [KeywordAtom <| Phrase "foo bar"; KeywordAtom <| Word "boo"]
+
+ [<TestMethod>]
+ member this.TestsFilter() =
+ equals (parse "\"foo bar\" project:boo") [KeywordAtom <| Phrase "foo bar"; FilterAtom <| Project "boo"]
+
+ [<TestMethod>]
+ member this.TestsFilters() =
+ equals (parse "\"foo bar\" project:boo repo:radley") [KeywordAtom <| Phrase "foo bar"; FilterAtom <| Project "boo"; FilterAtom <| Repo "radley"]
+
+ [<TestMethod>]
+ member this.TestsFilterPhrase() =
+ equals (parse "\"foo bar\" project:\"boo radley\"") [KeywordAtom <| Phrase "foo bar"; FilterAtom <| Project "boo radley"]
+
+ [<TestMethod>]
+ member this.TestsEmptyFilter() =
+ equals (parse "\"foo bar\" project:\"\"") [KeywordAtom <| Phrase "foo bar"; FilterAtom <| Project ""]
+
+ [<TestMethod>]
+ member this.TestsConfusingFilter() =
+ equals (parse ":taft:") [KeywordAtom <| Word ":taft:"]
+
+ [<TestMethod>]
+ member this.TestsMissingFilter() =
+ let f () = parse "\"foo bar\" project:" |> ignore
+ throws<ParseError> f
+
+ [<TestMethod>]
+ member this.TestsUnknownFilter() =
+ equals (parse "unknown:careless") [KeywordAtom <| Word "unknown:careless"]
\ No newline at end of file |
|
@@ -0,0 +1,74 @@ + <?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>233f7421-5047-42ed-b364-555a50258027</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <RootNamespace>babybearparser</RootNamespace>
+ <AssemblyName>babybearparser</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <Name>babybearparser</Name>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <Tailcalls>false</Tailcalls>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <WarningLevel>3</WarningLevel>
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DocumentationFile>bin\Debug\babybearparser.XML</DocumentationFile>
+ <Prefer32Bit>true</Prefer32Bit>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <Tailcalls>true</Tailcalls>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <WarningLevel>3</WarningLevel>
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DocumentationFile>bin\Release\babybearparser.XML</DocumentationFile>
+ <Prefer32Bit>true</Prefer32Bit>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="FParsec">
+ <HintPath>..\packages\FParsec.0.9.2.0\lib\net40\FParsec.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="FParsecCS">
+ <HintPath>..\packages\FParsec.0.9.2.0\lib\net40\FParsecCS.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ <Reference Include="mscorlib" />
+ <Reference Include="FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Numerics" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ <None Include="packages.config" />
+ <Compile Include="Parser.fs" />
+ <Compile Include="Testing.fs" />
+ <Compile Include="Program.fs" />
+ </ItemGroup>
+ <PropertyGroup>
+ <MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
+ </PropertyGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
\ No newline at end of file |
|
@@ -0,0 +1,4 @@ + <?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="FParsec" version="0.9.2.0" targetFramework="net45" />
+</packages>
\ No newline at end of file |
Loading...