Skip to content

Instantly share code, notes, and snippets.

@dai1741
Last active December 14, 2015 07:09
Show Gist options
  • Save dai1741/5048285 to your computer and use it in GitHub Desktop.
Save dai1741/5048285 to your computer and use it in GitHub Desktop.
A SublimeLinter linter for checking C++ syntax using g++ like flymake
# -*- coding: utf-8 -*-
# cppsyntax.py - sublimelint package for checking syntax of c++ files
# 以下のclang実装を参考に作成した
# https://github.com/itsbth/SublimeLinter/blob/da0e15275b7c38cbfbc768a2dcc8e62a0e925ca0/sublimelinter/modules/cpp.py
import os.path
import re
from base_linter import BaseLinter, INPUT_METHOD_TEMP_FILE
CONFIG = {
'language': 'cppsyntax',
'executable': 'g++',
'input_method': INPUT_METHOD_TEMP_FILE
}
class Linter(BaseLinter):
CPPSYNTAXCHECK_RE = re.compile(r'^.+:(?P<line>\d+):(?P<offset>\d+):\s+(?P<error>.+)')
def get_lint_args(self, view, code, filename):
return ('-fsyntax-only',
u'-I{0}'.format(os.path.dirname(filename)), # includes temp dir
u'-I{0}'.format(os.path.dirname(self.filename)), # includes dir containing the original file
filename)
def parse_errors(self, view, errors, lines, errorUnderlines, violationUnderlines,
warningUnderlines, errorMessages, violationMessages, warningMessages):
for line in errors.splitlines():
match = self.CPPSYNTAXCHECK_RE.match(line)
if match:
error, line = match.group('error'), match.group('line')
self.add_message(int(line), lines, error.decode("utf-8"), errorMessages)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment