Created
January 28, 2012 16:48
-
-
Save martintrojer/1694986 to your computer and use it in GitHub Desktop.
fsharp-parsing
This file contains hidden or 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
let extractField = function | |
// int32 version | |
| TAtomic(t) :: TString(n) :: rest -> | |
Field(n, AtomicType(t)), rest | |
// alias version | |
| TString(alias) :: TString(n) :: rest -> | |
Field(n, AliasType(alias)), rest | |
| _ -> | |
failwith "syntax error" |
This file contains hidden or 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
// int32 version | |
| TAtomic(t) :: TString(n) :: rest -> | |
Field(n, AtomicType(t), None), rest | |
// alias version | |
| TString(alias) :: TString(n) :: rest -> | |
Field(n, AliasType(alias), None), rest | |
// int32 version if? a > 1 | |
| TAtomic(t) :: TString(n) :: TCondExpr(expr) :: rest -> | |
Field(n, AtomicType(t), Some(expr)), rest | |
// alias version if? a > 1 | |
| TString(alias) :: TString(n) :: TCondExpr(expr) :: rest -> | |
Field(n, AliasType(alias), Some(expr)), rest | |
| _ -> | |
failwith "syntax error" |
This file contains hidden or 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
let (|ValidFieldOption|_|) = function | |
| THidden -> Some (ValidFieldOption Hidden) | |
| TDeprecated -> Some (ValidFieldOption Deprecated) | |
| _ -> None | |
let rec (|FieldOptions|) = function | |
| T(ValidFieldOption(o),_) :: FieldOptions(os, rest) -> Set.add o os, rest | |
| toks -> Set.empty, toks |
This file contains hidden or 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
// hidden? int32 version | |
| FieldOptions(os, TAtomic(t) :: TString(n) :: rest) -> | |
Field(n, AtomicType(t), None, os), rest | |
// hidden? alias version | |
| FieldOptions(os, TString(alias) :: TString(n) :: rest) -> | |
Field(n, AliasType(alias), None, os), rest | |
// hidden? int32 version if? a > 1 | |
| FieldOptions(os, TAtomic(t) :: TString(n) :: TCondExpr(expr) :: rest) -> | |
Field(n, AtomicType(t), Some expr, os), rest | |
// hidden? alias version if? a > 1 | |
| FieldOptions(os, TString(alias) :: TString(n) :: TCondExpr(expr) :: rest) -> | |
Field(n, AliasType(alias), Some expr, os), rest | |
| _ -> | |
failwith "syntax error" |
This file contains hidden or 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
// Parse FieldTypes | |
let (|FieldType|_|) = function | |
| TAtomic(at) :: rest -> Some (AtomicType at, rest) | |
| TString(n) :: rest -> Some (AliasType n , rest) | |
| _ -> None |
This file contains hidden or 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
// hidden? type version | |
| FieldOptions(os, FieldType(ftype, TString(n) :: rest) -> | |
Field(n, AtomicType(t), None, os), rest | |
// hidden? type version if? a > 1 | |
| FieldOptions(os, FieldType(ftype, TString(n) :: TCondExpr(expr) :: rest) -> | |
Field(n, AtomicType(t), Some expr, os), rest | |
| _ -> | |
failwith "syntax error" |
This file contains hidden or 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
let (|CondExpr|) = function | |
| TCondExpr es :: rest -> Some es, rest | |
| rest -> None, rest |
This file contains hidden or 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
let extractField = function | |
| FieldOptions(os, FieldType(ftype, TString(n) :: CondExpr(ces, rest))) -> | |
Field(n, AtomicType(t), ces, os), rest | |
| _ -> | |
failwith "syntax error" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment