Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- and (|Statement|_|) tokens =
- match tokens with
- | Token.Keyword ("let",row,col) :: remainingTokens ->
- match remainingTokens with
- | IdentifierDefinition (remainingTokens,identifier) ->
- let rec accumulateParameters tokens parameters =
- match tokens with
- | IdentifierDefinition (remainingTokens,identifier) ->
- let parameters = parameters @ [identifier]
- accumulateParameters remainingTokens parameters
- | Token.Op (symbol,row,col) :: tail when symbol = "=" ->
- (remainingTokens,parameters)
- | token :: tail ->
- let row,col = ((token :> IToken).row,(token :> IToken).col)
- failwith <| errorMessage codeLines.[row] row col "Unexpected token in function declaration"
- | _ -> failwith "Unexpected end of file"
- let (remainingTokens,parameters) = accumulateParameters remainingTokens []
- match parameters with
- | [] -> //Value definition
- match remainingTokens with
- | Expression (remainingTokens,expression) ->
- Some (remainingTokens,ValueDefinition (identifier,expression))
- | token :: tail ->
- let row,col = ((token :> IToken).row,(token :> IToken).col)
- failwith <| errorMessage codeLines.[row] row col "Expected expression"
- | _ -> failwith "Unexpected end of file"
- | parameters -> //Function definition
- match remainingTokens with
- | Expression (remainingTokens,expression) ->
- Some (remainingTokens,FunctionDefinition (identifier,parameters,expression))
- | token :: tail ->
- let row,col = ((token :> IToken).row,(token :> IToken).col)
- failwith <| errorMessage codeLines.[row] row col "Expected expression"
- | _ -> failwith "Unexpected end of file"
- | token :: tail ->
- let row,col = ((token :> IToken).row,(token :> IToken).col)
- failwith <| errorMessage codeLines.[row] row col "Unexpected token after let"
- | _ -> failwith "Unexpected end of file"
- | _ -> None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement