| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Highlighter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Copyright (C) 2016, Some right reserved. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @author Kacper "Kadet" Donat <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * Contact with author: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Xmpp: [email protected] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * E-mail: [email protected] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * From Kadet with love. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | namespace Kadet\Highlighter\Language; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Kadet\Highlighter\Matcher\CommentMatcher; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Kadet\Highlighter\Matcher\RegexMatcher; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Kadet\Highlighter\Matcher\WordMatcher; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Kadet\Highlighter\Parser\CloseRule; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Kadet\Highlighter\Parser\OpenRule; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Kadet\Highlighter\Parser\Rule; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use Kadet\Highlighter\Parser\Token\LanguageToken; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use Kadet\Highlighter\Parser\Token\TerminatorToken; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use Kadet\Highlighter\Parser\TokenFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use Kadet\Highlighter\Parser\Validator\Validator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | class Assembler extends GreedyLanguage | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     protected $registers = ['[re]?[abcd]x', '[abcd][lh]', 'r\d{1,2}', '[re]?[sd]i', '[re]?[si]p', '[re]?flags']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * Tokenization rules setup | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     public function setupRules() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $this->rules->addMany([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             'call' => new Rule(new RegexMatcher('/^\h*(\w[\w\.]*)/im')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             'operator.escape' => new Rule(new RegexMatcher('/(\\\(?:\R|.|[0-7]{3}|x\x{2}))/s'), [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                 'context' => Validator::everywhere() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             'keyword.format' => new Rule( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                 new RegexMatcher('/(%[diuoxXfFeEgGaAcspn%][-+#0]?(?:[0-9]+|\*)?(?:\.(?:[0-9]+|\*))?)/'), [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                     'context' => ['string'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                 ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                 'context' => ['!operator.escape', '!comment', '!string'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             'symbol' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                 'type'  => new Rule(new WordMatcher(['byte', 'word', 'dword', 'qword']), ['name' => 'builtin']), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 'label' => new Rule(new RegexMatcher('/([a-z]\w+:)/i'), ['priority'=>3]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             'comment' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                 new Rule(new CommentMatcher([';'], []), ['priority' => 2]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             'variable.register' => new Rule(new RegexMatcher('/\b('.implode('|', $this->registers).')\b/i')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             'number' => new Rule(new RegexMatcher('/\b(-?[0-9][0-9a-fA-F]*[tTdDhHOoqQbByY]?)\b/i')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             'operator' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                 'punctuation' => new Rule(new RegexMatcher('/(,)/'), ['priority' => 0]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 new Rule(new RegexMatcher('/([*+-])/'), ['priority' => 0]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * Unique language identifier, for example 'php' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     public function getIdentifier() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         return 'c'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |     public static function getMetadata() | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 84 |  |  |         return [ | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |             'name'      => ['asm', 'assembler'], | 
            
                                                        
            
                                    
            
            
                | 86 |  |  |             'mime'      => ['text/x-asm'], | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |             'extension' => ['*.asm'] | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |         ]; | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 90 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |  |