Skip to content

Commit

Permalink
Add to DSL exec, push, pull commands
Browse files Browse the repository at this point in the history
Signed-off-by: Uladzislau Harbuz <[email protected]>
Change-Id: Iaac69e971653249d939c2f6f0cd5d107ff77afa2
  • Loading branch information
Shadasviar committed Jul 11, 2019
1 parent 48276da commit 818c144
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Festral.cabal
Original file line number Diff line number Diff line change
@@ -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
Expand Down
64 changes: 58 additions & 6 deletions Festral/Internal/Preprocessor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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: /* */
-- @
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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"
]
}

Expand Down Expand Up @@ -221,6 +243,10 @@ statement' t
<|> includeStmt
<|> insertStmt
<|> rawStmt
<|> execStmt
<|> pushLatestStmt
<|> pushStmt
<|> pullStmt

genStmt a b = do
reserved tokenParser a
Expand All @@ -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
Expand All @@ -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

Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;]
```

Expand Down Expand Up @@ -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.

Expand Down

0 comments on commit 818c144

Please sign in to comment.