From 818c14474066bc0ebe29c488eed29e92f6e0a3cf Mon Sep 17 00:00:00 2001 From: Uladzislau Harbuz Date: Thu, 11 Jul 2019 14:06:20 +0200 Subject: [PATCH] Add to DSL exec, push, pull commands Signed-off-by: Uladzislau Harbuz Change-Id: Iaac69e971653249d939c2f6f0cd5d107ff77afa2 --- Festral.cabal | 2 +- Festral/Internal/Preprocessor.hs | 64 +++++++++++++++++++++++++++++--- README.md | 7 +++- 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/Festral.cabal b/Festral.cabal index 2c4b926..47c0531 100644 --- a/Festral.cabal +++ b/Festral.cabal @@ -1,5 +1,5 @@ Name: Festral -Version: 2.2.1 +Version: 2.3.0 Cabal-Version: >= 1.2 License: Apache-2.0 License-file: LICENSE diff --git a/Festral/Internal/Preprocessor.hs b/Festral/Internal/Preprocessor.hs index 1472305..33bdb19 100644 --- a/Festral/Internal/Preprocessor.hs +++ b/Festral/Internal/Preprocessor.hs @@ -29,7 +29,8 @@ -- cmp ::= == | != -- -- stmt ::= raw (text) | if (b) stmt else stmt fi | include (w) --- | insert (w) | [stmt;] +-- | insert (w) | exec(text) | push(text1, text2) | push_latest(src,dst) | pull(text1) +-- | [stmt;] -- -- comments: /* */ -- @ @@ -78,6 +79,10 @@ data Stmt | If BExpr Stmt Stmt | Include PWord | Insert PWord + | Exec PWord + | Push PWord PWord + | PushLatest PWord PWord + | Pull PWord | Seq [Stmt] deriving Show @@ -122,12 +127,31 @@ parseStatement t (Include x) = do then preprocess t file else return file parseStatement t (Insert x) = return $ parseWord t x +parseStatement t (Exec x) = return $ + " ##TEMPLATE_RUN " ++ parseWord t x +parseStatement t (Push src dest) = return $ + pushHelper "TEMPLATE_URL" t src parsedDest + where parsedDest = parseWord t dest +parseStatement t (PushLatest src dest) = return $ + pushHelper "TEMPLATE_LATEST" t src parsedDest + where parsedDest = parseWord t dest +parseStatement t (Pull src) = return $ + " - pull:\n\ + \ src: '" ++ parsedSrc ++ "'\n\ + \ alias: '"++ parsedSrc ++ "'\n" + where parsedSrc = parseWord t src parseStatement t (Seq (x:xs)) = do a <- parseStatement t x b <- parseStatement t (Seq xs) return $ unlines [a, b] parseStatement _ _ = return "" +pushHelper x t src dst = + " - push:\n\ + \ ##" ++ x ++ " " ++ parseWord t src ++ "##\n\ + \ dest: '" ++ dst ++ "'\n\ + \ alias: '"++ dst ++ "'\n" + boolExpr :: BExpr -> Bool boolExpr (BVal x) = x boolExpr (Not x) = not $ boolExpr x @@ -141,15 +165,13 @@ cmpExpr t (Eql a b) = if parseWord t a == parseWord t b cmpExpr t (NEql a b) = Not $ cmpExpr t (Eql a b) def = emptyDef - { commentStart = "/*" - , commentEnd = "*/" - , commentLine = "//" - , identStart = letter + { identStart = letter , identLetter = alphaNum , opStart = oneOf "&|=!%$@" , reservedOpNames = ["&&", "||", "==", "!=", "!", "%", "$", "@"] , reservedNames = [ "true", "false", "raw", "if", "fi", "else" - , "include", "insert" + , "include", "insert", "exec", "push", "pull" + , "push_latest" ] } @@ -221,6 +243,10 @@ statement' t <|> includeStmt <|> insertStmt <|> rawStmt + <|> execStmt + <|> pushLatestStmt + <|> pushStmt + <|> pullStmt genStmt a b = do reserved tokenParser a @@ -229,6 +255,18 @@ genStmt a b = do rawStmt :: Parser Stmt rawStmt = genStmt "raw" Raw +execStmt :: Parser Stmt +execStmt = genPword "exec" Exec + +pushStmt :: Parser Stmt +pushStmt = genPword2Args "push" Push + +pushLatestStmt :: Parser Stmt +pushLatestStmt = genPword2Args "push_latest" PushLatest + +pullStmt :: Parser Stmt +pullStmt = genPword "pull" Pull + genPword n y = do reserved tokenParser n spaces @@ -239,6 +277,20 @@ genPword n y = do char ')' return $ y x +genPword2Args n y = do + reserved tokenParser n + spaces + char '(' + spaces + x1 <- pwordSeq + spaces + char ',' + spaces + x2 <- pwordSeq + spaces + char ')' + return $ y x1 x2 + includeStmt :: Parser Stmt includeStmt = genPword "include" Include diff --git a/README.md b/README.md index bc28e25..2c86cc4 100644 --- a/README.md +++ b/README.md @@ -619,7 +619,8 @@ The abstract syntax tree of the preprocessor language is presented below: cmp ::= == | != stmt ::= raw (text) | if (b) stmt else stmt fi | include (w) - | insert (w) | [stmt;] + | insert (w) | exec(cmd) | push(src, dst) + | push_latest(src,dst) | pull(src) | [stmt;] ``` @@ -651,6 +652,10 @@ the first statement, else insert the second statement. End of `else` case is spe otherwise insert just raw content of that file. - `insert(w)` - insert into this place value of evaluated word (test config value, environment variable or string literal) +- `exec(cmd)` - execute command given as argument on device under test. +- `push(src,dst)` - push file from current build with name `src` to the device under test as `dst`. +- `push_latest(src,dst)` - push latest built file from all performed ever builds with name `src` to the device under test as `dst`. +- `pull(src)` - pull file with name `src` from device under test to the test result files. Statements are separated by `;` (semicolon) symbol. The last statement **have not** to have semicolon after it.