~ivle-dev/ivle/codemirror

« back to all changes in this revision

Viewing changes to ivle/webapp/filesystem/browser/media/codemirror/contrib/php/index.html

  • Committer: David Coles
  • Date: 2010-05-31 10:38:53 UTC
  • Revision ID: coles.david@gmail.com-20100531103853-8xypjpracvwy0qt4
Editor: Added CodeMirror-0.67 Javascript code editor source from 
http://marijn.haverbeke.nl/codemirror/ (zlib-style licence)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!--
 
2
Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved.
 
3
The copyrights embodied in the content of this file are licensed by
 
4
Yahoo! Inc. under the BSD (revised) open source license
 
5
 
 
6
@author Dan Vlad Dascalescu <dandv@yahoo-inc.com>
 
7
 
 
8
-->
 
9
 
 
10
 
 
11
<html xmlns="http://www.w3.org/1999/xhtml">
 
12
  <head>
 
13
    <script src="../../js/codemirror.js" type="text/javascript"></script>
 
14
    <title>CodeMirror: PHP+HTML+JavaScript+CSS mixed-mode demonstration</title>
 
15
    <link rel="stylesheet" type="text/css" href="../../css/docs.css"/>
 
16
  </head>
 
17
  <body style="padding: 20px;">
 
18
 
 
19
    <p>This is a complex demonstration of the <b>PHP+HTML+JavaScript+CSS mixed-mode
 
20
    syntax highlight</b> capabilities of <a href="../../index.html">CodeMirror</a>.
 
21
    &lt;?php ... ?> tags use the PHP parser, &lt;script> tags use the JavaScript
 
22
    parser, and &lt;style> tags use the CSS parser. The rest of the content is
 
23
    parsed using the XML parser in HTML mode.</p>
 
24
 
 
25
    <p>Features of the PHP parser:
 
26
    <ul>
 
27
      <li>special "deprecated" style for PHP4 keywords like 'var'
 
28
      <li>support for PHP 5.3 keywords: 'namespace', 'use'
 
29
      <li>911 predefined constants, 1301 predefined functions, 105 predeclared classes
 
30
        from a typical PHP installation in a LAMP environment
 
31
      <li>new feature: syntax error flagging, thus enabling strict parsing of:
 
32
        <ol>
 
33
          <li>function definitions with explicitly or implicitly typed arguments and default values
 
34
          <li>modifiers (public, static etc.) applied to method and member definitions
 
35
          <li>foreach(array_expression as $key [=> $value]) loops
 
36
        </ol>
 
37
      <li>differentiation between single-quoted strings and double-quoted interpolating strings
 
38
    </ul>
 
39
    </p>
 
40
 
 
41
    <div style="border: 1px solid black; padding: 3px; background-color: #F8F8F8">
 
42
    <textarea id="code" cols="120" rows="30">
 
43
The "root" parser is XML in HTML mode.
 
44
Next, we can switch into PHP mode, for example. This is
 
45
<?php echo 'text output by';
 
46
?>
 
47
PHP. </b>
 
48
On the line above, we just had an XML syntax error due to the </b> tag not being opened.
 
49
 
 
50
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>   HTML text will follow
 
51
<html>
 
52
  <head>
 
53
    <title>Similarly, the 'script' tag will switch to the JavaScript parser:</title>
 
54
    <script type="text/javascript">
 
55
       // Press enter inside the object and your new line will be suitably
 
56
       // indented.
 
57
       var keyBindings = {
 
58
         enter: "newline-and-indent",
 
59
         tab: "reindent-selection",
 
60
         ctrl_enter: "reparse-buffer",
 
61
         ctrl_z: "undo",
 
62
         ctrl_y: "redo",
 
63
         ctrl_backspace: "undo-for-safari-which-stupidly-enough-blocks-ctrl-z"
 
64
       };
 
65
 
 
66
       // Press tab on the next line and the wrong indentation will be fixed.
 
67
             var regex = /foo|bar/i;
 
68
 
 
69
       function example(x) {
 
70
         // Local variables get a different colour than global ones.
 
71
         var y = 44.4;
 
72
         return x + y - z;
 
73
       }
 
74
    </script>
 
75
    <style>
 
76
      /* Some example CSS */
 
77
 
 
78
      @import url("something.css");
 
79
 
 
80
      body {
 
81
        margin: 0;
 
82
        padding: 3em 6em;
 
83
        font-family: tahoma, arial, sans-serif;
 
84
        color: #000;
 
85
      }
 
