oflIndexTypes = ["FunctionIndex", "SpinIndex", "SpatialIndex"]
oflOperandTypes = ["Real", "Function", "Integer"]
-oflKeywords = oflIndexTypes ++ oflOperandTypes ++ ["*", "-", "^", "laplacian", "inner", "sum", "derivative"]
+oflKeywords = oflIndexTypes ++
+ oflOperandTypes ++
+ ["^", "+", "-", "*", "/", "laplacian", "inner", "sum", "derivative", "component"]
oflDef = emptyDef{ commentStart = ""
, commentEnd = ""
oflOperatorTable = [[Infix (do { oflSymbol "^"; return (\x y -> Power x y) }) AssocLeft],
[Prefix (do { oflSymbol "-"; return (\x -> Negate x)})],
[Infix (do { oflSymbol "*"; return (\x y -> Multiply x y) }) AssocLeft
- ,Infix (do { oflSymbol "/"; return (\x y -> Divide x y) }) AssocLeft]
+ ,Infix (do { oflSymbol "/"; return (\x y -> Divide x y) }) AssocLeft],
+ [Infix (do { oflSymbol "+"; return (\x y -> Add x y) }) AssocLeft
+ ,Infix (do { oflSymbol "-"; return (\x y -> Sub x y) }) AssocLeft]
]
parseType = foldl1 (<|>) [do { oflReserved $ show t; return t} | t <- [Real, Function, Integer]]
do { oflReserved "inner"; inner <- oflParens parseInner; return inner} <|>
do { oflReserved "sum"; sum <- oflParens parseSum; return sum} <|>
do { oflReserved "derivative"; derivative <- oflParens parseDerivative; return derivative} <|>
+ do { oflReserved "component"; component <- oflParens parseComponent; return component} <|>
do { float <- oflFloat; return $ ConstReal float } <|>
do { integer <- oflInteger; return $ ConstInteger integer } <|>
oflParens parseExpression <|>
parseSum = do { e1 <- parseExpression; oflSymbol ","; index <- parseIdentifier; return $ Sum e1 index} <?> "sum"
parseDerivative = do { e1 <- parseExpression; oflSymbol ","; index <- parseIdentifier; return $ Derivative e1 index} <?> "derivative"
+
+parseComponent = do { e1 <- parseExpression; oflSymbol ","; index <- parseIdentifier; return $ Component e1 index} <?> "component access"
parseIdentifierAccess = do { identifier <- parseIdentifier;
indices <- option [] (oflBrackets $ oflCommaSep parseIdentifier);
- return $ IndexedIdentifier identifier indices
+ return $ IndexedIdentifier identifier indices
} <?> "indexed identifier"
parseOFL :: Parsec String OFL OFL