Last active
August 29, 2015 14:26
-
-
Save allykzam/33c070f1d36b53428909 to your computer and use it in GitHub Desktop.
Attempts to handle MSBuild condition attributes
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
let input = @"$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*' And $(Configuration) == 'Debug'" | |
let rec parseWord (data : System.Text.StringBuilder) (input : string) (index : int) (inQuotes : bool) : string * int = | |
let substr = input.Substring(index) | |
let f i () = (data.ToString()), (index + i) | |
let ret = f 1 | |
if input.Length = index | |
then f 0 () | |
else | |
let c = input.[index] | |
if data.Length = 0 && not inQuotes && c = '\'' | |
then parseWord data input (index + 1) true | |
elif inQuotes && c = '\'' | |
then ret() | |
elif not inQuotes && c = ' ' && data.Length = 0 | |
then parseWord data input (index + 1) inQuotes | |
elif not inQuotes && c = ' ' | |
then ret() | |
else parseWord (data.Append(c)) input (index + 1) inQuotes | |
let sb = new System.Text.StringBuilder() | |
let (firstWord, index) = parseWord sb input 0 false | |
sb.Clear() | |
let rec parseComparison (data : System.Text.StringBuilder) (input : string) (index : int) : string * int = | |
let substr = input.Substring(index) | |
if input.Length = index | |
then "", index | |
else | |
let c = input.[index] | |
if data.Length = 0 && c = ' ' | |
then parseComparison data input (index + 1) | |
elif data.Length = 2 && c <> ' ' | |
then "", index | |
elif c = '<' || c = '>' || c = '!' || c = '=' | |
then parseComparison (data.Append(c)) input (index + 1) | |
else (data.ToString()), index | |
let (comp, index') = parseComparison sb input index | |
sb.Clear() | |
let (secondWord, index'') = parseWord sb input index' false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment