]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Explicitly handle position component references.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Fri, 14 Sep 2012 13:53:50 +0000 (14:53 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Fri, 14 Sep 2012 13:53:50 +0000 (14:53 +0100)
src/ParsedOFL.hs
src/Parsing.hs

index 4a46e2954ec9a92eb151eed445826649fe45a2b5..6c7d3f9676877ea82bf97b52eee428806a9bf43c 100644 (file)
@@ -18,7 +18,7 @@ data Expression = IndexedIdentifier String [String] |
                   Add Expression Expression |
                   Sub Expression Expression |
                   Power Expression Expression |
-                  Component Expression String |
+                  PositionComponent String |
                   Derivative Expression String deriving Show
 
 data Assignment = Assign Expression Expression deriving Show
@@ -95,7 +95,7 @@ getType ofl (Divide a b) = promote (getType ofl a) (getType ofl b)
 getType ofl (Add a b) = promote (getType ofl a) (getType ofl b)
 getType ofl (Sub a b) = promote (getType ofl a) (getType ofl b)
 getType ofl (Power a b) = promote (getType ofl a) (getType ofl b)
-getType ofl (Component e i) = Function
+getType ofl (PositionComponent _) = Function
 getType ofl (Derivative e i) = getType ofl e
 
 emptyOFL :: OFL
@@ -192,8 +192,7 @@ validateExpression ofl (Power a b) = do {
 }
 
 
-validateExpression ofl (Component e i) = do {
-  validateExpression ofl e;
+validateExpression ofl (PositionComponent i) = do {
   indexExists ofl i;
 }
 
index 6af4767a187dcc8f7d9738e744d2d8f584b456f5..57a74d989ef260e2ec45f7be2dfe00910cf71758 100644 (file)
@@ -12,7 +12,7 @@ oflIndexTypes = ["FunctionIndex", "SpinIndex", "SpatialIndex"]
 oflOperandTypes = ["Real", "Function", "Integer"] 
 oflKeywords = oflIndexTypes ++ 
               oflOperandTypes ++ 
-              ["^", "+", "-", "*", "/", "laplacian", "inner", "sum", "derivative", "component", "target"]
+              ["^", "+", "-", "*", "/", "laplacian", "inner", "sum", "derivative", "r", "target"]
 
 oflDef = emptyDef{ commentStart = ""
                  , commentEnd = ""
@@ -76,7 +76,7 @@ parseTerm = do { oflReserved "laplacian"; operand <- oflParens parseExpression;
              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 { oflReserved "r"; index <- oflBrackets parseIdentifier; return $ PositionComponent index} <|>
              do { number <- oflNaturalOrFloat; 
                   return $ case number of
                     Left i -> ConstInteger i
@@ -92,8 +92,6 @@ parseSum = do { e1 <- parseExpression; oflSymbol ","; index <- parseIdentifier;
 
 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