How to use the ohm-js.grammar function in ohm-js

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-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 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)
	}
github robotlolita / helm / source / ohm-to-ast.js View on Github external
function makeParser(code) {
  const grammar = Ohm.grammar(code);

  const parse = (source, rule, { filename }) => {
    const match = grammar.match(source, rule);
    if (match.failed()) {
      throw new SyntaxError(match.message);
    }

    return match;
  };

  return parse;
}
github spderosso / deja-vu / packages / language / src / actionCompiler.ts View on Github external
constructor() {
    const grammarPath = path.join(__dirname, 'dv.ohm');
    this.grammar = ohm.grammar(readFileSync(grammarPath, 'utf-8'));
    this.semantics = this.grammar.createSemantics();
  }

ohm-js

An object-oriented language for parsing and pattern matching

MIT
Latest version published 2 years ago

Package Health Score

69 / 100
Full package analysis