agentsclimarketplace

Lexer tokenizer implementation

Skill HolobiomicsLab/asb-skill-collections/collections/metabolomics/v2/skills/lexer-tokenizer-implementation

Use when when you need to parse a domain-specific query language (like MassQL) into an abstract syntax tree (AST), and the query strings must be decomposed into discrete lexical units before syntactic analysis.From its SKILL.md

Install
npx -y skills add HolobiomicsLab/asb-skill-collections --skill lexer-tokenizer-implementation

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 15 stars15 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its file declares

Copied from the file, not written here

The file declares its own license as CC-BY-4.0. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

6.4 KB, ~1.0k tokens by cl100k_base, as published. Nobody here has run it

lexer-tokenizer-implementation

Summary

Implement a lexer (tokenizer) that breaks domain-specific query strings into meaningful tokens (keywords, identifiers, operators, literals) as the first stage of parsing. This skill is essential for converting raw query syntax into a token stream that a parser can consume to build structured representations.

When to use

When you need to parse a domain-specific query language (like MassQL) into an abstract syntax tree (AST), and the query strings must be decomposed into discrete lexical units before syntactic analysis. Use this skill when designing or implementing a query parser where the input is raw text and the first step is to identify and classify meaningful tokens according to the language grammar.

When NOT to use

  • Input is already a pre-tokenized or intermediate representation (e.g., JSON AST, token stream)—skip directly to parsing or validation.
  • Query language uses only trivial delimiters (e.g., space-separated fields)—simple string splitting may suffice instead of a full lexer.
  • You are working with a well-established query language with existing, maintained tokenizer libraries—prefer the reference implementation over reimplementation.

Inputs

  • Raw MassQL query string (e.g., 'QUERY scaninfo(MS2DATA) WHERE MS1MZ=100')
  • Domain-specific language grammar specification (lexical rules, keyword list, operator definitions)

Outputs

  • Sequence of Token objects (token type, value, position/line/column metadata)
  • Token stream suitable for parser consumption

How to apply

Analyze the domain-specific language grammar to identify lexical categories: keywords (e.g., QUERY, WHERE, MS1DATA), identifiers (variable or field names), operators (=, AND, etc.), numeric and string literals, and special symbols. Design token types (enums or classes) for each category. Implement a tokenizer that scans the input query string sequentially, matching character sequences against lexical rules (keywords, regex patterns for numbers/identifiers) and emitting Token objects containing type, value, and position metadata. Use techniques like longest-match and lookahead to resolve ambiguities (e.g., distinguishing keywords from identifiers). Validate the token stream by verifying it contains no unexpected characters and that token sequences respect basic structural constraints (e.g., operators are not adjacent). The output token stream should be complete and unambiguous, ready for consumption by a recursive-descent or other parser.

Related tools

  • MassQueryLanguage (mwang87/MassQueryLanguage) (Reference parser implementation and language grammar specification; used to extract lexical rules, token types, and AST structure for MassQL queries) — https://github.com/mwang87/MassQueryLanguage
  • massql (Python package) (Official Python API for MassQL query execution; tokenizer is internal component accessed via msql_engine.process_query()) — https://github.com/mwang87/MassQueryLanguage

Examples

from massql import msql_engine; results_df = msql_engine.process_query('QUERY scaninfo(MS2DATA) WHERE MS1MZ=100', 'test.mzML')

Evaluation signals

  • Token stream contains no unrecognized characters; all input is consumed.
  • Token sequence respects grammar: keywords are recognized, operators are classified correctly, literals match expected patterns (e.g., numeric vs. string).
  • Tokenized output can be successfully parsed by the downstream parser into a valid AST without lexical errors.
  • Ambiguous sequences (e.g., 'MS1MZ' vs. keywords) are resolved consistently with the grammar specification.
  • Position metadata (line, column) in tokens is accurate and useful for error reporting.

Limitations

  • Tokenizer must be aligned with the exact grammar version in use; grammar changes (e.g., new operators or keywords in MassQL updates) require tokenizer updates.
  • No changelog found for MassQL repository, so backward compatibility and lexical rule stability are not formally documented—monitor repository commits for breaking changes.
  • Tokenizer design is tightly coupled to the domain; a lexer built for MassQL syntax will not generalize to other query languages without significant modification.

Evidence

  • [other] Grammar extraction and tokenization step: "Implement a tokenizer (lexer) that breaks MassQL query strings into meaningful tokens (keywords, identifiers, operators, literals)."
  • [readme] MassQL query syntax and domains: "The Mass Spec Query Language (MassQL) is a domain specific language meant to be a succinct way to express a query in a mass spectrometry centric fashion."
  • [other] Reference implementation availability: "Clone or load the MassQueryLanguage repository from github.com/mwang87/MassQueryLanguage to access the reference parser implementation."
  • [other] AST target and validation: "Implement a parser (recursive descent or similar) that consumes tokens and builds a structured AST representation."
  • [other] Query component preservation: "Serialize the AST to JSON format, preserving query components (SELECT clauses, WHERE conditions, mass tolerance, scan type constraints, etc.)."

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.