How to use ohm-js - 10 common examples

To help you get started, we’ve selected a few ohm-js 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 GameMakerDiscord / gml-tools-langserver / src / langserv.ts View on Github external
constructor(public connection: IConnection) {
        this.connection = connection;
        this.originalOpenDocuments = [];
        this.gmlGrammar = grammar(fse.readFileSync(path.join(__dirname, path.normalize('../lib/gmlGrammar.ohm')), 'utf-8'));
        this.__dirName = path.normalize(__dirname);

        // Create our tools:
        this.reference = new Reference(this);
        this.fsManager = new FileSystem(this.gmlGrammar, this);
        this.initialStartup = new InitialAndShutdown(this.reference, this.gmlGrammar, this);

        //#region Language Services
        this.gmlHoverProvider = new GMLHoverProvider(this.reference, this.fsManager);
        this.gmlDefinitionProvider = new GMLDefinitionProvider(this.reference, this);
        this.gmlSignatureProvider = new GMLSignatureProvider(this.reference, this.fsManager);
        this.gmlCompletionProvider = new GMLCompletionProvider(this.reference, this.fsManager);
        this.timer = new TimeUtil();

        // Basic User Settings
        this.userSettings = {
github harc / ohm / examples / ecmascript / es5.js View on Github external
for (var i = 0; i < flatChildren.length; ++i) {
    var child = flatChildren[i];

    // Restore any discarded whitespace between this node and the previous one.
    if (child.source.startIdx > prevEndIdx) {
      code += node.source.sourceString.slice(prevEndIdx, child.source.startIdx);
    }
    code += child.toES5();
    prevEndIdx = child.source.endIdx;
  }
  return code;
}

// Instantiate the ES5 grammar.
var contents = fs.readFileSync(path.join(__dirname, 'es5.ohm'));
var g = ohm.grammars(contents).ES5;
var semantics = g.createSemantics();

semantics.addOperation('toES5()', {
  Program: function(_, sourceElements) {
    // Top-level leading and trailing whitespace is not handled by nodeToES5(), so do it here.
    var sourceString = this.source.sourceString;
    return sourceString.slice(0, this.source.startIdx) +
           nodeToES5(this, [sourceElements]) +
           sourceString.slice(this.source.endIdx);
  },
  _nonterminal: function(children) {
    return nodeToES5(this, children);
  },
  _terminal: function() {
    return this.sourceString;
  }
github harc / ohm-editor / test / testUtil.js View on Github external
function makeGrammar(source, optNamespace) {
  if (Array.isArray(source)) {
    source = source.join('\n');
  }
  return ohm.grammar(source, optNamespace);
}
github harc / ohm-editor / test / testUtil.js View on Github external
function makeGrammars(source, optNamespace) {
  if (Array.isArray(source)) {
    source = source.join('\n');
  }
  return ohm.grammars(source, optNamespace);
}
github spderosso / deja-vu / packages / compiler / src / component-input / component-input.compiler.ts View on Github external
constructor() {
    const grammarPath = path.join(
      __dirname, '..', 'component', 'component.grammar.ohm');
    this.grammar = ohm.grammar(readFileSync(grammarPath, 'utf-8'));
    this.semantics = this.grammar.createSemantics();
  }
github davidbalbert / spreadsheet.js / src / parser.js View on Github external
= "(" Exp ")"  -- paren
    | "+" PriExp   -- pos
    | "-" PriExp   -- neg
    | cell
    | number

  cell  (a cell)
    = upper+ digit+

  number  (a number)
    = digit* "." digit+  -- fract
    | digit+             -- whole
}
`;

const formulaGrammar = ohm.grammar(GRAMMAR_SRC);

class UnOp {
  constructor(child) {
    this.child = child;
  }
}

class BinOp {
  constructor(left, right) {
    this.left = left;
    this.right = right;
  }
}

class Plus extends BinOp {
  eval(name, cells) {
github spderosso / deja-vu / core / lang / src / parser.ts View on Github external
constructor() {
    const grammar_path = path.join(__dirname, "grammar.ohm");
    this._grammar = ohm.grammar(fs.readFileSync(grammar_path, "utf-8"));
    this._semantics = this._grammar.createSemantics()
      .addOperation("tbonds", {
        ClicheDecl: (cliche, name, uses, key1, para, key2) => {
          this.cliche_map = this._get_cliche_map(name.sourceString, uses);
          return _u
            .chain(para.tbonds())
            .flatten()
            .reject(_u.isEmpty)
            .value();
        },
        Paragraph_widget: decl => [],
        Paragraph_data: decl => decl.tbonds(),
        Paragraph_assignment: decl => [],
        DataDecl: (data, name, key1, fields, key2, bond) => {
          const subtype = name.sourceString;
          const mapped_cliche = this.cliche_map["this"];
github mlajtos / moniel / src / scripts / Parser.js View on Github external
constructor() {
		this.contents = fs.readFileSync(__dirname + "/src/moniel.ohm", "utf8")
		this.grammar = ohm.grammar(this.contents)
		this.semantics = this.grammar.createSemantics().addOperation("eval", this.evalOperation)
	}

ohm-js

An object-oriented language for parsing and pattern matching

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis