Skip to content

Commit 9fd234e

Browse files
authored
Merge pull request #56 from asklar/copilot/fix-unsupported-ifndef
Add support for #else and #elif preprocessor directives
2 parents 3af4d69 + 5b28c78 commit 9fd234e

File tree

6 files changed

+71
-3
lines changed

6 files changed

+71
-3
lines changed

.github/agents/midl-dev.agent.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ npm run test:parser # Run parser tests
103103
- Open any `.idl` file to test language features
104104

105105
### Publishing
106-
- Update version: `npm version patch`
106+
- **Always bump the package version** in `package.json` when making changes that will be published
107+
- Use semantic versioning: patch (0.0.X) for bug fixes, minor (0.X.0) for features, major (X.0.0) for breaking changes
107108
- Publishing happens automatically via GitHub Actions on push to main
108109

109110
## Common Development Tasks
@@ -168,6 +169,7 @@ When working on this repository:
168169
6. **Document**: Update README or comments if making significant changes
169170
7. **Security**: Check for vulnerabilities, especially in dependencies
170171
8. **Validate**: Test language features in a real VSCode instance when possible
172+
9. **Version Bumping**: Always bump the package version in `package.json` for any PR that will be merged (use patch version for bug fixes, minor for features)
171173

172174
## Example Tasks
173175

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"icon": "images/midl3.png",
66
"author": "Microsoft Corporation",
77
"license": "MIT",
8-
"version": "0.0.32",
8+
"version": "0.0.33",
99
"repository": {
1010
"type": "git",
1111
"url": "https://github.com/asklar/midl-langserv"

server/src/midl.pegjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ importKeyword = "import" { return emit('keyword'); }
5252
( includeKW _ includeReference ) /
5353
( ifdefKW _ preprocessorExpression ) /
5454
( ifndefKW _ preprocessorExpression ) /
55+
( elifKW _ preprocessorExpression ) /
5556
( ifKW _ preprocessorExpression) /
57+
( elseKW ) /
5658
( endifKW ) /
5759
( defineKW _ identifier preprocessorExpression ) /
5860
( undefKW _ identifier )
@@ -61,7 +63,9 @@ importKeyword = "import" { return emit('keyword'); }
6163
includeKW = "#include" { emit('preProcessor'); }
6264
ifdefKW = "#ifdef" { emit('preProcessor'); }
6365
ifndefKW = "#ifndef" { emit('preProcessor'); }
66+
elifKW = "#elif" { emit('preProcessor'); }
6467
ifKW = "#if" { emit('preProcessor'); }
68+
elseKW = "#else" { emit('preProcessor'); }
6569
endifKW = "#endif" { emit('preProcessor'); }
6670
defineKW = "#define" { emit('preProcessor'); }
6771
undefKW = "#undef" { emit('preProcessor'); }
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef FOO
2+
#define FOO 1
3+
4+
namespace TestNamespace
5+
{
6+
runtimeclass TestClass
7+
{
8+
TestClass();
9+
Int32 TestProperty{ get; };
10+
}
11+
}
12+
13+
#else
14+
15+
namespace AlternateNamespace
16+
{
17+
runtimeclass AlternateClass
18+
{
19+
AlternateClass();
20+
String AlternateProperty{ get; };
21+
}
22+
}
23+
24+
#endif
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef VERSION
2+
#define VERSION 3
3+
#endif
4+
5+
#if VERSION == 1
6+
7+
namespace Version1
8+
{
9+
runtimeclass MyClass
10+
{
11+
MyClass();
12+
Int32 Property1{ get; };
13+
}
14+
}
15+
16+
#elif VERSION == 2
17+
18+
namespace Version2
19+
{
20+
runtimeclass MyClass
21+
{
22+
MyClass();
23+
String Property2{ get; };
24+
}
25+
}
26+
27+
#else
28+
29+
namespace DefaultVersion
30+
{
31+
runtimeclass MyClass
32+
{
33+
MyClass();
34+
Boolean Property3{ get; };
35+
}
36+
}
37+
38+
#endif

syntaxes/midl3.tmGrammar.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"preprocessor": {
2020
"name": "keyword.other",
21-
"match": "#(include|define|ifdef|ifndef|if|else|endif|pragma)"
21+
"match": "#(include|define|ifdef|ifndef|if|elif|else|endif|pragma)"
2222
},
2323
"comment": {
2424
"patterns": [

0 commit comments

Comments
 (0)