-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStrategy.Highlighting.htm
163 lines (150 loc) · 5.24 KB
/
Strategy.Highlighting.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE HTML>
<html>
<head>
<title>La colorisation lexicale</title>
<link rel="stylesheet" type="text/css" href="src/css/styles.css">
<link rel="stylesheet" type="text/css" href="src/css/syntaxes.css">
<style>
.editor {
float: left;
width: 100%;
height:300px;
}
#eResult1 {
border: 1px solid #000;
}
</style>
</head>
<body spellcheck="false">
<a href="./index.htm">index</a>
<h1>La colorisation lexicale</h1>
<div><h2>Objectif</h2>
<p>Offrir et tester différents analyseurs lexicales ou syntaxiques. Celui par défaut :</p>
<ul>
<li>affiche les tabulations si désirées.</li>
<li>ne gère pas les tabulations souples.</li>
<li>n'affiche pas les sauts de lignes.</li>
<li>ne colorise rien de tout...</li>
</ul>
</div>
<div><h2>Diagramme</h2>
<img src="diagram/Class.Highlighting.gif">
</div>
<div><h2>Aperçu</h2>
<textarea id="eSource" wrap="off" style="width:45%; height:400px; display:none;"></textarea>
<label for="eStrategy">oEditor.oActiveDocument.oSyntax.setStrategy( </label>
<select id="eStrategy">
<option value="Default">Default</option>
<option value="Syntax" selected>Syntax</option>
</select>
<label for="eStrategy"> ) </label>
<a href="Strategy.Highlighting.Syntax.htm">Stratégie colorisation Syntax</a>
<div id="eEditeur1"></div>
<div id="eStats" class="stats"></div>
</div>
<div id="eContents"><!--var Highlighting:(function(){
var Strategies ={
Default :(function(){
var generateContents =function( s ){ // return array
var _SEPARATOR = "@GRR_END_LINE@"
, a = s.str_replace(
[ '&', '<', '>', /\t/g, /(\n|\r)/g ],
[ '&', '<', '>', Modules.Tabulation.HTML, Modules.NewLine.HTML+_SEPARATOR ]
).split( _SEPARATOR )
a.pop()
return a
}
return function( D ){
D.oTabulation.bSoftTab = D.bSoftTab = false
this.getElementsByTagName =function( sNodeName ){
return []
}
this.getContents =function(){
return generateContents( D.oSource.getValue())
}
this.getLine =function( nLine ){
return generateContents( D.oSource.getLine( nLine ))[0] || ''
}
this.getLines =function( nStart, nEnd ){
return generateContents( D.oSource.getLines( nStart, nEnd ))
}
this.update =function(){
var o = D.oUpdates
o.nLineShift = o.nLinesNew - o.nLinesOld
o.nLineStart = o.oDeleted.text ? o.oDeleted.nLineStart : o.oAdded.nLineStart
o.nLineEnd = o.oDeleted.text && o.oAdded.text
? Math.max( o.oDeleted.nLineEnd , o.oAdded.nLineEnd )
: ( o.oDeleted.text ? o.oDeleted.nLineEnd : o.oAdded.nLineEnd )
}
}
})()
}
var HS =function( D, sStrategyName ){
this.setStrategy =function( s ){
if( ! Strategies[ s ]) throw new Error ( '"'+ s +'" render strategy undefined.' )
this.oStrategy = new Strategies[ this.sStrategyName=s ](D)
}
this.setStrategy( this.sName = sStrategyName||'Default' )
}
HS.prototype={
getElementsByTagName :function( sNodeName ){ return this.oStrategy.getElementsByTagName( sNodeName )},
getContents :function(){ return this.oStrategy.getContents()},
getLine :function( nLine ){ return this.oStrategy.getLine( nLine )},
getLines :function( nStart, nEnd ){ return this.oStrategy.getLines( nStart, nEnd )},
update :function( oUpdates ){ return this.oStrategy.update( oUpdates )}
}
HS.get =function( s ){ return Strategies[ s ]}
HS.addStrategy =function( s, o ){
if( o.getContents && o.getLine && o.getLines && o.update )
return Strategies[ s ] = o
var oP = o.prototype
if( oP.getContents && oP.getLine && oP.getLines && oP.update )
return Strategies[ s ] = o
throw new Error (
'"'+ s +'" highlighting strategy is not valid.'
+ ( o.getContents ? '' : '\n getContents undefined.' )
+ ( o.getLine ? '' : '\n getLine undefined.' )
+ ( o.getLines ? '' : '\n getLines undefined.' )
+ ( o.update ? '' : '\n update undefined.' )
)
}
return HS
})()
--></div>
<script src="shared.js"></script>
<script src="src/js/Editor.js"></script>
<script src="src/js/Commands.js"></script>
<script src="src/js/KeyBoard.js"></script>
<script src="src/js/Selection.js"></script>
<script src="src/js/UndoStack.js"></script>
<!---->
<script src="src/js/Syntax.js"></script>
<script src="src/js/Fold.js"></script>
<script src="src/js/Brackets.js"></script>
<script src="src/js/TextMarker.js"></script>
<link rel="stylesheet" type="text/css" href="src/stats.css">
<script src="src/stats.js"></script>
<script>
_( 'eEditeur1,eSource,eContents,eTOKENS,eStats,eStrategy' )
eSource.value = eContents.firstChild.data
Events.add(
Editor.prototype, 'documentinit', function( D ){ D.oSyntax.setStrategy( eStrategy.value )},
eStrategy, 'change', function(){ oEditor.oActiveDocument.oSyntax.setStrategy( eStrategy.value )}
)
BenchmarkFunctions(
eStats, Editor.Strategies.Highlighting.prototype,
'getLine,getLines,getContents,getElementsByTagName,getElementsByLine,update'
)
var oEditor = new Editor ( eEditeur1, { bWhiteSpaces: 1, sSyntax:'JS' })
var D = oEditor.newDoc( 'Source', eSource.value )
var F=oEditor.oActiveDocument.oFold
F.fold( 3, true )
F.fold( 10, true )
F.fold( 13, true )
oEditor.execCommand( 'FOLD_LEVEL_5' )
</script>
<link rel="stylesheet" type="text/css" href="src/toc.css">
<script src="src/toc.js"></script>
<script>setTOC("Strategy.Highlighting.htm")</script>
</body>
</html>