comparison vendor/gems/coderay-0.9.7/test/functional/.svn/text-base/vhdl.rb.svn-base @ 210:0579821a129a

Update to Redmine trunk rev 4802
author Chris Cannam
date Tue, 08 Feb 2011 13:51:46 +0000
parents
children
comparison
equal deleted inserted replaced
128:07fa8a8b56a8 210:0579821a129a
1 class VHDL < CodeRay::Scanners::Scanner
2
3 register_for :vhdl
4
5 RESERVED_WORDS = [
6 'access','after','alias','all','assert','architecture','begin',
7 'block','body','buffer','bus','case','component','configuration','constant',
8 'disconnect','downto','else','elsif','end','entity','exit','file','for',
9 'function','generate','generic','group','guarded','if','impure','in',
10 'inertial','inout','is','label','library','linkage','literal','loop',
11 'map','new','next','null','of','on','open','others','out','package',
12 'port','postponed','procedure','process','pure','range','record','register',
13 'reject','report','return','select','severity','signal','shared','subtype',
14 'then','to','transport','type','unaffected','units','until','use','variable',
15 'wait','when','while','with','note','warning','error','failure','and',
16 'or','xor','not','nor',
17 'array'
18 ]
19
20 PREDEFINED_TYPES = [
21 'bit','bit_vector','character','boolean','integer','real','time','string',
22 'severity_level','positive','natural','signed','unsigned','line','text',
23 'std_logic','std_logic_vector','std_ulogic','std_ulogic_vector','qsim_state',
24 'qsim_state_vector','qsim_12state','qsim_12state_vector','qsim_strength',
25 'mux_bit','mux_vector','reg_bit','reg_vector','wor_bit','wor_vector'
26 ]
27
28 PREDEFINED_CONSTANTS = [
29
30 ]
31
32 IDENT_KIND = CodeRay::CaseIgnoringWordList.new(:ident).
33 add(RESERVED_WORDS, :reserved).
34 add(PREDEFINED_TYPES, :pre_type).
35 add(PREDEFINED_CONSTANTS, :pre_constant)
36
37 ESCAPE = / [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x
38 UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x
39
40 def scan_tokens tokens, options
41
42 state = :initial
43
44 until eos?
45
46 kind = nil
47 match = nil
48
49 case state
50
51 when :initial
52
53 if scan(/ \s+ | \\\n /x)
54 kind = :space
55
56 elsif scan(/-- .*/x)
57 kind = :comment
58
59 elsif scan(/ [-+*\/=<>?:;,!&^|()\[\]{}~%]+ | \.(?!\d) /x)
60 kind = :operator
61
62 elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
63 kind = IDENT_KIND[match.downcase]
64
65 elsif match = scan(/[a-z]?"/i)
66 tokens << [:open, :string]
67 state = :string
68 kind = :delimiter
69
70 elsif scan(/ L?' (?: [^\'\n\\] | \\ #{ESCAPE} )? '? /ox)
71 kind = :char
72
73 elsif scan(/(?:\d+)(?![.eEfF])/)
74 kind = :integer
75
76 elsif scan(/\d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
77 kind = :float
78
79 else
80 getch
81 kind = :error
82
83 end
84
85 when :string
86 if scan(/[^\\\n"]+/)
87 kind = :content
88 elsif scan(/"/)
89 tokens << ['"', :delimiter]
90 tokens << [:close, :string]
91 state = :initial
92 next
93 elsif scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
94 kind = :char
95 elsif scan(/ \\ | $ /x)
96 tokens << [:close, :string]
97 kind = :error
98 state = :initial
99 else
100 raise_inspect "else case \" reached; %p not handled." % peek(1), tokens
101 end
102
103 else
104 raise_inspect 'Unknown state', tokens
105
106 end
107
108 match ||= matched
109 if $DEBUG and not kind
110 raise_inspect 'Error token %p in line %d' %
111 [[match, kind], line], tokens
112 end
113 raise_inspect 'Empty token', tokens unless match
114
115 tokens << [match, kind]
116
117 end
118
119 if state == :string
120 tokens << [:close, :string]
121 end
122
123 tokens
124 end
125
126 end