86
 
 
87
      #navigation a {
 
88
        font-weight: bold;
 
89
        text-decoration: none !important;
 
90
      }
 
91
 
 
92
      h1 {
 
93
        font-size: 2.5em;
 
94
      }
 
95
 
 
96
      h1:before, h2:before {
 
97
        content: "::";
 
98
      }
 
99
 
 
100
      code {
 
101
        font-family: courier, monospace;
 
102
        font-size: 80%;
 
103
        color: #418A8A;
 
104
      }
 
105
    </style>
 
106
  </head>
 
107
 
 
108
  <body>
 
109
 
 
110
  The PHP code below contains some deliberate errors. Play with the editor by fixing them
 
111
  and observing how the highlight changes.
 
112
 
 
113
    <?php
 
114
    namespace A;
 
115
    namespace A::B::C;
 
116
    namespace A::::B;
 
117
    namespace A::B::C::;
 
118
    namespace A::B::C::D x;
 
119
    self::range($row['lft'], $row['rgt']));  // error: extra ')'
 
120
    $a = (b() + 4) 5 foo;  // error: missing operators
 
121
    self::$var;
 
122
    $parent = self::range($max + 1, $max + 1);
 
123
    $row[attributes][$attribute_name] = $attribute_value;
 
124
    $row[attributes()][$attribute_name] = $attribute_value;
 
125
    $row[attributes(5)][$attribute_name] = $attribute_value;
 
126
    $row[$attributes()][$attribute_name] = $attribute_value;
 
127
    abstract class 5 extends foo implements echo {
 
128
        private function domainObjectBuilder() {
 
129
            return $this->use_domain_object_builder
 
130
                   ? $this->domain()->objectBuilder()
 
131
                   : null;
 
132
        }
 
133
 
 
134
        const $myconst = 'some string';
 
135
        $array[myconst] = 4;
 
136
        // this is a single-line C++-style comment
 
137
        # this is a single-line shell-style comment
 
138
        private var $a = __FILE__;
 
139
        protected static $b = timezone_transitions_get('some parameter here');
 
140
        global $g = isset("string");
 
141
        static $s = hash_update_file;  // warning: predefined function non-call
 
142
        function mike ($var) $foo;
 
143
        mike(A::func(param));
 
144
        func($b $c);  // error: function parameters must be comma-separated
 
145
        foo bar;  // error: no operator
 
146
        $baz $quux;  // error: no operator
 
147
        public abstract function loadPageXML(util_FilePath $filename, $merge=0+$foo, $x, $y=3) {
 
148
            $newrow[$key] = $val;
 
149
            $newresult[] = $row;
 
150
            $state = $row['c'] == 1;
 
151
            $attribute_values[$attribute_name] = null;
 
152
            $row['attributes'][$attribute_name] = $attribute_value;
 
153
            $result[$row['element']][$row['attribute']] = $row['value'];
 
154
            $sql = "multiline string
 
155
line2 is special - it'll interpolate variables like $state and method calls
 
156
{$this->cache->add($key, 5)} and maybe \"more\"
 
157
 
 
158
line5";
 
159
            $sql = 'multiline string
 
160
single quoting means no \'interpolation\' like "$start" or method call
 
161
{$this->cache->add($key, 5)} will happen
 
162
 
 
163
line5';
 
164
            $bitpattern = 1 << 2;
 
165
            $bitpattern <<= 3;
 
166
            $incorrect = <<< 5 EOSTRING  // FIXME: CodeMirror update bug: add a letter before 5 and notice that syntax is not updated until EOF, even with continuousScanning: 500
 
167
error: the identifier must conform to the identifier rules
 
168
EOSTRING;
 
169
            $sql = <<< EOSQL
 
170
                SELECT attribute, element, value
 
171
                FROM attribute_values
 
172
                WHERE dimension = ?
 
173
EOSQL;
 
174
            $this->lr_cache->add($key, self::range($row['lft'], $row['rgt']));
 
175
            $composite_string = <<<EOSTRING
 
176
some lines here
 
177
EOSTRING
 
178
. 'something extra';
 
179
            $page_lft = ($domain->name() == 'page') ? $start + 1 : $page_start + 1;
 
180
            echo "This is class foo";
 
181
            echo "a = ".$this ->a[2+3*$array["foo"]]."";
 
182
            echo "b = {$this->b}";  // FIXME: highlight interpolation in strings
 
183
        }
 
184
        final function makecoffee error($types = array("cappuccino"), $coffeeMaker = NULL) {
 
185
            $out_of_way_amount = $max - $child->left() + 1;
 
186
            $absolute_pos = $child->left() - $move->width();
 
187
            $varfunc(1, 'x');
 
188
            $varfunc(1, 'x') + foo() - 5;
 
189
            $funcarray[$i]('param1', $param2);
 
190
                $lr[$domain_name] = $this->get_left_and_right($domain,
 
191
                                                              $dimension_name,
 
192
                                                              $element_name);
 
193
            $domain_list = is_null($domain) ?
 
194
                           r3_Domain::names() :
 
195
                           array($domain->name());
 
196
            foreach (r3_Domain::names() as $domain_name) {
 
197
                $placeholders = 'distance LIKE '
 
198
                            . implode(array_fill(1, $num_distances, '?'),
 
199
                                      ' OR distance LIKE ');
 
200
 
 
201
            }
 
202
            return $this->target*$this->trans+myfunc(__METHOD__);
 
203
            /*
 
204
            echo 'This is a test'; /* This comment will cause a problem */
 
205
            */
 
206
        }
 
207
        switch( $type ) {
 
208
            case "r3core_AddTemplateToTargetEvent":
 
209
                $this->notifyAddTemplateToTarget( $genevent );
 
210
                break;
 
211
            case "r3core_GenerateTargetEvent" $this:
 
212
                for($i=0; $i<=this->method(); $i++) {
 
213
                    echo 'Syntax "highlighting"';
 
214
                }
 
215
                try {
 
216
                    foreach($array xor $loader->parse_fn($filename) as $key => value) {
 
217
                        namespace r3;
 
218
                    }
 
219
                } catch( Exception $e ) {
 
220
                    /** restore the backup
 
221
                    */
 
222
                    $this->loadAll($tmp, $event, true);
 
223
                    // `php -l` doesn't complain at all at this (it assumes string constants):
 
224
                    this + makes * no - sense;
 
225
                }
 
226
 
 
227
                break;
 
228
 
 
229
            default moo:
 
230
                throw new r3_util_Exception( get_class( $genevent ) . " does not map" );
 
231
        }
 
232
 
 
233
 
 
234
    };
 
