EB Template Syntax Highlighter
A Visual Studio Code extension that provides syntax highlighting for Elektrobit (EB) template files used in AUTOSAR code generation.
Features
This extension provides syntax highlighting for EB template syntax, including:
- Template Directives:
[!IF], [!ELSEIF], [!ELSE], [!ENDIF], [!LOOP], [!ENDLOOP], [!FOR], [!ENDFOR], [!MACRO], [!ENDMACRO], [!CALL], [!NOCODE], [!ENDNOCODE], [!CODE], [!ENDCODE], [!CR]
- Function Calls:
- Text functions:
text:match(), text:contains(), text:uniq(), text:toupper()
- Node functions:
node:value(), node:exists(), node:ref(), node:refvalid(), node:refs()
- Number functions:
num:i(), num:inttohex()
- Variable functions:
var:defined(), var:name()
- EC functions:
ecu:get(), ecu:list()
- Variant functions:
variant:size()
- Other functions:
contains(), count()
- Variables:
- Variable definitions:
[!VAR "variableName"=...], [!FOR "variableName"=...]
- Variable references:
$variableName
- Nested function calls with full support
- Comments inside template blocks:
- Multi-line comments:
[!/* ... */!]
- Single-line comments:
[!// ...
- Template syntax in comments: Template code inside
/* ... */ and // comments is also highlighted
Installation
Option 1: From Marketplace (Recommended)
- Open VS Code
- Go to Extensions (Ctrl+Shift+X)
- Search for "EB Template Syntax Highlighter"
- Click Install
Usage
Important: Manual Language Mode Switching
This extension does NOT automatically associate with .c, .h, or .m files to preserve the default C/C++ syntax highlighting. You must manually switch to EB Template language mode when needed.
Switching Language Mode
- Open your EB template file (
.c, .h, or .m extension)
- Click on the language indicator in the bottom-right corner of VS Code (e.g., "C" or "C++")
- Select "EB Template" from the dropdown menu
Alternatively, use the Command Palette:
- Press
Ctrl+Shift+P
- Type "Change Language Mode"
- Select "EB Template"
Switching Back to C/C++
To return to normal C/C++ highlighting:
- Click on the language indicator (now showing "EB Template")
- Select "C" or "C++"
Syntax Examples
Template Directives
[!IF "text:toupper(./SomeNode)"!]
// Code when condition is true
[!ELSEIF "./AnotherNode = 'VALUE'"!]
// Alternative condition
[!ELSE!]
// Fallback code
[!ENDIF!]
Function Calls
[!FOR "x" = "0" TO "count(AdcConfigSet/AdcHwUnit/*/AdcGroup/*)-1"!]
[!VAR "channelId"="num:i($x + 1)"!]
Channel: [!"$channelId"!]
[!ENDFOR!]
Nested Functions
[!IF "text:contains(ecu:list('Crc.Protocols.SwapBitByte.List'), ./CrcProtocolInfo/CrcProtocolType)"!]
// Condition with nested function call
[!ENDIF!]
MACRO Definitions
[!MACRO "CrcProtocol"!][!//
[!NOCODE!]
[!VAR "MacCrcProtocol"="node:value(./CrcProtocolInfo/CrcProtocolType)"!]
[!ENDNOCODE!][!//
[!"$MacCrcProtocol"!][!//
[!ENDMACRO!]
/* CRC[!IF "var:defined('postBuildVariant')"!]_[!"text:toupper($postBuildVariant)"!][!ENDIF!]_PBCFG_H */
// [!IF "text:toupper($var)"!]This template code is also highlighted[!ENDIF!]
[!/*****************************************************************************/!][!//
[!/* This is a multi-line comment block inside template */!][!//
[!/* Everything inside [!/* ... */!] is highlighted as a comment */!][!//
[!/*****************************************************************************/!]
Highlighting Scope
Inside [!] Template Blocks
All template syntax is fully highlighted:
- Keywords (IF, ELSE, LOOP, MACRO, VAR, etc.)
- Function names and namespaces
- Variable definitions and references
- Strings and numbers
- Operators
Outside [!] Template Blocks
Only C-style comments are highlighted:
// single-line comments
/* */ multi-line comments
Note: All other code outside template blocks appears as plain text to avoid conflicts with C/C++ highlighting.
Syntax Coloring
The extension uses the following color scheme (based on your VS Code theme):
- Keywords: Purple (e.g., IF, ELSE, LOOP, MACRO, VAR)
- Function Names: Blue
- Function Namespaces: Blue
- Variable References: Red
- Variable Definitions: Red
- Strings: Green
- Comments: Gray
- Numbers: Orange/Yellow
Requirements
- Visual Studio Code version 1.80.0 or higher
Supported File Types
While the extension can be used with any file type, it's designed for:
.c files (C source files)
.h files (C header files)
.m files (EB template files)
Troubleshooting
Syntax highlighting is not showing
- Verify you have switched to "EB Template" language mode
- Reload the window:
Ctrl+Shift+P → "Developer: Reload Window"
- Check that your template code uses
[!] delimiters
Template blocks are highlighted as plain text
- Ensure the template blocks use correct syntax:
[! and !]
- Check for typos in template directives
- Try reloading the window
Conflicts with C/C++ extension
This extension is designed to avoid conflicts by requiring manual language switching. If you experience issues, ensure only one language mode is active at a time.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE.md for details
Changelog
Version 0.0.3
- Added
text:toupper() function support
- Improved variable highlighting in VAR/FOR statements
- Added template syntax highlighting inside comments
- Fixed nested function call highlighting
- Removed all syntax highlighting outside template blocks (except comments)
Version 0.0.2
- Initial release with basic template directive highlighting
- Support for function calls and variables
Author
NeilBest
Acknowledgments
Built for Elektrobit (EB) template files used in AUTOSAR code generation.