// Special manipulation if we are going to write a new paragraph
function handleBeginningOfParagraph(bBeginningOfParagraph : node) {
if bBeginningOfParagraph {
@@
bBeginningOfParagraph = false;
}
}
TrafficLight2OASIS ::=
=> {
// Invariant part of the document, such as styles
@
@
}
=> local bBeginningOfParagraph = true;
// consume token by token
[
// an identifier: keyword or function of the language or sensor
#readIdentifier:sWord
=> handleBeginningOfParagraph(bBeginningOfParagraph);
[
// a keyword
#check(sWord in {"activate", "desactivate", "duration", "start", "strategy"})
=> {@@sWord@@}
|
// the sensor: 'hour' is displayed in subscript
#check(sWord == "vehicles_hour")
=> {@vehicleshour@}
|
// a function
#check(sWord == "time")
=> {@@sWord@@}
|
// other
=> {@@sWord@@}
]
|
// a constant string
#readCString:sText
=> handleBeginningOfParagraph(bBeginningOfParagraph);
=> {@"@sText.composeHTMLLikeString()@"@}
|
// symbols to highlight
["=>" | "->"]:sSymbol
=> handleBeginningOfParagraph(bBeginningOfParagraph);
=> {@@sSymbol.composeHTMLLikeString()@@}
|
// multi-line comment
!!"/*"
=> handleBeginningOfParagraph(bBeginningOfParagraph);
[->"*/"]:sComment
=> {@@sComment.composeHTMLLikeString()@@}
|
// inline comment
!!"//"
=> handleBeginningOfParagraph(bBeginningOfParagraph);
[~[['\r']? '\n']]*:sComment
=> {@@sComment.composeHTMLLikeString()@@}
|
// special case: tabulation
'\t'
=> handleBeginningOfParagraph(bBeginningOfParagraph);
=> {@@}
|
// special case: end of paragraph
['\r']? '\n'
=> {
if bBeginningOfParagraph {
@@
} else {
bBeginningOfParagraph = true;
}
@@
}
|
// any other non-empty character
#readChar:cChar
=> handleBeginningOfParagraph(bBeginningOfParagraph);
=>{@@cChar.composeHTMLLikeString()@@}
]*
=> {
// may have a paragraph to close
if !bBeginningOfParagraph {
@@
}
local sFileName = getShortFilename(getInputFilename());
local sPictureFile = sFileName.rsubString(4) + ".png";
if sFileName.endString(".tlc") && sPictureFile.existFile() {
// reference the PNG diagram of the strategy in the document and
// copy it to the directory devoted to pictures
copyFile(sPictureFile, "OpenOffice2.0/Pictures/" + sPictureFile);
@@
@@
}
// end of the document
@@
}
;