lib/textbringer/modes/c_mode.rb in textbringer-0.1.7 vs lib/textbringer/modes/c_mode.rb in textbringer-0.1.8

- old
+ new

@@ -8,19 +8,46 @@ CONFIG[:c_label_offset] = -2 class CMode < ProgrammingMode self.file_name_pattern = /\A.*\.[ch]\z/i + KEYWORDS = %w( + auto break case char const continue default double do + else enum extern float for goto if inline int long + register restrict return short signed sizeof static struct + switch typedef union unsigned void volatile while _Bool + _Complex _Imaginary + ) + + define_syntax :comment, / + (?: \/\* (?> (?:.|\n)*? \*\/ ) ) | + (?: \/\/ .*(?:\\\n.*)*(?:\z|(?<!\\)\n) ) + /x + + define_syntax :preprocessing_directive, / + ^ [\ \t]* (?: \# | %: ) [\ \t]* [_a-zA-Z][_a-zA-Z0-9]* + /x + + define_syntax :keyword, / + \b (?: #{KEYWORDS.join("|")} ) \b + /x + + define_syntax :string, / + (?: " (?: [^\\"] | \\ (?:.|\n) )* " ) | + (?: ' (?: [^\\'] | \\ (?:.|\n) )* ' ) + /x + def initialize(buffer) super(buffer) @buffer[:indent_level] = CONFIG[:c_indent_level] @buffer[:indent_tabs_mode] = CONFIG[:c_indent_tabs_mode] end def compile(cmd = read_from_minibuffer("Compile: ", default: default_compile_command)) - shell_execute(cmd, "*Compile result*") + shell_execute(cmd, buffer_name: "*Compile result*", + mode: BacktraceMode) end def symbol_pattern /[A-Za-z0-9\_\\]/ end @@ -53,16 +80,10 @@ (?<partial_comment> (?<multiline_comment> \/\* (?:.|\n)* ) | (?<singleline_comment> \/\/ .*? \\\n (?:.|\n)* ) ) | (?<keyword> - (?: - auto | break | case | char | const | continue | default | double | do | - else | enum | extern | float | for | goto | if | inline | int | long | - register | restrict | return | short | signed | sizeof | static | struct | - switch | typedef | union | unsigned | void | volatile | while | _Bool | - _Complex | _Imaginary - ) \b + (?: #{KEYWORDS.join("|")} ) \b ) | (?<constant> (?<floating_constant> (?<decimal_floating_constant> (?<fractional_constant>