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: '!=',
  binComp: BINARY_COMPARATORS,
  arithmetic: BINARY_ARITHMETIC_OPS,
  labelOp: LABEL_OPERATORS,
  // 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({
      aggOp: AGGREGATION_OPERATORS,
      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: [
			/'(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})'/,
			/"(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})"/,
			/`(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})`/,
		],
		'"': '"',
		"'": "'",
		'`': '`',
		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', 
      'SET_DELEGATE', 'CREATE_CONTRACT', 'IMPLICIT_ACCOUNT', 'NOW', 'AMOUNT', 'BALANCE', 'CHECK_SIGNATURE', 'BLAKE2B', 'SHA256',
      'SHA512', 'HASH_KEY', 'STEPS_TO_QUOTA', 'SOURCE', 'SENDER', 'ADDRESS', 'FAIL', 'CDAR', 'CDDR', 'DUUP', 'DUUUP', 'DUUUUP', 
      'DUUUUUP', 'DUUUUUUP', 'DUUUUUUUP', 'DIIP', 'DIIIP', 'DIIIIP', 'DIIIIIP', 'DIIIIIIP', 'DIIIIIIIP', 'REDUCE', 'CMPLT', 'UNPAIR', 'CMPGT',
      'CMPLE', 'CMPGE', 'UNPAPAIR', 'CAAR', 'CDDDDADR', 'CDDADDR', 'CDADDR', 'CDADAR', 'IFCMPEQ', 'CDDDADR', 'CADAR', 'CDDDAAR',
      'CADDR', 'CDDDDR', 'CDDAAR', 'CDDADAR', 'CDDDDDR', 'CDDDDAAR', 'ASSERT_CMPGE', 'CDAAR', 'CDADR', 'CDDAR', 'CDDDR', 
      'CMPEQ', 'CAAR', 'CAAAR', 'CAAAAR', 'CAAAAAR', 'CAAAAAAR', 'CAAAAAAAR', 'CDDR', 'CDDDR', 'CDDDDR', 'CDDDDDR', 'CDDDDDDR', 'CDDDDDDDR',
      'ASSERT_CMPEQ', 'ASSERT_CMPLT', 'ISNAT', 'IFCMPGT', 'IFCMPGE', 'IFCMPLT', 'IFCMPLE', 'IF_SOME', 'CADR' ],

moo

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

BSD-3-Clause
Latest version published 2 years ago

Package Health Score

77 / 100
Full package analysis