import
[web.mtrack] / inc / hyperlight / python.php
1 <?php
2
3 # TODO
4 # Implement correct number formats (don't forget imaginaries)
5 # Implement correct string/bytes formats (escape sequences)
6 # Add type “keywords”?
7 # <http://docs.python.org/dev/3.0/reference/lexical_analysis.html>
8
9 class PythonLanguage extends HyperLanguage {
10     public function __construct() {
11         $this->setInfo(array(
12             parent::NAME => 'Python',
13             parent::VERSION => '0.1',
14             parent::AUTHOR => array(
15                 parent::NAME => 'Konrad Rudolph',
16                 parent::WEBSITE => 'madrat.net',
17                 parent::EMAIL => 'konrad_rudolph@madrat.net'
18             )
19         ));
20
21         $this->setExtensions(array('py'));
22
23         $this->setCaseInsensitive(false);
24
25         $this->addStates(array(
26             'init' => array(
27                 'string',
28                 'bytes',
29                 'number',
30                 'comment',
31                 'keyword' => array('', 'literal', 'operator'),
32                 'identifier'
33             ),
34         ));
35
36         $this->addRules(array(
37             'string' => Rule::C_DOUBLEQUOTESTRING,
38             'bytes' => Rule::C_SINGLEQUOTESTRING,
39             'number' => Rule::C_NUMBER,
40             'comment' => '/#.*/',
41             'keyword' => array(
42                 array(
43                     'assert', 'break', 'class', 'continue', 'def', 'del',
44                     'elif', 'else', 'except', 'finally', 'for', 'from',
45                     'global', 'if', 'import', 'in', 'lambda', 'nonlocal',
46                     'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'
47                 ),
48                 'literal' => array(
49                     'False', 'None', 'True'
50                 ),
51                 'operator' => array(
52                     'and', 'as', 'is', 'not', 'or'
53                 )
54             ),
55             'identifier' => Rule::C_IDENTIFIER,
56         ));
57
58         $this->addMappings(array(
59             'bytes' => 'char'
60         ));
61     }
62 }
63
64 ?>