Advertisement
Guest User

Untitled

a guest
Jan 11th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.43 KB | None | 0 0
  1.     and (|Statement|_|) tokens =
  2.         match tokens with
  3.         | Token.Keyword ("let",row,col) :: remainingTokens ->
  4.             match remainingTokens with
  5.             | IdentifierDefinition (remainingTokens,identifier) ->
  6.                 let rec accumulateParameters tokens parameters =
  7.                     match tokens with
  8.                     | IdentifierDefinition (remainingTokens,identifier) ->
  9.                         let parameters = parameters @ [identifier]
  10.                         accumulateParameters remainingTokens parameters
  11.                     | Token.Op (symbol,row,col) :: tail when symbol = "=" ->
  12.                         (remainingTokens,parameters)
  13.                     | token :: tail ->
  14.                         let row,col = ((token :> IToken).row,(token :> IToken).col)
  15.                         failwith <| errorMessage codeLines.[row] row col "Unexpected token in function declaration"
  16.                     | _ -> failwith "Unexpected end of file"
  17.                 let (remainingTokens,parameters) = accumulateParameters remainingTokens []
  18.                 match parameters with
  19.                 | [] ->         //Value definition
  20.                     match remainingTokens with
  21.                     | Expression (remainingTokens,expression) ->
  22.                         Some (remainingTokens,ValueDefinition (identifier,expression))
  23.                     | token :: tail ->
  24.                         let row,col = ((token :> IToken).row,(token :> IToken).col)
  25.                         failwith <| errorMessage codeLines.[row] row col "Expected expression"
  26.                     | _ -> failwith "Unexpected end of file"
  27.                 | parameters -> //Function definition
  28.                     match remainingTokens with
  29.                     | Expression (remainingTokens,expression) ->
  30.                         Some (remainingTokens,FunctionDefinition (identifier,parameters,expression))
  31.                     | token :: tail ->
  32.                         let row,col = ((token :> IToken).row,(token :> IToken).col)
  33.                         failwith <| errorMessage codeLines.[row] row col "Expected expression"
  34.                     | _ -> failwith "Unexpected end of file"
  35.             | token :: tail ->
  36.                 let row,col = ((token :> IToken).row,(token :> IToken).col)
  37.                 failwith <| errorMessage codeLines.[row] row col "Unexpected token after let"
  38.             | _ -> failwith "Unexpected end of file"
  39.         | _ -> None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement