Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hgdsraj committed Sep 13, 2016
2 parents e002348 + 69500eb commit b44a11a
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 14 deletions.
54 changes: 54 additions & 0 deletions grammars/c++.cson
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
{
'include': '#special_block'
}
{
'include': '#strings'
}
{
'include': 'source.c'
}
Expand Down Expand Up @@ -329,3 +332,54 @@
]
}
]
'strings':
'patterns': [
{
'begin': '(u|u8|U|L)?"'
'beginCaptures':
'0':
'name': 'punctuation.definition.string.begin.cpp'
'1':
'name': 'meta.encoding.cpp'
'end': '"'
'endCaptures':
'0':
'name': 'punctuation.definition.string.end.cpp'
'name': 'string.quoted.double.cpp'
'patterns': [
{
'match': '\\\\u\\h{4}|\\\\U\\h{8}'
'name': 'constant.character.escape.cpp'
}
{
'match': '\\\\[\'"?\\\\abfnrtv]'
'name': 'constant.character.escape.cpp'
}
{
'match': '\\\\[0-7]{1,3}'
'name': 'constant.character.escape.cpp'
}
{
'match': '\\\\x\\h+'
'name': 'constant.character.escape.cpp'
}
]
}
{
'begin': '(u|u8|U|L)?R"(?:([^ ()\\\\\\t]{0,16})|([^ ()\\\\\\t]*))\\('
'beginCaptures':
'0':
'name': 'punctuation.definition.string.begin.cpp'
'1':
'name': 'meta.encoding.cpp'
'3':
'name': 'invalid.illegal.delimiter-too-long.cpp'
'end': '\\)\\2(\\3)"'
'endCaptures':
'0':
'name': 'punctuation.definition.string.end.cpp'
'1':
'name': 'invalid.illegal.delimiter-too-long.cpp'
'name': 'string.quoted.double.raw.cpp'
}
]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.52.1",
"version": "0.53.1",
"name": "language-c",
"description": "Atom language support for C/C++",
"homepage": "https://atom.github.io/language-c",
Expand Down
14 changes: 7 additions & 7 deletions snippets/language-c.cson
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@
'body': 'enum ${1:name} { $0 };'
'Class':
'prefix': 'cl'
'body': 'class ${1:name_t} {\nprivate:\n\t${0:/* data */}\npublic:\n\t${1:name_t} (${2:arguments});\n\tvirtual ~${1:name_t} ();\n\n};'
'body': 'class ${1:name_t} {\nprivate:\n\t${0:/* data */}\n\npublic:\n\t${1:name_t} (${2:arguments});\n\tvirtual ~${1:name_t} ();\n};'
'Namespace':
'prefix': 'ns'
'body': 'namespace ${1:name} {\n\t$2\n} /* $1 */'
'cout':
'prefix': 'cout'
'body': 'std::cout << \"${1:/* message */}\" << std::endl;'
'body': 'std::cout << \"${1:/* message */}\" << \'\\\\n\';'
'cin':
'prefix': 'cin'
'body': 'std::cin >> ${1:/* variable */};'
'cerr':
'prefix': 'cerr'
'body': 'std::cerr << \"${1:/* error message */}\" << std::endl;'
'body': 'std::cerr << \"${1:/* error message */}\" << \'\\\\n\';'
'std::map':
'prefix': 'map'
'body': 'std::map<${1:key}, ${2:value}> map$3;'
Expand All @@ -101,13 +101,13 @@
'body': 'std::string'
'std::vector':
'prefix': 'vector'
'body': 'std::vector<${1:char}> v$2;'
'body': 'std::vector<${1:int}> v$2;'
'template <typename>':
'prefix': 'tp'
'body': 'template <typename ${1:_InputIter}>'
'body': 'template <typename ${1:T}>'
'output file':
'prefix': 'outf'
'body': 'ofstream ${1:afile} ("${2:filename.txt}", ios::out);\nif(${1:afile}.is_open()) { \n\t${1:afile} << "${3:This is a line.}\\\\n";\n\t${1:afile}.close();\n}'
'body': 'std::ofstream ${1:afile}("${2:filename.txt}", std::ios::out);\nif (${1:afile}.is_open()) {\n\t${1:afile} << "${3:This is a line.}\\\\n";\n\t${1:afile}.close();\n}'
'input file':
'prefix': 'inf'
'body': 'ifstream ${1:afile} ("${2:filename.txt}",ios::in);\nif(${1:afile}.is_open()) { \n\tstring buffer;\n\twhile( getline(myfile,buffer) ) {\n\t\tcout << line << endl;\n\t}\n\t\t${1:afile}.close();\n\t}\nelse {\n\tcout << "Unable to open file" << endl;\n}'
'body': 'std::ifstream ${1:afile}("${2:filename.txt}", std::ios::in);\nif (${1:afile}.is_open()) {\n\tstd::string line;\n\twhile (std::getline(${1:afile}, line)) {\n\t\tstd::cout << line << \'\\\\n\';\n\t}\n\t${1:afile}.close();\n}\nelse {\n\tstd::cerr << "Unable to open file\\\\n";\n}'
53 changes: 47 additions & 6 deletions spec/c-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,9 @@ describe "Language-C", ->
}
'''
expect(lines[0][0]).toEqual value: 'extern', scopes: ['source.cpp', 'meta.extern-block.cpp', 'storage.modifier.cpp']
expect(lines[0][2]).toEqual value: '"', scopes: ['source.cpp', 'meta.extern-block.cpp', 'string.quoted.double.c', 'punctuation.definition.string.begin.c']
expect(lines[0][3]).toEqual value: 'C', scopes: ['source.cpp', 'meta.extern-block.cpp', 'string.quoted.double.c']
expect(lines[0][4]).toEqual value: '"', scopes: ['source.cpp', 'meta.extern-block.cpp', 'string.quoted.double.c', 'punctuation.definition.string.end.c']
expect(lines[0][2]).toEqual value: '"', scopes: ['source.cpp', 'meta.extern-block.cpp', 'string.quoted.double.cpp', 'punctuation.definition.string.begin.cpp']
expect(lines[0][3]).toEqual value: 'C', scopes: ['source.cpp', 'meta.extern-block.cpp', 'string.quoted.double.cpp']
expect(lines[0][4]).toEqual value: '"', scopes: ['source.cpp', 'meta.extern-block.cpp', 'string.quoted.double.cpp', 'punctuation.definition.string.end.cpp']
expect(lines[0][6]).toEqual value: '{', scopes: ['source.cpp', 'meta.extern-block.cpp', 'punctuation.section.block.begin.c']
expect(lines[1][0]).toEqual value: '#', scopes: ['source.cpp', 'meta.extern-block.cpp', 'meta.preprocessor.include.c', 'keyword.control.directive.include.c', 'punctuation.definition.directive.c']
expect(lines[1][1]).toEqual value: 'include', scopes: ['source.cpp', 'meta.extern-block.cpp', 'meta.preprocessor.include.c', 'keyword.control.directive.include.c']
Expand All @@ -579,9 +579,9 @@ describe "Language-C", ->
expect(lines[0][1]).toEqual value: 'ifdef', scopes: ['source.cpp', 'meta.preprocessor.c', 'keyword.control.directive.conditional.c']
expect(lines[0][2]).toEqual value: ' __cplusplus', scopes: ['source.cpp', 'meta.preprocessor.c']
expect(lines[1][0]).toEqual value: 'extern', scopes: ['source.cpp', 'meta.extern-block.cpp', 'storage.modifier.cpp']
expect(lines[1][2]).toEqual value: '"', scopes: ['source.cpp', 'meta.extern-block.cpp', 'string.quoted.double.c', 'punctuation.definition.string.begin.c']
expect(lines[1][3]).toEqual value: 'C', scopes: ['source.cpp', 'meta.extern-block.cpp', 'string.quoted.double.c']
expect(lines[1][4]).toEqual value: '"', scopes: ['source.cpp', 'meta.extern-block.cpp', 'string.quoted.double.c', 'punctuation.definition.string.end.c']
expect(lines[1][2]).toEqual value: '"', scopes: ['source.cpp', 'meta.extern-block.cpp', 'string.quoted.double.cpp', 'punctuation.definition.string.begin.cpp']
expect(lines[1][3]).toEqual value: 'C', scopes: ['source.cpp', 'meta.extern-block.cpp', 'string.quoted.double.cpp']
expect(lines[1][4]).toEqual value: '"', scopes: ['source.cpp', 'meta.extern-block.cpp', 'string.quoted.double.cpp', 'punctuation.definition.string.end.cpp']
expect(lines[1][6]).toEqual value: '{', scopes: ['source.cpp', 'meta.extern-block.cpp', 'punctuation.section.block.begin.c']
expect(lines[2][0]).toEqual value: '#', scopes: ['source.cpp', 'meta.preprocessor.c', 'keyword.control.directive.conditional.c', 'punctuation.definition.directive.c']
expect(lines[2][1]).toEqual value: 'endif', scopes: ['source.cpp', 'meta.preprocessor.c', 'keyword.control.directive.conditional.c']
Expand All @@ -593,6 +593,47 @@ describe "Language-C", ->
expect(lines[6][0]).toEqual value: '#', scopes: ['source.cpp', 'meta.preprocessor.c', 'keyword.control.directive.conditional.c', 'punctuation.definition.directive.c']
expect(lines[6][1]).toEqual value: 'endif', scopes: ['source.cpp', 'meta.preprocessor.c', 'keyword.control.directive.conditional.c']

it "tokenizes UTF string escapes", ->
lines = grammar.tokenizeLines '''
string str = U"\\U01234567\\u0123\\"\\0123\\x123";
'''
expect(lines[0][0]).toEqual value: 'string str = ', scopes: ['source.cpp']
expect(lines[0][1]).toEqual value: 'U', scopes: ['source.cpp', 'string.quoted.double.cpp', 'punctuation.definition.string.begin.cpp', 'meta.encoding.cpp']
expect(lines[0][2]).toEqual value: '"', scopes: ['source.cpp', 'string.quoted.double.cpp', 'punctuation.definition.string.begin.cpp']
expect(lines[0][3]).toEqual value: '\\U01234567', scopes: ['source.cpp', 'string.quoted.double.cpp', 'constant.character.escape.cpp']
expect(lines[0][4]).toEqual value: '\\u0123', scopes: ['source.cpp', 'string.quoted.double.cpp', 'constant.character.escape.cpp']
expect(lines[0][5]).toEqual value: '\\"', scopes: ['source.cpp', 'string.quoted.double.cpp', 'constant.character.escape.cpp']
expect(lines[0][6]).toEqual value: '\\012', scopes: ['source.cpp', 'string.quoted.double.cpp', 'constant.character.escape.cpp']
expect(lines[0][7]).toEqual value: '3', scopes: ['source.cpp', 'string.quoted.double.cpp']
expect(lines[0][8]).toEqual value: '\\x123', scopes: ['source.cpp', 'string.quoted.double.cpp', 'constant.character.escape.cpp']
expect(lines[0][9]).toEqual value: '"', scopes: ['source.cpp', 'string.quoted.double.cpp', 'punctuation.definition.string.end.cpp']
expect(lines[0][10]).toEqual value: ';', scopes: ['source.cpp']

it "tokenizes raw string literals", ->
lines = grammar.tokenizeLines '''
string str = R"test(
this is \"a\" test 'string'
)test";
'''
expect(lines[0][0]).toEqual value: 'string str = ', scopes: ['source.cpp']
expect(lines[0][1]).toEqual value: 'R"test(', scopes: ['source.cpp', 'string.quoted.double.raw.cpp', 'punctuation.definition.string.begin.cpp']
expect(lines[1][0]).toEqual value: ' this is "a" test \'string\'', scopes: ['source.cpp', 'string.quoted.double.raw.cpp']
expect(lines[2][0]).toEqual value: ')test"', scopes: ['source.cpp', 'string.quoted.double.raw.cpp', 'punctuation.definition.string.end.cpp']
expect(lines[2][1]).toEqual value: ';', scopes: ['source.cpp']

it "errors on long raw string delimiters", ->
lines = grammar.tokenizeLines '''
string str = R"01234567890123456()01234567890123456";
'''
expect(lines[0][0]).toEqual value: 'string str = ', scopes: ['source.cpp']
expect(lines[0][1]).toEqual value: 'R"', scopes: ['source.cpp', 'string.quoted.double.raw.cpp', 'punctuation.definition.string.begin.cpp']
expect(lines[0][2]).toEqual value: '01234567890123456', scopes: ['source.cpp', 'string.quoted.double.raw.cpp', 'punctuation.definition.string.begin.cpp', 'invalid.illegal.delimiter-too-long.cpp']
expect(lines[0][3]).toEqual value: '(', scopes: ['source.cpp', 'string.quoted.double.raw.cpp', 'punctuation.definition.string.begin.cpp']
expect(lines[0][4]).toEqual value: ')', scopes: ['source.cpp', 'string.quoted.double.raw.cpp', 'punctuation.definition.string.end.cpp']
expect(lines[0][5]).toEqual value: '01234567890123456', scopes: ['source.cpp', 'string.quoted.double.raw.cpp', 'punctuation.definition.string.end.cpp', 'invalid.illegal.delimiter-too-long.cpp']
expect(lines[0][6]).toEqual value: '"', scopes: ['source.cpp', 'string.quoted.double.raw.cpp', 'punctuation.definition.string.end.cpp']
expect(lines[0][7]).toEqual value: ';', scopes: ['source.cpp']

describe "comments", ->
it "tokenizes them", ->
{tokens} = grammar.tokenizeLine '// comment'
Expand Down

0 comments on commit b44a11a

Please sign in to comment.