This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from MikaelFangel/setup-project
Setup project
- Loading branch information
Showing
8 changed files
with
265 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
<Crn〉 ::= 'crn = {'〈RootSList〉'}' | ||
〈RootSList〉 ::= 〈RootS〉 | ||
| 〈RootS〉 ',' 〈RootSList〉 | ||
〈RootS〉 ::= 〈ConcS〉 | ||
| 〈StepS〉 | ||
〈ConcS〉 ::= | ||
'conc ['〈species〉','〈number〉']' | ||
〈Crn〉 ::= 'crn = {'〈RootSList〉'}' | ||
〈RootSList〉 ::= 〈RootS〉| 〈RootS〉 ',' 〈RootSList〉 | ||
|
||
〈RootS〉 ::= 〈ConcS〉|〈StepS〉 | ||
|
||
〈ConcS〉 ::= 'conc ['〈species〉','〈number〉']' | ||
|
||
〈StepS〉 ::= 'step ['CommandSList']' | ||
|
||
〈CommandSList〉 ::= 〈CommandS〉 | ||
| 〈CommandS〉 ',' 〈CommandSList〉 | ||
〈CommandS〉 ::= 〈RxnS〉 | ||
|
||
〈CommandS〉 ::= | ||
| 〈RxnS〉 | ||
| 〈ModuleS〉 | ||
| 〈ConditionalS〉 | ||
〈RxnS〉 ::= 'rxn['〈Expr〉','〈Expr〉','〈number〉']' | ||
〈ModuleS〉 ::= 'ld ['〈species〉','〈species〉']' | ||
〈ModuleS〉 ::= | ||
| 'ld ['〈species〉','〈species〉']' | ||
| 'add ['〈species〉','〈species〉','〈species〉']' | ||
| 'sub ['〈species〉','〈species〉','〈species〉']' | ||
| 'mul ['〈species〉','〈species〉','〈species〉']' | ||
| 'div ['〈species〉','〈species〉','〈species〉']' | ||
| 'sqrt ['〈species〉','〈species〉']' | ||
| 'cmp ['〈species〉','〈species〉']' | ||
|
||
〈ConditionalS〉 ::= | ||
'ifGT ['〈CommandSList〉']' | ||
| 'ifGT ['〈CommandSList〉']' | ||
| 'ifGE ['〈CommandSList〉']' | ||
| 'ifEQ ['〈CommandSList〉']' | ||
| 'ifLT ['〈CommandSList〉']' | ||
| 'ifLE ['〈CommandSList〉']' | ||
|
||
〈Expr〉 ::= 〈species〉 { '+' 〈species〉 } | ||
〈Expr〉 ::= 〈species〉('+' 〈species〉)+ | ||
〈number〉 ::= ([^0]([0-9])+)|0 | ||
〈species〉::= ([A-Za-z0-9])+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
#r "nuget:FParsec" | ||
|
||
open FParsec | ||
|
||
let test p str = | ||
match run p str with | ||
| Success(result, _, _) -> printfn "Success: %A" result | ||
| Failure(errorMsg, _, _) -> printfn "Failure: %s" errorMsg | ||
|
||
test pfloat "1.25" | ||
|
||
type SpeciesS = string | ||
type PNumberS = PNumber of float | ||
|
||
type ConcS = Conc of SpeciesS * PNumberS | ||
|
||
type ExprS = Expr of list<SpeciesS> | ||
|
||
type ReactionS = Reaction of ExprS * ExprS * PNumberS | ||
|
||
type ModuleS = | ||
| Ld of SpeciesS * SpeciesS | ||
| Add of SpeciesS * SpeciesS * SpeciesS | ||
| Sub of SpeciesS * SpeciesS * SpeciesS | ||
| Mul of SpeciesS * SpeciesS * SpeciesS | ||
| Div of SpeciesS * SpeciesS * SpeciesS | ||
| Sqrt of SpeciesS * SpeciesS | ||
| Cmp of SpeciesS * SpeciesS | ||
|
||
type ConditionS = | ||
| Gt of CommandS list | ||
| Ge of CommandS list | ||
| Eq of CommandS list | ||
| Lt of CommandS list | ||
| Le of CommandS list | ||
|
||
and CommandS = | ||
| Reaction of ReactionS | ||
| Module of ModuleS | ||
| Condition of ConditionS | ||
|
||
type StepS = Step of list<CommandS> | ||
|
||
type RootS = | ||
| Conc of ConcS | ||
| Step of StepS | ||
|
||
type CrnS = Crn of list<RootS> | ||
|
||
|
||
|
||
let comment = | ||
let anythingExceptNewline = isNoneOf [ '\n'; '\r' ] | ||
skipString "//" >>. spaces >>. manySatisfy anythingExceptNewline | ||
|
||
test comment "// hello world" | ||
|
||
let ws = comment |>> ignore <|> spaces | ||
let str_ws s = pstring s .>> ws | ||
|
||
let float_ws = pfloat .>> ws | ||
|
||
let identifier = | ||
let isFirstChar c = isLetter c || c = '_' | ||
let isChar c = isLetter c || isDigit c || c = '_' | ||
many1Satisfy2L isFirstChar isChar "identifier" .>> ws | ||
|
||
test identifier "_blahblah123 " | ||
|
||
let pspecies = identifier .>> ws |>> SpeciesS | ||
let pnumber = float_ws |>> PNumber | ||
|
||
let pexpr = sepBy pspecies (str_ws "+") .>> ws |>> Expr | ||
|
||
let start_bracket bcopen start = | ||
str_ws start .>> str_ws bcopen | ||
|
||
let end_bracket bcclose = str_ws bcclose | ||
|
||
let comma = str_ws "," | ||
|
||
let brackets2 popen pclose t1 t2 cons = | ||
pipe2 (popen >>. t1) (comma >>. t2 .>> pclose) (fun v1 v2 -> cons (v1, v2)) | ||
|
||
let brackets3 popen pclose t1 t2 t3 cons = | ||
pipe3 (popen >>. t1) (comma >>. t2) (comma >>. t3 .>> pclose) (fun v1 v2 v3 -> cons (v1, v2, v3)) | ||
|
||
let pconc = | ||
brackets2 (start_bracket "[" "conc") (end_bracket "]") pspecies pnumber ConcS.Conc | ||
|
||
let brackets3species name = | ||
brackets3 (start_bracket "[" name) (end_bracket "]") pspecies pspecies pspecies | ||
|
||
let brackets2species name = | ||
brackets2 (start_bracket "[" name) (end_bracket "]") pspecies pspecies | ||
|
||
let pmoduleld = brackets2species "ld" Ld | ||
let pmoduleadd = brackets3species "add" Add | ||
let pmodulesub = brackets3species "sub" Sub | ||
let pmodulemul = brackets3species "mul" Mul | ||
let pmodulediv = brackets3species "div" Div | ||
let pmodulesqrt = brackets2species "sqrt" Sqrt | ||
let pmodulecmp = brackets2species "cmp" Cmp | ||
|
||
let pmodule = | ||
choice | ||
[ pmoduleld | ||
pmoduleadd | ||
pmodulesub | ||
pmodulemul | ||
pmodulediv | ||
pmodulesqrt | ||
pmodulecmp ] | ||
|
||
let prxn = | ||
brackets3 (start_bracket "[" "rxn") (end_bracket "]") pexpr pexpr pnumber ReactionS.Reaction | ||
|
||
let listparser popen pclose listelem = | ||
between popen pclose (sepBy listelem (str_ws ",")) | ||
|
||
let pcon, pconref = createParserForwardedToRef<'a, 'u> () | ||
|
||
let pcommand = | ||
choice | ||
[ pmodule |>> CommandS.Module | ||
prxn |>> CommandS.Reaction | ||
pcon |>> CommandS.Condition ] | ||
|
||
let commandopen start = | ||
str_ws start >>. str_ws "[" .>> str_ws "{" | ||
|
||
let commandclose = str_ws "}" .>> str_ws "]" | ||
|
||
let pcommandlist start = | ||
listparser (commandopen start) commandclose pcommand | ||
|
||
let pcmdif = pcommandlist "ifGT" |>> Gt | ||
let pcmdge = pcommandlist "ifGE" |>> Ge | ||
let pcmdeq = pcommandlist "ifEQ" |>> Eq | ||
let pcmdlt = pcommandlist "ifLT" |>> Lt | ||
let pcmdle = pcommandlist "ifLE" |>> Le | ||
|
||
pconref.Value <- choice [ pcmdif; pcmdge; pcmdeq; pcmdlt; pcmdle ] | ||
|
||
let pstep = pcommandlist "step" |>> StepS.Step | ||
|
||
let proot = choice [ pstep |>> RootS.Step; pconc |>> RootS.Conc ] | ||
|
||
let crnopen = | ||
str_ws "crn" >>. str_ws "=" .>> str_ws "{" | ||
|
||
let crnclose = str_ws "}" | ||
let curlyparser = listparser crnopen crnclose | ||
let pcrn = ws >>. curlyparser proot .>> eof |>> Crn | ||
|
||
let example = | ||
"crn = { | ||
conc[c, 5.0], conc[cInitial, 4.0], | ||
conc[one, 1], conc[zero, 0], | ||
step[{ | ||
sub[c, one, cnext], | ||
cmp[c, zero] | ||
}], | ||
step[{ | ||
ifGT[{ ld[cnext, c] }], | ||
ifLE[{ ld[cInitial, c] }] | ||
}] | ||
}" | ||
|
||
test pcrn example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// For more information see https://aka.ms/fsharp-console-apps | ||
printfn "Hello from F#" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Program.fs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module Program = let [<EntryPoint>] main _ = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Tests | ||
|
||
open System | ||
open Xunit | ||
|
||
[<Fact>] | ||
let ``My test`` () = | ||
Assert.True(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
<GenerateProgramFile>false</GenerateProgramFile> | ||
<IsTestProject>true</IsTestProject> | ||
|
||
<IsPublishable>false</IsPublishable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Tests.fs" /> | ||
<Compile Include="Program.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FsCheck" Version="2.16.*" /> | ||
<PackageReference Include="FsCheck.Xunit" Version="2.16.6" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" /> | ||
<PackageReference Include="xunit" Version="2.8.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\crncc\crncc.fsproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |