Kaynağa Gözat

Allow preprocessor conditionals inside functions

pull/6/head
Max Brunsfeld 9 yıl önce
ebeveyn
işleme
eaa878ce95
2 değiştirilmiş dosya ile 27 ekleme ve 5 silme
  1. +24
    -0
      corpus/preprocessor.txt
  2. +3
    -5
      grammar.js

+ 24
- 0
corpus/preprocessor.txt Dosyayı Görüntüle

@ -109,3 +109,27 @@ General if blocks
(preproc_if
(logical_expression (call_expression (identifier) (identifier)) (call_expression (identifier) (identifier)))
(preproc_def (identifier) (preproc_arg))))
============================================
Preprocessor conditionals in functions
============================================
int main() {
#if a
return 0;
#else
return 1;
#endif
}
---
(translation_unit
(function_definition
(identifier)
(function_declarator (identifier))
(compound_statement
(preproc_if (identifier)
(return_statement (number_literal))
(preproc_else
(return_statement (number_literal)))))))

+ 3
- 5
grammar.js Dosyayı Görüntüle

@ -43,6 +43,7 @@ module.exports = grammar({
$._preproc_statement,
$.function_definition,
$.declaration,
$._statement,
$._empty_declaration,
$.linkage_specification
),
@ -98,6 +99,7 @@ module.exports = grammar({
preproc_if: $ => seq(
'#if',
$._expression,
'\n',
repeat($._top_level_item),
optional($.preproc_else),
'#endif'
@ -225,11 +227,7 @@ module.exports = grammar({
compound_statement: $ => seq(
'{',
repeat(choice(
$.declaration,
$._empty_declaration,
$._statement
)),
repeat($._top_level_item),
'}'
),

Yükleniyor…
İptal
Kaydet