diff --git a/frontends/LexOccam.x b/frontends/LexOccam.x index 1c99d4c..e48dd1e 100644 --- a/frontends/LexOccam.x +++ b/frontends/LexOccam.x @@ -36,7 +36,7 @@ $horizSpace = [\ \t] $vertSpace = [\r\n] @directive = "COMMENT" | "ELSE" | "ENDIF" | "IF" | "INCLUDE" - | "OPTION" | "PRAGMA" | "RELAX" | "USE" + | "OPTION" | "RELAX" | "USE" | "DEFINE" @preprocessor = "#" @directive [^\n]* @@ -99,9 +99,15 @@ occam :- -- In state one, we're reading the first thing on a line. -- In state two, we're reading the rest of the line. -- In state three, we're in the middle of a multi-line string. +-- In state four, we're in the middle of a pragma-external string <0> $horizSpace* { mkState one } + "#PRAGMA" $horizSpace+ "SHARED" { mkToken TokPreprocessor two } + "#PRAGMA" $horizSpace+ "PERMITALIASES" { mkToken TokPreprocessor two } + "#PRAGMA" $horizSpace+ "EXTERNAL" $horizSpace* \" { mkToken TokPreprocessor four } + \" $horizSpace* $vertSpace+ { mkState 0 } + @preprocessor { mkToken TokPreprocessor 0 } "--" [^\n]* { mkState 0 } $vertSpace+ { mkState 0 } @@ -109,6 +115,9 @@ occam :- @reserved { mkToken TokReserved two } @identifier { mkToken TokIdentifier two } + @reserved { mkToken TokReserved four } + @identifier { mkToken TokIdentifier four } + @charLiteral { mkToken TokCharLiteral two } @fullString { mkToken TokStringLiteral two } @startString { mkToken TokStringCont three } @@ -121,7 +130,11 @@ occam :- @hexLiteral { mkToken TokHexLiteral two } @realLiteral { mkToken TokRealLiteral two } - $horizSpace+ { mkState two } + @intLiteral { mkToken TokIntLiteral four } + @hexLiteral { mkToken TokHexLiteral four } + @realLiteral { mkToken TokRealLiteral four } + + $horizSpace+ ; { -- | An occam source token and its position. diff --git a/frontends/ParseOccam.hs b/frontends/ParseOccam.hs index 6513a2a..0338cf3 100644 --- a/frontends/ParseOccam.hs +++ b/frontends/ParseOccam.hs @@ -1347,8 +1347,11 @@ pragma :: OccParser () pragma = do Pragma p <- genToken isPragma m <- getPosition >>* sourcePosToMeta case map (flip matchRegex p . mkRegex) - ["^SHARED +(.*)", "^PERMITALIASES +(.*)"] of - [Just [varsRaw], _] -> + [ "^SHARED.*" + , "^PERMITALIASES.*" + , "^EXTERNAL.*"] of + [Just _, _, _] -> do + vars <- sepBy1 identifier sComma mapM_ (\var -> do st <- get A.Name _ n <- case lookup var (csLocalNames st) of @@ -1356,8 +1359,9 @@ pragma = do Pragma p <- genToken isPragma Just def -> return $ fst def modify $ \st -> st {csNameAttr = Map.insertWith Set.union n (Set.singleton NameShared) (csNameAttr st)}) - (processVarList varsRaw) - [Nothing, Just [varsRaw]] -> + vars + [Nothing, Just _, _] -> do + vars <- sepBy1 identifier sComma mapM_ (\var -> do st <- get A.Name _ n <- case lookup var (csLocalNames st) of @@ -1365,24 +1369,25 @@ pragma = do Pragma p <- genToken isPragma Just def -> return $ fst def modify $ \st -> st {csNameAttr = Map.insertWith Set.union n (Set.singleton NameAliasesPermitted) (csNameAttr st)}) - (processVarList varsRaw) + vars + [Nothing, Nothing, Just _] -> do + m <- md + sPROC + n <- newProcName + fs <- formalList >>* map fst + sEq + integer + let on = A.nameName n + sp = A.Proc m (A.PlainSpec, A.PlainRec) fs (A.Skip m) + nd = A.NameDef m on on sp A.Original A.NamePredefined A.Unplaced + modify $ \st -> st + { csNames = Map.insert on nd (csNames st) + , csLocalNames = (on, (n, ProcName)) : csLocalNames st + } _ -> warnP m WarnUnknownPreprocessorDirective $ "Unknown PRAGMA: " ++ p eol where - processVarList raw = map chopBoth $ - splitRegex (mkRegex ",") $ if "--" `isInfixOf` raw - then chopComment [] raw - else raw - - chopComment prev ('-':'-':_) = prev - chopComment prev (x:xs) = chopComment (prev++[x]) xs - chopComment prev [] = prev - - chopBoth = chopLeadingSpaces . chopTrailingSpaces - chopLeadingSpaces = dropWhile (`elem` " \t") - chopTrailingSpaces = reverse . dropWhile (`elem` " \t") . reverse - isPragma (Token _ p@(Pragma {})) = Just p isPragma _ = Nothing --}}}