Use undef to guess macro names
This commit is contained in:
Родитель
4a899635cc
Коммит
ab2b0dd8cc
|
@ -17,26 +17,28 @@ pub enum Preproc {
|
|||
PreprocIfToken2 = 12,
|
||||
PreprocElifToken1 = 13,
|
||||
PreprocElseToken1 = 14,
|
||||
PreprocNothingToken1 = 15,
|
||||
StringLiteralToken1 = 16,
|
||||
CharLiteralToken1 = 17,
|
||||
IntegerLiteral = 18,
|
||||
Comment = 19,
|
||||
RawStringLiteral = 20,
|
||||
TranslationUnit = 21,
|
||||
TopLevelItem = 22,
|
||||
PreprocInclude = 23,
|
||||
Define = 24,
|
||||
PreprocIf = 25,
|
||||
PreprocElif = 26,
|
||||
PreprocElse = 27,
|
||||
PreprocNothing = 28,
|
||||
StringLiteral = 29,
|
||||
CharLiteral = 30,
|
||||
TranslationUnitRepeat1 = 31,
|
||||
DefineRepeat1 = 32,
|
||||
PreprocIfRepeat1 = 33,
|
||||
Error = 34,
|
||||
UndefToken1 = 15,
|
||||
PreprocNothingToken1 = 16,
|
||||
StringLiteralToken1 = 17,
|
||||
CharLiteralToken1 = 18,
|
||||
IntegerLiteral = 19,
|
||||
Comment = 20,
|
||||
RawStringLiteral = 21,
|
||||
TranslationUnit = 22,
|
||||
TopLevelItem = 23,
|
||||
PreprocInclude = 24,
|
||||
Define = 25,
|
||||
PreprocIf = 26,
|
||||
PreprocElif = 27,
|
||||
PreprocElse = 28,
|
||||
Undef = 29,
|
||||
PreprocNothing = 30,
|
||||
StringLiteral = 31,
|
||||
CharLiteral = 32,
|
||||
TranslationUnitRepeat1 = 33,
|
||||
DefineRepeat1 = 34,
|
||||
PreprocIfRepeat1 = 35,
|
||||
Error = 36,
|
||||
}
|
||||
|
||||
impl Into<&'static str> for Preproc {
|
||||
|
@ -57,6 +59,7 @@ impl Into<&'static str> for Preproc {
|
|||
Preproc::PreprocIfToken2 => "preproc_if_token2",
|
||||
Preproc::PreprocElifToken1 => "preproc_elif_token1",
|
||||
Preproc::PreprocElseToken1 => "preproc_else_token1",
|
||||
Preproc::UndefToken1 => "undef_token1",
|
||||
Preproc::PreprocNothingToken1 => "preproc_nothing_token1",
|
||||
Preproc::StringLiteralToken1 => "string_literal_token1",
|
||||
Preproc::CharLiteralToken1 => "char_literal_token1",
|
||||
|
@ -70,6 +73,7 @@ impl Into<&'static str> for Preproc {
|
|||
Preproc::PreprocIf => "preproc_if",
|
||||
Preproc::PreprocElif => "preproc_elif",
|
||||
Preproc::PreprocElse => "preproc_else",
|
||||
Preproc::Undef => "undef",
|
||||
Preproc::PreprocNothing => "preproc_nothing",
|
||||
Preproc::StringLiteral => "string_literal",
|
||||
Preproc::CharLiteral => "char_literal",
|
||||
|
@ -83,47 +87,58 @@ impl Into<&'static str> for Preproc {
|
|||
|
||||
#[allow(clippy::unreadable_literal)]
|
||||
static KEYS: phf::Map<&'static str, Preproc> = ::phf::Map {
|
||||
key: 2575009635930530140,
|
||||
disps: ::phf::Slice::Static(&[(1, 0), (3, 0), (0, 19), (1, 1), (1, 1), (9, 1), (19, 28)]),
|
||||
key: 3347381344252206323,
|
||||
disps: ::phf::Slice::Static(&[
|
||||
(12, 20),
|
||||
(23, 13),
|
||||
(0, 0),
|
||||
(0, 2),
|
||||
(2, 12),
|
||||
(0, 1),
|
||||
(2, 30),
|
||||
(33, 34),
|
||||
]),
|
||||
entries: ::phf::Slice::Static(&[
|
||||
("path", Preproc::Path),
|
||||
("translation_unit_repeat1", Preproc::TranslationUnitRepeat1),
|
||||
("string_literal", Preproc::StringLiteral),
|
||||
("preproc_if_repeat1", Preproc::PreprocIfRepeat1),
|
||||
("preproc_include", Preproc::PreprocInclude),
|
||||
("end", Preproc::End),
|
||||
("preproc_else_token1", Preproc::PreprocElseToken1),
|
||||
("define_token1", Preproc::DefineToken1),
|
||||
("nothing", Preproc::Nothing),
|
||||
("preproc_nothing_token1", Preproc::PreprocNothingToken1),
|
||||
(
|
||||
"preproc_continuation_line",
|
||||
Preproc::PreprocContinuationLine,
|
||||
),
|
||||
("preproc_if_token1", Preproc::PreprocIfToken1),
|
||||
("define_repeat1", Preproc::DefineRepeat1),
|
||||
("_top_level_item", Preproc::TopLevelItem),
|
||||
("preproc_elif", Preproc::PreprocElif),
|
||||
("string_literal_token1", Preproc::StringLiteralToken1),
|
||||
("char_literal", Preproc::CharLiteral),
|
||||
("\\n", Preproc::LF),
|
||||
("preproc_if_token2", Preproc::PreprocIfToken2),
|
||||
("preproc_if", Preproc::PreprocIf),
|
||||
("<", Preproc::LT),
|
||||
("preproc_line", Preproc::PreprocLine),
|
||||
("define", Preproc::Define),
|
||||
("char_literal_token1", Preproc::CharLiteralToken1),
|
||||
("preproc_nothing_token1", Preproc::PreprocNothingToken1),
|
||||
("preproc_else_token1", Preproc::PreprocElseToken1),
|
||||
(">", Preproc::GT),
|
||||
("raw_string_literal", Preproc::RawStringLiteral),
|
||||
("preproc_elif_token1", Preproc::PreprocElifToken1),
|
||||
("path", Preproc::Path),
|
||||
("ERROR", Preproc::Error),
|
||||
("nothing", Preproc::Nothing),
|
||||
("preproc_else", Preproc::PreprocElse),
|
||||
("string_literal", Preproc::StringLiteral),
|
||||
("preproc_line", Preproc::PreprocLine),
|
||||
("raw_string_literal", Preproc::RawStringLiteral),
|
||||
("preproc_include", Preproc::PreprocInclude),
|
||||
("identifier", Preproc::Identifier),
|
||||
("preproc_nothing", Preproc::PreprocNothing),
|
||||
("define_token1", Preproc::DefineToken1),
|
||||
("translation_unit_repeat1", Preproc::TranslationUnitRepeat1),
|
||||
("translation_unit", Preproc::TranslationUnit),
|
||||
("undef_token1", Preproc::UndefToken1),
|
||||
("comment", Preproc::Comment),
|
||||
("preproc_include_token1", Preproc::PreprocIncludeToken1),
|
||||
("_top_level_item", Preproc::TopLevelItem),
|
||||
("preproc_if", Preproc::PreprocIf),
|
||||
("preproc_nothing", Preproc::PreprocNothing),
|
||||
("translation_unit", Preproc::TranslationUnit),
|
||||
("\\n", Preproc::LF),
|
||||
("integer_literal", Preproc::IntegerLiteral),
|
||||
("preproc_elif", Preproc::PreprocElif),
|
||||
("char_literal_token1", Preproc::CharLiteralToken1),
|
||||
("undef", Preproc::Undef),
|
||||
("char_literal", Preproc::CharLiteral),
|
||||
(">", Preproc::GT),
|
||||
("string_literal_token1", Preproc::StringLiteralToken1),
|
||||
("preproc_if_token2", Preproc::PreprocIfToken2),
|
||||
("define_repeat1", Preproc::DefineRepeat1),
|
||||
("preproc_elif_token1", Preproc::PreprocElifToken1),
|
||||
("end", Preproc::End),
|
||||
("preproc_else", Preproc::PreprocElse),
|
||||
("<", Preproc::LT),
|
||||
("preproc_if_token1", Preproc::PreprocIfToken1),
|
||||
("define", Preproc::Define),
|
||||
]),
|
||||
};
|
||||
|
||||
|
|
|
@ -184,7 +184,7 @@ pub fn preprocess(parser: &PreprocParser, path: &PathBuf, results: Arc<Mutex<Pre
|
|||
|
||||
let id = Preproc::from(node.kind_id());
|
||||
match id {
|
||||
Preproc::Define => {
|
||||
Preproc::Define | Preproc::Undef => {
|
||||
cursor.reset(node);
|
||||
cursor.goto_first_child();
|
||||
let identifier = cursor.node();
|
||||
|
|
|
@ -15,6 +15,7 @@ module.exports = grammar({
|
|||
$.comment,
|
||||
$.nothing,
|
||||
$.define,
|
||||
$.undef,
|
||||
$.preproc_if,
|
||||
$.preproc_include,
|
||||
$.preproc_nothing,
|
||||
|
@ -84,8 +85,16 @@ module.exports = grammar({
|
|||
repeat($._top_level_item),
|
||||
),
|
||||
|
||||
undef: $ => seq(
|
||||
/[ \t]*#[ \t]*undef[ \t]+/,
|
||||
$.identifier,
|
||||
repeat($.preproc_continuation_line),
|
||||
$.preproc_line,
|
||||
'\n',
|
||||
),
|
||||
|
||||
preproc_nothing: $ => seq(
|
||||
token.immediate(/[ \t]*#[ \t]*(error|pragma|undef|line)/),
|
||||
token.immediate(/[ \t]*#[ \t]*(error|pragma|line)/),
|
||||
repeat($.preproc_continuation_line),
|
||||
$.preproc_line,
|
||||
),
|
||||
|
@ -102,8 +111,6 @@ module.exports = grammar({
|
|||
/[0-9]+[0-9']*/
|
||||
),
|
||||
|
||||
// static constexpr uint8_t Global = 0b0'0010; ^^ pas compatible avec char
|
||||
|
||||
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
|
||||
comment: $ => token(choice(
|
||||
seq('//', /(\\(.|\r?\n)|[^\\\n])*/),
|
||||
|
|
|
@ -35,6 +35,10 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "define"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "undef"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "preproc_if"
|
||||
|
@ -244,6 +248,34 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"undef": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[ \\t]*#[ \\t]*undef[ \\t]+"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "preproc_continuation_line"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "preproc_line"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "\n"
|
||||
}
|
||||
]
|
||||
},
|
||||
"preproc_nothing": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
|
@ -251,7 +283,7 @@
|
|||
"type": "IMMEDIATE_TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[ \\t]*#[ \\t]*(error|pragma|undef|line)"
|
||||
"value": "[ \\t]*#[ \\t]*(error|pragma|line)"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -74,6 +74,10 @@
|
|||
{
|
||||
"type": "string_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "undef",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -125,6 +129,10 @@
|
|||
{
|
||||
"type": "string_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "undef",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -184,6 +192,10 @@
|
|||
{
|
||||
"type": "string_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "undef",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -282,6 +294,33 @@
|
|||
{
|
||||
"type": "string_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "undef",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "undef",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "preproc_continuation_line",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "preproc_line",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче