Skip to content

Commit

Permalink
* fixed some small bugs in OMNotebook
Browse files Browse the repository at this point in the history
* updated Mathematica parser in OMNotebook
* updated the OMNotebookHelp.onb documentation
* converted DrModelica to OMNotebook
// Anders Fernström

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2247 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x05andfe committed Mar 24, 2006
1 parent 9b27ec1 commit 968d4b9
Show file tree
Hide file tree
Showing 30 changed files with 685 additions and 399 deletions.
28 changes: 25 additions & 3 deletions OMNotebook/NotebookParser/lexer.g
Expand Up @@ -69,12 +69,14 @@ tokens
{
MODULENAME = "FrontEnd";
LIST = "List";
LIST_SMALL = "list";
NOTEBOOK = "Notebook";
CELL = "Cell";
TEXTDATA = "TextData";
CELLGROUPDATA = "CellGroupData";

RULE = "Rule";
RULE_SMALL = "rule";
RULEDELAYED = "RuleDelayed";

GRAYLEVEL = "GrayLevel";
Expand All @@ -100,9 +102,17 @@ tokens
FRACTIONBOX = "FractionBox";
SQRTBOX = "SqrtBox";
RADICALBOX = "RadicalBox";
DIREXTEDINFINITY = "DirectedInfinity";
NOT_MATH_STARTMODELEDITOR = "StartModelEditor";
NOT_MATH_OLEDATE = "OLEData";
INTERPRETATIONBOX = "InterpretationBox";
ANNOTATION = "Annotation";
EQUAL = "Equal";
DIAGRAM = "Diagram";
ICON = "Icon";
POLYGON = "Polygon";
ELLIPSE = "Ellipse";
LINE = "Line";
DIREXTEDINFINITY = "DirectedInfinity";
NOT_MATH_STARTMODELEDITOR = "StartModelEditor";
NOT_MATH_OLEDATE = "OLEData";

//ATTRIBUTE
FONTSLANT = "FontSlant";
Expand All @@ -127,6 +137,7 @@ tokens
LINESPACING = "LineSpacing";
HYPHENATION = "Hyphenation";
ACTIVE_TOKEN = "Active";
VISIBLE_TOKEN = "Visible";
EVALUATABLE = "Evaluatable";
BUTTONFUNCTION = "ButtonFunction";
BUTTONDATA = "ButtonData";
Expand All @@ -147,6 +158,10 @@ tokens
DEFAULTFORMATTYPE = "DefaultFormatType";
NUMBERMARKS = "NumberMarks";
LINEBREAKADJUSTMENTS = "LinebreakAdjustments";
VISIOLINEFORMAT = "VisioLineFormat";
VISIOFILLFORMAT = "VisioFillFormat";
EXTENT = "Extent";
NAMEPOSITION = "NamePosition";

//CELLOPTIONS
CELLTAGS = "CellTags";
Expand All @@ -160,6 +175,7 @@ tokens
CELLMARGINS = "CellMargins";
CELLDINGBAT = "CellDingbat";
CELLHORIZONTALSCROLL = "CellHorizontalScrolling";
CELLOPEN = "CellOpen";
CELLGENERATED = "GeneratedCell";
SHOWCELLBRACKET = "ShowCellBracket";
SHOWCELLLABEL = "ShowCellLabel";
Expand All @@ -183,6 +199,8 @@ tokens
SCREENSTYLEENV = "ScreenStyleEnvironment";
PRINTINGSTYLEENV = "PrintingStyleEnvironment";
PRINTINGOPTIONS = "PrintingOptions";
PRINTINGCOPIES = "PrintingCopies";
PRINTINGPAGERANGE = "PrintingPageRange";
PRIVATEFONTOPTIONS = "PrivateFontOptions";

//ANNAT
Expand Down Expand Up @@ -213,6 +231,7 @@ tokens
IMAGEREGION = "ImageRegion";
IMAGERANGECACHE = "ImageRangeCache";
IMAGECACHE = "ImageCache";
NOT_MATH_MODELEDITOR = "ModelEditor";
GENERATECELL = "GenerateCell";
CELLAUTOOVRT = "CellAutoOverwrite";
MAGNIFICATION = "Magnification";
Expand Down Expand Up @@ -267,6 +286,9 @@ EXP
protected
DIGIT
: '0'..'9'
| '`'
| '*'
| '^'
;

/*
Expand Down
44 changes: 32 additions & 12 deletions OMNotebook/NotebookParser/parser.g
Expand Up @@ -52,8 +52,9 @@ expr
;

exprheader
: NOTEBOOK^ LBRACK! expr (COMMA! rule)* RBRACK!
| LIST^ LBRACK! listbody (COMMA! listbody)* RBRACK!
: NOTEBOOK^ LBRACK! expr (COMMA! rule)* RBRACK!
| LIST^ LBRACK! (listbody)* (COMMA! listbody)* RBRACK!
| LIST_SMALL^ LBRACK! (listbody)* (COMMA! listbody)* (COMMA! rule)* RBRACK!
| CELL^ LBRACK! expr (COMMA! expr)? (COMMA! rule)* RBRACK!
| CELLGROUPDATA^ LBRACK! expr (COMMA! (CELLGROUPOPEN|CELLGROUPCLOSED)) RBRACK!

Expand All @@ -70,20 +71,29 @@ exprheader
| SQRTBOX^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| RADICALBOX^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| ROWBOX^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| GRIDBOX^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| FORMBOX^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| TAGBOX^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| COUNTERBOX^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| ADJUSTMENTBOX^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| BUTTONBOX^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| GRAYLEVEL^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| NOT_MATH_OLEDATE^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| RGBCOLOR^ LBRACK! NUMBER COMMA! NUMBER COMMA! NUMBER RBRACK!
| FILENAME^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| BOXDATA^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| GRAPHICSDATA^ LBRACK! QSTRING COMMA! QSTRING (COMMA! rule!)* RBRACK!
| DIREXTEDINFINITY^ LBRACK! NUMBER RBRACK!
| NOT_MATH_STARTMODELEDITOR! LBRACK! RBRACK!
| PARENTDIRECTORY! LBRACK! RBRACK!
| INTERPRETATIONBOX^ LBRACK! expr COMMA! expr RBRACK!
| ANNOTATION^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| EQUAL^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| DIAGRAM^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| ICON^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| POLYGON^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| ELLIPSE^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| LINE^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| GRAYLEVEL^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| NOT_MATH_OLEDATE^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| RGBCOLOR^ LBRACK! NUMBER COMMA! NUMBER COMMA! NUMBER RBRACK!
| FILENAME^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| BOXDATA^ LBRACK! expr (COMMA! expr)* (COMMA! rule)* RBRACK!
| GRAPHICSDATA^ LBRACK! QSTRING COMMA! QSTRING (COMMA! rule!)* RBRACK!
| DIREXTEDINFINITY^ LBRACK! NUMBER RBRACK!
| NOT_MATH_STARTMODELEDITOR! LBRACK! RBRACK!
| PARENTDIRECTORY! LBRACK! RBRACK!
;

listbody
Expand All @@ -92,6 +102,7 @@ listbody

rule
: RULE^ LBRACK! expr (COMMA! expr) RBRACK!
| RULE_SMALL^ LBRACK! expr (COMMA! expr) RBRACK!
| RULEDELAYED^ LBRACK! expr (COMMA! expr) RBRACK!
;

Expand Down Expand Up @@ -141,6 +152,7 @@ attribute
| LINESPACING
| HYPHENATION
| ACTIVE_TOKEN
| VISIBLE_TOKEN
| EVALUATABLE
| BUTTONFUNCTION
| BUTTONDATA
Expand All @@ -161,6 +173,10 @@ attribute
| DEFAULTFORMATTYPE
| NUMBERMARKS
| LINEBREAKADJUSTMENTS
| VISIOLINEFORMAT
| VISIOFILLFORMAT
| EXTENT
| NAMEPOSITION
| CELLTAGS
| CELLFRAME
| CELLFRAMECOLOR
Expand All @@ -172,6 +188,7 @@ attribute
| CELLMARGINS
| CELLDINGBAT
| CELLHORIZONTALSCROLL
| CELLOPEN
| CELLGENERATED
| SHOWCELLBRACKET
| SHOWCELLLABEL
Expand All @@ -193,6 +210,8 @@ attribute
| SCREENSTYLEENV
| PRINTINGSTYLEENV
| PRINTINGOPTIONS
| PRINTINGCOPIES
| PRINTINGPAGERANGE
| PRIVATEFONTOPTIONS
| MAGNIFICATION
| GENERATEDCELL
Expand All @@ -201,5 +220,6 @@ attribute
| IMAGEMARGINS
| IMAGEREGION
| IMAGERANGECACHE
| IMAGECACHE
| IMAGECACHE
| NOT_MATH_MODELEDITOR
;
100 changes: 90 additions & 10 deletions OMNotebook/NotebookParser/walker.g
Expand Up @@ -27,6 +27,7 @@ header {
#include "rule.h"
#include "factory.h"
#include "stripstring.h"
#include "xmlnodename.h"

using namespace std;
using namespace IAEX;
Expand Down Expand Up @@ -79,9 +80,11 @@ options
//This is not very nice.

// AF
bool imagePartOfText;
bool imagePartOfText;
bool convertingToONB;
int readmode_;
}
document[Cell *ws, Factory *f]
document[Cell *ws, Factory *f, int readmode]
{
//This is in NotebookTreeParser.cpp
factory = f;
Expand All @@ -90,6 +93,12 @@ document[Cell *ws, Factory *f]

// AF
imagePartOfText = false;
readmode_ = readmode;

if( readmode_ == READMODE_CONVERTING_ONB )
convertingToONB = true;
else
convertingToONB = false;


result_t result(output);// = new result_t; //??
Expand Down Expand Up @@ -348,11 +357,34 @@ exprheader [result_t &result]
// have to insert # symbol
filename = StripString::fixFilename( filename );

// 2006-03-21 AF, if convertion to ONB - replace .nb with .onb
if( convertingToONB )
{
string::size_type index = filename.find( ".nb" );
if( index != string::npos )
{
filename.replace( index, 3, ".onb" );
}
}


result.first << "<a href=\"" << filename << "\">"
<< buttonTitle.first.str() << "</a>";
}
| {
|
{
// InpterpretationBox contains hidden information in Mathematica
ostringstream boxesoutput;
result_t boxes(boxesoutput);

ostringstream interpretationdataoutput;
result_t interpretationdata(interpretationdataoutput);
}
#(INTERPRETATIONBOX expr[boxes] expr[interpretationdata])
{
}
|
{
ostringstream diroutput;
ostringstream filenameoutput;
result_t dir(diroutput);
Expand All @@ -370,7 +402,7 @@ exprheader [result_t &result]
|
{
}
#(GRAPHICSDATA type:QSTRING data:QSTRING)
#(GRAPHICSDATA type:QSTRING data:QSTRING)
{
}
|
Expand All @@ -397,7 +429,9 @@ exprheader [result_t &result]
else
result.first << "7777:3333:2222";
}
| #(LIST_SMALL expr[result] (expr[result])* (rule[rules])*)
| #(ROWBOX expr[result] (expr[result])* (rule[rules])*)
| #(GRIDBOX expr[result] (expr[result])* (rule[rules])*)
| #(FORMBOX expr[result] (expr[result])* (rule[rules])*)
| #(TAGBOX expr[result] (expr[result])* (rule[rules])*)
| #(COUNTERBOX expr[result] (expr[result])* (rule[rules])*)
Expand All @@ -406,12 +440,19 @@ exprheader [result_t &result]
| #(UNDERSCRIPTBOX expr[result] (expr[result])* (rule[rules])*)
| #(OVERSCRIPTBOX expr[result] (expr[result])* (rule[rules])*)
| #(UNDEROVERSCRIPTBOX expr[result] (expr[result])* (rule[rules])*)
| #(FRACTIONBOX expr[result] (expr[result])* (rule[rules])*)
| #(SQRTBOX expr[result] (expr[result])* (rule[rules])*)
| #(RADICALBOX expr[result] (expr[result])* (rule[rules])*)
| #(GRAYLEVEL expr[result] (expr[result])* (rule[rules])*)
| #(STYLEDATA expr[result] (expr[result])* (rule[rules])*)
| #(NOT_MATH_OLEDATE expr[result] (expr[result])* (rule[rules])*)
| #(FRACTIONBOX expr[result] (expr[result])* (rule[rules])*)
| #(SQRTBOX expr[result] (expr[result])* (rule[rules])*)
| #(RADICALBOX expr[result] (expr[result])* (rule[rules])*)
| #(ANNOTATION expr[result] (expr[result])* (rule[rules])*)
| #(EQUAL expr[result] (expr[result])* (rule[rules])*)
| #(DIAGRAM expr[result] (expr[result])* (rule[rules])*)
| #(ICON expr[result] (expr[result])* (rule[rules])*)
| #(POLYGON expr[result] (expr[result])* (rule[rules])*)
| #(ELLIPSE expr[result] (expr[result])* (rule[rules])*)
| #(LINE expr[result] (expr[result])* (rule[rules])*)
| #(GRAYLEVEL expr[result] (expr[result])* (rule[rules])*)
| #(STYLEDATA expr[result] (expr[result])* (rule[rules])*)
| #(NOT_MATH_OLEDATE expr[result] (expr[result])* (rule[rules])*)
;

listelement[result_t &list]
Expand Down Expand Up @@ -441,6 +482,9 @@ rule [rules_t &rules]
//rules.push_back(Rule(attribute.first.str(), value.first.str()));
rules.push_back(rule_t(attribute.first.str(), value.first.str()));
}
| #(RULE_SMALL expr[attribute] expr[value])
{
}
| #(RULEDELAYED expr[attribute] expr[value])
{
//rules.push_back(Rule(attribute.first.str(), value.first.str()));
Expand Down Expand Up @@ -625,6 +669,10 @@ attribute returns [string value]
{
value = string(activetoken->getText());
}
| visibletoken:VISIBLE_TOKEN
{
value = string(visibletoken->getText());
}
| evaluatable:EVALUATABLE
{
value = string(evaluatable->getText());
Expand Down Expand Up @@ -705,6 +753,22 @@ attribute returns [string value]
{
value = string(linebreakadjustments->getText());
}
| visiolineformat:VISIOLINEFORMAT
{
value = string(visiolineformat->getText());
}
| visiofillformat:VISIOFILLFORMAT
{
value = string(visiofillformat->getText());
}
| extent:EXTENT
{
value = string(extent->getText());
}
| nameposition:NAMEPOSITION
{
value = string(nameposition->getText());
}
| celltags:CELLTAGS
{
value = string(celltags->getText());
Expand Down Expand Up @@ -749,6 +813,10 @@ attribute returns [string value]
{
value = string(cellhorizontalscrolling->getText());
}
| cellopen:CELLOPEN
{
value = string(cellopen->getText());
}
| cellgenerated:CELLGENERATED
{
value = string(cellgenerated->getText());
Expand Down Expand Up @@ -833,6 +901,14 @@ attribute returns [string value]
{
value = string(printingoptions->getText());
}
| printingcopies:PRINTINGCOPIES
{
value = string(printingcopies->getText());
}
| printingpagerange:PRINTINGPAGERANGE
{
value = string(printingpagerange->getText());
}
| privatefontoption:PRIVATEFONTOPTIONS
{
value = string(privatefontoption->getText());
Expand Down Expand Up @@ -869,4 +945,8 @@ attribute returns [string value]
{
value = string(imagecache->getText());
}
| modeleditor:NOT_MATH_MODELEDITOR
{
value = string(modeleditor->getText());
}
;

0 comments on commit 968d4b9

Please sign in to comment.