The Wayback Machine - https://web.archive.org/web/20220322165807/https://github.com/atom/language-c/pull/102
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preprocessor directives improvements + specs #102

Merged
merged 21 commits into from Dec 2, 2015
Merged

Preprocessor directives improvements + specs #102

merged 21 commits into from Dec 2, 2015

Conversation

MaximSokolov
Copy link
Member

@MaximSokolov MaximSokolov commented Nov 22, 2015

  1. Added specs for preprocessor directives

  2. Renamed keyword.control.import -> keyword.control.directive

    I think it's confusing that all preprocessor directives are tokenized as import

  3. # is tokenized as part of a keyword

    Before: # - punctuation.definition.keyword, define - keyword.control.import
    After: #define - keyword.control.directive, # - punctuation.definition.directive

  4. Strings and numbers are tokenized in #line 151 "copy.c"

  5. Fixes #92

// diagnostics
#error C++ compiler required.
#warning This is a warning.

// includes
#include <stdio.h>
#include<stdio.h>
#import "filename"
#import"filename"

// '#pragma'
#pragma mark – Initialization
#pragma once
#pragma OPTIMIZE ON

// '#line'
#line 151 "copy.c"

// conditionals
#if defined(CREDIT)
    credit();
#elif defined(DEBIT)
    debit();
#else
    printerror();
#endif
#if 0
  return 1;
#else
  return 0;
#endif
#if 1
  return 1;
#else
  return 0;
#endif
#if (DEBUG && !MYTEST)
        Console.WriteLine("DEBUG is defined");
#elif (!DEBUG && MYTEST)
        Console.WriteLine("MYTEST is defined");
#elif (DEBUG && MYTEST)
        Console.WriteLine("DEBUG and MYTEST are defined");
#else
        Console.WriteLine("DEBUG and MYTEST are not defined");
#endif
#ifdef __unix__ /* is defined by compilers targeting Unix systems */
  # include <unistd.h>
#elif defined _WIN32 /* is defined by compilers targeting Windows systems */
  # include <windows.h>
#endif

// '#define'
#define _FILE_NAME_H_
#define ABC XYZ(1)
#define PI_PLUS_ONE (3.14 + 1)
#define INCREMENT(x) x++
#define MULT(x, y) x * y
#define multiply( f1, f2 ) ( f1 * f2 )
#define MULT(x, y) (x) * (y)
#define SWAP(a, b)  do { a ^= b; b ^= a; a ^= b; } while ( 0 )
#define max(a,b) (a>b)? \
                  a:b
#define SWAP(a, b)  { \
  a ^= b;             \
  b ^= a;             \
  a ^= b;             \
}

// 'line continuation' character
#include<stdio.h>
ma\
in()
{
p\
r\
i\
n\
t\
f (
  "Hello\
  World"
  );
}

// #92
#ifdef __cplusplus
extern "C" {
#endif
)
(\\))
)?
'''
Copy link
Member Author

@MaximSokolov MaximSokolov Nov 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From atom/language-css#38:

This should be triple-quoted, not sure why Travis is passing

Not necessary. (?x) will remove all \n, \t anyway.

''' are required when pattern contains comments

Copy link
Member

@50Wliu 50Wliu Nov 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to know 👍

@50Wliu
Copy link
Member

@50Wliu 50Wliu commented Nov 22, 2015

What do you think about keyword.control.preprocessor instead?

'name': 'keyword.control.import.c'
'name': 'punctuation.definition.directive.c'
'3':
'name': 'keyword.control.directive.conditional.c'
Copy link
Member

@50Wliu 50Wliu Nov 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are elif, else, etc. given a special subscope but define, defined, etc. aren't?

Also, is there any way to reduce the amount of non-capture groups?

Copy link
Member Author

@MaximSokolov MaximSokolov Nov 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add subscopes for them. Also define, defined should be 🔥 since #define is matched above, #defined isn't a directive

@50Wliu
Copy link
Member

@50Wliu 50Wliu commented Nov 22, 2015

Why were quotes in the spec file changed? Standardization with other languages I'm guessing (though there really isn't any with regards to the type of quotes used)?

@MaximSokolov
Copy link
Member Author

@MaximSokolov MaximSokolov commented Nov 22, 2015

What do you think about keyword.control.preprocessor instead?

directive is more accurate and specific IMO. Note that it's inside meta.preprocessor

Why were quotes in the spec file changed? Standardization with other languages I'm guessing (though there really isn't any with regards to the type of quotes used)?

Single/double quotes were mixed. I used double quotes for describe and it, single quotes for the rest (see javascript-spec.coffee)

'include': '#numbers'
}
{
'match': '(?>\\\\\\s*\\n)'
Copy link
Member

@50Wliu 50Wliu Nov 24, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this supposed to be an atomic group?

it "tokenizes them", ->
{tokens} = grammar.tokenizeLine '// comment'
expect(tokens[0]).toEqual value: '//', scopes: ['source.cpp', 'comment.line.double-slash.c++', 'punctuation.definition.comment.c++']
expect(tokens[1]).toEqual value: ' comment', scopes: ['source.cpp', 'comment.line.double-slash.c++']
Copy link
Member Author

@MaximSokolov MaximSokolov Nov 24, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why it's still c++? Probably should be replaced (in separate PR): c++ -> cpp
Edit: #108

Copy link
Member

@50Wliu 50Wliu Dec 2, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

50Wliu pushed a commit that referenced this issue Dec 2, 2015
Preprocessor directives improvements + specs
@50Wliu 50Wliu merged commit 11b919d into atom:master Dec 2, 2015
1 check passed
@50Wliu
Copy link
Member

@50Wliu 50Wliu commented Dec 2, 2015

💥

@MaximSokolov MaximSokolov deleted the preprocessor-directives branch Dec 2, 2015
simurai added a commit to atom/solarized-dark-syntax that referenced this issue Dec 7, 2015
simurai added a commit to atom/solarized-light-syntax that referenced this issue Dec 7, 2015
@aminya aminya mentioned this pull request Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants