How to use the moo.keywords function in moo

To help you get started, we’ve selected a few moo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github magma / magma / nms / app / fbcnms-packages / fbcnms-alarms / components / prometheus / PromQLTokenizer.js View on Github external
  // `!=` needs explicit token because it is ambiguous:
  // can mean either vector comparator or label matcher.
  // Must be declared above binComp and labelOp, because their definitions
  // include `!=`, too.
  neq: '!=',
  // Allows greedy-matching identifiers, e.g.
  // `by` will be emitted as %clauseOp, but
  // `byteCount` will be emitted as %identifier
  identifier: {
    match: /\w+/,
    type: Moo.keywords({
      aggClause: AGGR_CLAUSE_TYPES,
      groupClause: GROUP_CLAUSE_TYPES,
      matchClause: MATCH_CLAUSE_TYPES,
      setOp: BINARY_SET_OPS,
  string: [
      // double-quoted string with no escape sequences;
      // shortcut for performance
      match: /"[^"\\]*"/,
      value: s => s.slice(1, -1),
      // single-quoted string with no escape sequences;
github byteball / ocore / formula / grammars / ojson.js View on Github external
'[': '[',
		']': ']',
		':': ':',
		',': ',',
		base64: [
		'"': '"',
		"'": "'",
		'`': '`',
		decimal: /(?:[+-])?(?:[0-9]*[.])?[0-9]+/,
		str: {
      match: /[a-zA-Z_0-9 =+*/@>
github ThaumRystra / DiceCloud / app / imports / parser / grammar.js View on Github external
import CallNode from '/imports/parser/parseTree/CallNode.js';
	import ConstantNode from '/imports/parser/parseTree/ConstantNode.js';
	import IfNode from '/imports/parser/parseTree/IfNode.js';
	import OperatorNode from '/imports/parser/parseTree/OperatorNode.js';
	import SymbolNode from '/imports/parser/parseTree/SymbolNode.js';
	import moo from 'moo';

  const lexer = moo.compile({
    number: /[0-9]+(?:\.[0-9]+)?/,
    string: {
      match: /'.*?'|".*?"/,
      value: s => s.slice(1, -1),
    name: {
      match: /[a-zA-Z]+\w*?/,
      type: moo.keywords({
        'keywords': ['if', 'else', 'd'],
    space: {
      match: /\s+/,
      lineBreaks: true,
    separators: [',', '.'],
    multiplicativeOperator: ['*', '/'],
    exponentOperator: ['^'],
    additiveOperator: ['+', '-'],
    unaryOperator: ['-'],
    andOperator: ['&', '&&'],
    orOperator: ['|', '||'],
    stringDelimiters: ['\"', '\''],
    equalityOperator: ['=', '==', '===', '!=', '!=='],
github Cryptonomic / ConseilJS / dist / chain / tezos / lexer / Michelson.js View on Github external
- There is a function called CREATE_CONTRACT which can create a contract inside of a contract, including the parameter,
    storage, and code definitions. We do not handle this nesting, as we do a lot of preprocessing outside of the grammar.
  - There may not be an exhaustive handling of annotations for types, but it should be covered for instructions

  Lexer to parse keywords more efficiently.
const lexer = moo.compile({
    annot: ["%",":","@"],
    lparen: '(',
    rparen: ')',
    lbrace: '{',
    rbrace: '}',
    semicolon: ";",
    identifiers: {match: /"(?:\\["\\]|[^\n"\\])*"/, type: moo.keywords({
      comparableType: ['int', 'nat', 'string', 'bytes', 'mutez', 'bool', 'key_hash', 'timestamp'],
      constantType: ['key', 'unit', 'signature', 'operation', 'address'],
      singleArgType: ['option', 'list', 'set', 'contract'],
      doubleArgType: ['pair', 'or', 'lambda', 'map', 'big_map'],
      type: ['key', 'unit', 'signature', 'option', 'list', 'set', 'operation', 'address', 'contract', 'pair', 'or', 'lambda', 'map', 'big_map'],
      instruction: ['DROP', 'DUP', 'SWAP', 'SOME', 'NONE', 'UNIT', 'IF_NONE', 'PAIR', 'CAR', 'CDR', 'LEFT', 'RIGHT', 'IF_LEFT', 'IF_RIGHT', 
      'NIL', 'CONS', 'IF_CONS', 'SIZE', 'EMPTY_SET', 'EMPTY_MAP', 'MAP',  'ITER', 'MEM',  'GET',  'UPDATE',  'IF',  'LOOP',  'LOOP_LEFT',  
      'LAMBDA', 'EXEC', 'DIP', 'FAILWITH', 'CAST', 'RENAME', 'CONCAT', 'SLICE', 'PACK', 'UNPACK', 'ADD',  'SUB',  'MUL', 'EDIV', 'ABS', 'NEG',   
      'LSL', 'LSR', 'OR', 'AND', 'XOR', 'NOT', 'COMPARE', 'EQ', 'NEQ', 'LT', 'GT', 'LE', 'GE', 'SELF', 'CONTRACT', 'TRANSFER_TOKENS', 


Optimised tokenizer/lexer generator! 🐄 Much performance. Moo!

Latest version published 1 year ago

Package Health Score

74 / 100
Full package analysis