chore(deps): bump cc from 1.2.56 to 1.2.58 in /rust (#48)
Bumps cc from 1.2.56 to 1.2.58.
updated-dependencies:
- dependency-name: cc dependency-version: 1.2.58 dependency-type: direct:production update-type: version-update:semver-patch …
Signed-off-by: dependabot[bot] support@github.com Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
merve
A fast C++ lexer for extracting named exports from CommonJS modules. This library performs static analysis to detect CommonJS export patterns without executing the code.
Features
std::string_view\u{XXXX}and surrogate pairsmerve_c.h) for use from C, FFI, or other languagesInstallation
CMake
Single Header
Copy
singleheader/merve.handsingleheader/merve.cppto your project. The C API headersingleheader/merve_c.his also included in the distribution.Usage
Output:
API Reference
lexer::parse_commonjsParses CommonJS source code and extracts export information.
Parameters:
file_contents: The JavaScript source code to analyzeReturns:
std::optional<lexer_analysis>: Analysis result, orstd::nullopton parse errorlexer::lexer_analysislexer::export_entryEach export/re-export entry includes the name and the 1-based line number where it was found in the source.
lexer::export_stringExport names are stored as a variant to avoid unnecessary copies:
std::string_view: Used for simple identifiers (zero-copy, points to source)std::string: Used when unescaping is needed (e.g., Unicode escapes)lexer::get_string_viewHelper function to get a
string_viewfrom anexport_stringorexport_entry.lexer::get_last_errorReturns the last parse error, if any.
lexer::get_last_error_locationReturns the location of the last parse error, if available. Location tracking is best-effort and may be unavailable.
lexer::error_locationC API
merve provides a C API (
merve_c.h) for use from C programs, FFI bindings, or any language that can call C functions. The C API is compiled into the merve library alongside the C++ implementation.C API Usage
Output:
C API Reference
Types
merve_stringdata+length). Not null-terminated.merve_analysismerve_free().merve_version_componentsmajor,minor,revisionfields.merve_error_locline,column).{0,0}means unavailable.Functions
merve_parse_commonjs(input, length, out_err)merve_is_valid(result)merve_free(result)merve_get_exports_count(result)merve_get_reexports_count(result)merve_get_export_name(result, index){NULL, 0}on error.merve_get_export_line(result, index)merve_get_reexport_name(result, index){NULL, 0}on error.merve_get_reexport_line(result, index)merve_get_last_error()MERVE_ERROR_*), or -1 if no error.merve_get_version()"1.0.1").merve_get_version_components(){major, minor, revision}.On parse failure,
merve_parse_commonjswrites a non-zero location whenout_erris non-NULL and the location is available.Error Constants
MERVE_ERROR_UNEXPECTED_ESM_IMPORTimportdeclarationMERVE_ERROR_UNEXPECTED_ESM_EXPORTexportdeclarationMERVE_ERROR_UNEXPECTED_ESM_IMPORT_METAimport.metaMERVE_ERROR_UNTERMINATED_STRING_LITERALMERVE_ERROR_UNTERMINATED_TEMPLATE_STRINGMERVE_ERROR_UNTERMINATED_REGEXMERVE_ERROR_UNEXPECTED_PAREN)MERVE_ERROR_UNEXPECTED_BRACE}MERVE_ERROR_UNTERMINATED_PAREN(MERVE_ERROR_UNTERMINATED_BRACE{MERVE_ERROR_TEMPLATE_NEST_OVERFLOWLifetime Rules
merve_analysishandle must be freed withmerve_free().merve_stringvalues returned by accessors are valid as long as the handle has not been freed.string_view(most identifiers), the original source buffer must also remain valid.{NULL, 0}).Supported Patterns
Direct Exports
Object Literal Assignment
Object.defineProperty
Re-exports (Transpiler Patterns)
Spread Re-exports
Unicode Handling
The lexer properly handles JavaScript string escape sequences:
Invalid escape sequences (like lone surrogates) are filtered out.
ESM Detection
The lexer detects ESM syntax and returns an error:
This helps identify files that should be parsed as ES modules instead.
Error Handling
Building
Running Tests
Build Options
MERVE_TESTINGONMERVE_BENCHMARKSOFFMERVE_USE_SIMDUTFOFFMERVE_SANITIZEOFFBuilding with simdutf
To enable SIMD-accelerated string operations:
When
MERVE_USE_SIMDUTF=ON, CMake will automatically fetch simdutf via CPM if it’s not found on the system. The library uses simdutf’s optimizedfind()function for faster escape sequence detection.For projects that already have simdutf available (like Node.js), define
MERVE_USE_SIMDUTF=1and ensure the simdutf header is in the include path.Performance
The lexer is optimized for speed:
std::string_viewconstevalLicense
Licensed under either of
at your option.