235
 
 
236
    ?>
 
237
 
 
238
    <r3:cphp>
 
239
        php("works", $here, 2);
 
240
    </r3:cphp>
 
241
 
 
242
    <r4:cphp>
 
243
    class foo {
 
244
        // a comment
 
245
        var $a;
 
246
        var $b;
 
247
    };
 
248
    </r4:cphp>
 
249
 
 
250
  <h1>This is an <?php # echo 'simple';?> example.</h1>
 
251
  <p>The header above will say 'This is an  example'.</p>
 
252
  <h1>This is an <?php // echo 'simple';?> example.</h1>
 
253
 
 
254
  <?php echo; ?>
 
255
    <body>
 
256
 
 
257
<?php echo "<html>
 
258
  <head>
 
259
    <script>
 
260
    var foo = 'bar';
 
261
    </script>
 
262
    <style>
 
263
      span.test {font-family: arial, 'lucida console', sans-serif}
 
264
    </style>
 
265
  </head>
 
266
  <body>
 
267
    <!-- comment -->
 
268
  </body>
 
269
</html>"; ?>
 
270
 
 
271
</body>
 
272
</html>
 
273
 
 
274
 
 
275
    </textarea>
 
276
    </div>
 
277
 
 
278
    <script type="text/javascript">
 
279
      var editor = CodeMirror.fromTextArea('code', {
 
280
        height: "350px",
 
281
        parserfile: ["parsexml.js", "parsecss.js", "tokenizejavascript.js", "parsejavascript.js",
 
282
                     "../contrib/php/js/tokenizephp.js", "../contrib/php/js/parsephp.js",
 
283
                     "../contrib/php/js/parsephphtmlmixed.js"],
 
284
        stylesheet: ["../../css/xmlcolors.css", "../../css/jscolors.css", "../../css/csscolors.css", "css/phpcolors.css"],
 
285
        path: "../../js/",
 
286
        continuousScanning: 500
 
287
      });
 
288
    </script>
 
289
 
 
290
 
 
291
  </body>
 
292
</html>