<?ZBNF-www.vishia.org version="1.0" encoding="iso-8859-1" ?>
##This script converts a make prescript given in lines with translator (Zmake) to xml and than to ant.xml
##yyyy-mm-dd who       what
##2007-12-29 HartmutS  new: fileset as a new feature
$comment=[?...?].

Zmake::=<*|\nZMAKE_RULES:?> ZMAKE_RULES:  
{ \$<ZmakeVariable> ; 
| &<filesetdef?ZmakeVariable> ; 
| <target> ; 
} \e.

##A ZmakeVariable may contain a fileset.

string::= { <""?literal> | <forInputString> | @<$?inputField> | $<$?contentOfVariable> ? + }.
?en:string::="A string is a concatenation of \"literal\" + $contentOfVariable + @inputField + for(...)".

forInputString::= for ( <input?> : <string?> ).
?en:forInputString::="For any input file, a String was built. All strings are concatenated. ".

ZmakeVariable::=<$?@name> = [ fileset ( <fileset> ) | file ( <file> ) | <objExpr?> ]. ##<string> ]. ## | { <execCmd> }
  ].

filesetdef::= <$?@name> ( <fileset> ).


##same syntax is ZText:


textExpr::=<$NoWhiteSpaces>
{ [?\<\.\>]              ##abort on <.> 
[ \<*<dataText>
| \<: [<?transcription> n | r | t | \< | # ] \>
| \<:lf\><?newline>
| \<:\ \><!\\s*?> [ \#\#<*\r\n?> <!\\s*?> ]
| \#\#<*\r\n?>{\r|\n} 
| \<:\><textExpr?>\<\.\>
| <*|\<:|\<+|\<=|\<*|\<\.?plainText>
]
}.

dataText::=<datapath>[ : <*\>?formatText>] \>.     ##<*expr: format>


variable::= <$@-?startVariable>[ [?\. \>] \.{ <datapathElement> ? [?\. \>] \.}].

datapathElement::= [<?ident>[@]<$-?>] [( [{ <objExpr?argument> ? ,}])<?whatisit=(>].


datapath::= 
[ $$<$?envVariable> 
| [<?startVariable> $<![1-9]?>| $<$?>]    ## $1 .. $9 are the arguments of Jbatch, $name for environment 
| <variable?> 
| new <newJavaClass> 
| java <staticJavaMethod> 
| %<staticJavaMethod> 
].


newJavaClass::= <$\.$?javapath> [ ( [{ <objExpr?argument> ? , }] )].
staticJavaMethod::= <$\.$?javapath> [( [ { <objExpr?argument> ? , } ] )].
##a javapath is the full package path and class [.staticmetod] separated by dot. 

objExpr::= <""?text> | \<:\><textExpr>\<\.\> | <numExpr>.



numExpr::=              bool ( <boolExpr> ) 
            | <multExpr?> [{ + <multExpr?addOperation> | - <multExpr?subOperation>}].


multExpr::= <value?> [{ * <value?multOperation> | / <value?divOperation> }].

value::= <#?intValue> | <#f?floatValue> |   ##unary - associated to value.
[{[<?unaryOperator> ! | ~ | - | + ]}]        ##additional unary operators.
[<#?intValue> | 0x<#x?intValue> | <#f?floatValue> ##ones of kind of value:
| '<!.?charValue>' | <""?textValue> 
| ( <numExpr?parenthesisExpr> ) 
| <datapath> 
].



condition::=<andExpr?> [{\|\| <andExpr?boolOrOperation>}].

andExpr::= <boolExpr?> [{ && <boolExpr?boolAndOperation>}].

boolExpr::= [<?boolNot> ! | not|]
[ ( <condition?parenthesisCondition> ) 
| <numExpr?> [<cmpOperation>]
].

cmpOperation::=[ \?[<?cmpOperator>gt|ge|lt|le|eq|ne] |  [<?cmpOperator> != | == | \>= | \> | \<= | \< ]] <numExpr?>.

conditionInText::=<andExprInText?> [{\|\| <andExprInText?boolOrOperation>}].

andExprInText::= <boolExprInText?> [{ && <boolExprInText?boolAndOperation>}].

boolExprInText::= [<?boolNot> ! | not|]
[ ( <conditionInText?parenthesisCondition> ) 
| <numExpr?> [<cmpOperationInText>]
].

cmpOperationInText::=[ \?[<?cmpOperator>gt|ge|lt|le|eq|ne] |  [<?cmpOperator> != | == ]] <numExpr?>.


##end part from ZText


forInput::= :<$?@target>: for ( <input?> ) : <string?dst> := exec <exec?> .   ##TODO use right side of target::=


##old: cmd::= cmd ( <string?executable>) [, { arg(<string?arg>) ? ,}].
execCmd::= cmd ( <string?executable> ) [, curdir ( <""?curdir> )] [ , { arg (  <string?arg> ) ? , }].

fileset::= [ commonpath = <file?commonpath> , ] { <file> ? , }.



file::=<""?!prepFilePath>|<*\ \r\n,)?!prepFilePath>.

##The translator is written like a function. It may be nested.
target::=[:<$?@targetName>:] <output> := <$?@translator> ( { <param> | <inputvalue> ? ,} ).


XXXtarget::=  [:<$?@target>:] 
[ <specials?do>  ##action without dst file. 
|
  ##<*|\ |\r|\n|:=?!prepOutputfile> :=  
  <output> :=
  [ for ( <input?> ) <routine?doForAll> 
  | <routine?>
  ##| exec <exec?>
  ##| <$?@translator> ( <input?> )
  ]
].

##The output will be parsed either in "" or all chars until whitespace or :=, than inner syntax.
output::=<*|\ |\r|\n|:=?!prepFilePath>.
##it doesn't work: output::=<""?!prepFilePath>|<*|\ |\r|\n|:=?!prepFilePath>.

routine::= 
  exec <exec?> 
|  <$?@translator> ( <inputlist?> )
.

specials::=
{ mkdir ( [ <""?mkdir>| <* )?mkdir>] )
| deltree ( [ <""?deltree>| <* )?deltree>] )
| exec <exec?>
? ,}.
?en:specials/mkdir::="creation of directory if not exists".
?en:specials/deltree::="delete of a directory tree or create if not exists".

exec::= \{ { [<execCmd> | $<$?execVariable/@name>] ; } \}.



##An input can be a file in "pathfile"
##Or an input can be a fileset given with a variable.
##Or an input can be a whole target in {....}
##Or an input can be a parameter, it is ident = "value"
##Or an input can be a filename without "" but to whitespace
##It is repeatable with , or + as separator.
inputlist::=<?>
{ <param> | <inputvalue>? , }.


inputvalue::=
##[ $<$?referVariable>[: [$$<$?srcpathEnvVariable>|$<$?srcpathVariable>|] [<""?srcpathTargetInput>|<*\
  \r\n,)?srcpathTargetInput>]]
##| 
[ \{ <target> \}
| & <$?fileset>
| [<""?!prepInputfile>| <*\ \r\n,)&?!prepInputfile>|] [ & <$?fileset> ]
##| $$<$?srcpathEnvVariable> [! ,| )]
##| $<$?srcpathVariable> [! ,| )]
##| <""?!prepInputfile>
##| <*\ \r\n,)&?!prepInputfile>
].


?input/srcext::="This extension should be added to any src file.".

prepInputfile::=<prepFilePath?input>.

##example: D:\path/path/file.c          normal path with \ or /
##example: D:srcpath:path/path/file.c   a special srcpath, inside a path
##example: D:srcpath:file.c             a special srcpath, inside a file directly
##example: srcpath:path/path/file.c     without drive, the drive has only one letter.

##NOTE ZBNF: [?:=] means: if := occurs, it doesnot match.
##NOTE ZBNF: [<*:?@pathbase>[?:=]:] means: all chars until ':', but the ':' must follow. it is optional.


prepFilePath::=<$NoWhiteSpaces><! *?>
[ $$<$?@envVariable> [\\|/|]     ##path can start with a environment variable's content
| $<$?@scriptVariable> [\\|/|]   ##path can start with a scriptvariable's content
| [<!.?@drive>:]                 ## only 1 char with followed : is the drive letter
  [ [/|\\]<?@absPath>]           ## starting with / is absolute path
|]  
[ <*:?@pathbase>[?:=]:]          ## all until : is pathbase, but not till a :=
[ <toLastChar:/\\?@path>[\\|/|]] ## all until last \\ or / is path
[ <toLastChar:.?@name>           ## all until exclusive dot is the name
  <*\e?@ext>                     ## from dot to end is the extension
| <*\e?@name>                    ## No dot is found, all is the name. 
] .


##  [ **<?@allTree><*?@ext>                     ## ** means: all files also in subfolders. The rest after** is
  extension.
##  | *<?@someFiles><*?@ext>                    ## * means: Some files or placeholder for the name. The rest after * is
  extension.
##  | <stringtolastExclChar.?@file><*?@ext>     ## or a filename and a extension if a . is found
##  | <*?@file>                                 ## or only a file if no . is found.
##  ]<! *?>.

##prepOutputfile::=<prepFilePath?output>.

##prepOutputFilePath::=[<+<</:\\?@path>]<*?@file>.

param::=<$?name> [ = <""?@value> | [ = | : ]{ <inputvalue> ? +} ] .
##[ <$?name> = [ <""?@value>]]   ##if given, it is a named parameter, with a possible value. If not given it is a input
  file or fileset.