### Setup development environment Source: https://github.com/ohmjs/ohm/blob/main/packages/compiler/README.md Install project dependencies for development. ```bash pnpm install ``` -------------------------------- ### Customized AST Transformation Example Source: https://github.com/ohmjs/ohm/blob/main/doc/extras.md This code snippet demonstrates how to create an AST from a matched expression using a custom mapping. It shows the initial setup for transforming CST to AST with specific rule configurations. ```javascript // create ohm, g, match and toAST const ast = toAST(match, { Equation: {content: 0}, AddExpr: {type: 'Expression', expr1: 0, op: 1, expr2: 2}, }); ``` -------------------------------- ### Install Ohm with pnpm Source: https://github.com/ohmjs/ohm/blob/main/README.md Install the ohm-js package using pnpm. ```bash pnpm add ohm-js ``` -------------------------------- ### toAST Example Source: https://github.com/ohmjs/ohm/blob/main/doc/extras.md Example demonstrating the use of toAST to convert a MatchResult to an AST. ```javascript const ohm = require('ohm-js'); const g = ohm.grammar( ` G { Equation = AddExpr AddExpr = number "+" number number = digit+ } ` ); const match = g.match('24 + 6'); const toAST = require('ohm-js/extras').toAST; const ast = toAST(match); ``` -------------------------------- ### Example: Compile and specify output file Source: https://github.com/ohmjs/ohm/blob/main/doc/docker.md An example demonstrating how to compile a grammar file and specify the output file name for the WASM module. ```sh docker run --rm -v $(pwd):/local ohmjs/ohm:latest compile -o arithmetic.wasm arithmetic.ohm ``` -------------------------------- ### Matching with a Specific Start Rule Source: https://github.com/ohmjs/ohm/blob/main/examples/math/index.html Shows how to specify a start rule for the match() method, overriding the default start rule. ```javascript g.match(' ( \t123 ) ', 'PriExp').succeeded(); // evaluates to `true` ``` -------------------------------- ### Install Ohm with Yarn Source: https://github.com/ohmjs/ohm/blob/main/README.md Install the ohm-js package using Yarn. ```bash yarn add ohm-js ``` -------------------------------- ### Install dependencies Source: https://github.com/ohmjs/ohm/blob/main/packages/compiler/README.md Install @ohm-js/compiler as a dev dependency and ohm-js for runtime. ```bash npm install --save-dev @ohm-js/compiler npm install ohm-js ``` -------------------------------- ### Example Semantic Actions with Implementation Source: https://github.com/ohmjs/ohm/blob/main/doc/api-reference.md Example semantic actions with placeholder implementations filled in. ```javascript return lastName.x().toUpperCase() + ', ' + firstName.x(); return this.sourceString; ``` -------------------------------- ### Install Ohm with npm Source: https://github.com/ohmjs/ohm/blob/main/README.md Install the ohm-js package using npm. ```bash npm install ohm-js ``` -------------------------------- ### Generated AST Example Source: https://github.com/ohmjs/ohm/blob/main/doc/extras.md The resulting AST from the toAST example. ```json { "type": "AddExpr", // 'type' automatically taken from the rule name "0": "24", // First part (position 0) matched by AddExpr rule "2": "6" // Third part (position 2) matched by AddExpr rule } ``` -------------------------------- ### Instantiating a Grammar Source: https://github.com/ohmjs/ohm/blob/main/doc/api-reference.md Example of instantiating a Grammar using ohm.grammar. ```javascript const parentDef = String.raw` Parent { start = "parent" } `; const parentGrammar = ohm.grammar(parentDef); ``` -------------------------------- ### Install development dependencies Source: https://github.com/ohmjs/ohm/blob/main/doc/contributor-guide.md Installs the necessary development dependencies using pnpm. ```bash cd ohm pnpm install ``` -------------------------------- ### Minimal Docker setup for macOS Source: https://github.com/ohmjs/ohm/blob/main/doc/docker.md Steps to set up Docker, Colima, and Docker Compose on macOS. ```sh brew install colima docker docker-compose docker-credential-helper colima start ``` -------------------------------- ### Parameterized Rule Example Source: https://github.com/ohmjs/ohm/blob/main/doc/syntax-reference.md Example of defining a parameterized rule in Ohm. ```ohm Repeat = x x ``` -------------------------------- ### Install ohm-grammar-ecmascript Source: https://github.com/ohmjs/ohm/blob/main/examples/ecmascript/README.md Installs the ECMAScript grammars package using NPM. ```bash npm install ohm-grammar-ecmascript ``` -------------------------------- ### Syntactic Rule Example Source: https://github.com/ohmjs/ohm/blob/main/doc/syntax-reference.md Example of syntactic rules for an Array grammar. ```ohm Array = "[" "]" -- empty | "[" Elements "]" -- nonEmpty Elements = Element ("," Element)* ``` -------------------------------- ### Grammar for asIteration Example Source: https://github.com/ohmjs/ohm/blob/main/doc/api-reference.md A simple Ohm grammar demonstrating a ListOf expression. ```ohm G { Start = ListOf } ``` -------------------------------- ### Example Semantic Actions Source: https://github.com/ohmjs/ohm/blob/main/doc/api-reference.md An example of semantic actions for the Name grammar, demonstrating how to compute values for parse nodes. ```javascript const actions = { FullName(firstName, lastName) { ... }, name(parts) { ... } }; ``` -------------------------------- ### Install @ohm-js/cli Source: https://github.com/ohmjs/ohm/blob/main/doc/typescript.md Install the Ohm CLI package as a development dependency. ```bash npm install -D @ohm-js/cli ``` -------------------------------- ### Usage Example Source: https://github.com/ohmjs/ohm/blob/main/packages/compiler/test/go/README.md Instantiates a grammar from compiled Wasm bytes, matches input against it, and retrieves the CST root if the match succeeded. ```go // Instantiate a grammar from compiled Wasm bytes wasmBytes, _ := os.ReadFile("path/to/grammar.wasm") g, err := NewGrammar(ctx, wasmBytes) defers g.Close() // Match input against the grammar (optional second arg is start rule) result, err := g.Match("var x = 1;") defers result.Close() if result.Succeeded() { cstRoot, err := result.GetCstRoot() // ...walk the tree } ``` -------------------------------- ### Getting help from the Docker image Source: https://github.com/ohmjs/ohm/blob/main/doc/docker.md Command to display usage information for the Ohm.js Docker image. ```sh docker run --rm ohmjs/ohm:latest help ``` -------------------------------- ### Example Usage Source: https://github.com/ohmjs/ohm/blob/main/packages/es-grammars/README.md Demonstrates how to import and use an ES grammar to match JavaScript code. ```javascript import {es2020} from '@ohm-js/es-grammars'; es2020.match('() => 3').succeeded(); // true ``` -------------------------------- ### Usage Example Source: https://github.com/ohmjs/ohm/blob/main/examples/ecmascript/README.md Demonstrates how to import and use the ES5 grammar from the ohm-grammar-ecmascript package to match ECMAScript code. ```javascript import * as es5 from 'ohm-grammar-ecmascript'; const result = es5.grammar.match('var x = 3; console.log(x);'); assert(result.succeeded()); ``` -------------------------------- ### JavaScript Setup and Event Handling Source: https://github.com/ohmjs/ohm/blob/main/examples/incremental/index.html JavaScript code for setting up the CodeMirror editor, handling grammar parsing, and updating statistics. ```javascript 'use strict'; const grammarSource = String.raw` F { Exp = let PriPat "=" Exp in Exp -- let | let rec ident "=" Exp in Exp -- letrec | let rec "(" ident ":" Type ")" "=" Exp in Exp -- typedLetrec | fun PriPat+ "->" Exp -- fun | if Exp then Exp else Exp -- if | match Exp with "|"? NonemptyListOf -- match PatAndExp = Pat "->" Exp Pat = ctor PriPat -- datum | PriPat PriPat -- emptyDatum | "(" Pat ")" -- paren | "(" Pat ":" Type ")" -- typed | "(" ListOf ")" -- tuple | "[" ListOf "]" -- list | "_" -- wild | ident -- ident | number -- number | trueK -- true | falseK -- false OrExp = OrExp "||" AndExp -- or | AndExp AndExp = AndExp "&&" EqExp -- and | EqExp EqExp = RelExp "=" RelExp -- eq | RelExp "!=" RelExp -- neq | RelExp RelExp = AddExp "<" AddExp -- lt | AddExp ">" AddExp -- gt | AddExp AddExp = AddExp "+" MulExp -- plus | AddExp "-" MulExp -- minus | MulExp MulExp = MulExp "*" CallExp -- times | MulExp "/" CallExp -- divide | MulExp "%" CallExp -- modulus | CallExp CallExp = CallExp PriExp -- call | UnExp UnExp = "+" DatumExp -- pos | "-" DatumExp -- neg | delay DatumExp -- delay | force DatumExp -- force | DatumExp DatumExp = ctor PriExp -- datum | PriExp PriExp = ctor -- emptyDatum | "(" Exp ")" -- paren | "(" Exp ":" Type ")" -- typed | "(" ListOf ")" -- tuple | "[" Exp "|" Pat "<-" Exp ("," Exp)? "]" -- listComp | "[" ListOf "]" -- list | ident -- ident | number -- number | trueK -- true | falseK -- false Type = FunType FunType = TupleType "->" FunType -- fun | TupleType TupleType = ListOrDelayedType ("*" ListOrDelayedType)+ -- tuple | ListOrDelayedType ListOrDelayedType = ListOrDelayedType list -- list | ListOrDelayedType delayed -- delayed | PriType PriType = "(" Type ")" -- paren | int -- int | bool -- bool | unit -- unit | typeVar typeVar (a type variable) = "'" ident // Lexical rules ident (an identifier) = ~keyword lower alnum* ctor (a data constructor) = ~keyword upper alnum* number (a number) = digit* "." digit+ -- fract | digit+ -- whole fun = "fun" ~alnum let = "let" ~alnum rec = "rec" ~alnum in = "in" ~alnum if = "if" ~alnum then = "then" ~alnum else = "else" ~alnum match = "match" ~alnum with = "with" ~alnum trueK = "true" ~alnum falseK = "false" ~alnum delay = "delay" ~alnum force = "force" ~alnum int = "int" ~alnum bool = "bool" ~alnum unit = "unit" ~alnum list = "list" ~alnum delayed = "delayed" ~alnum keyword = fun | let | rec | in | if | then | else | match | with | trueK | falseK | delay | force | int | bool | unit | list | delayed space += comment comment = "/*" (~"*/" any)* "*/" -- multiLine | "//" (~"\n" any)* -- singleLine } `; // Declare some helpers function time(fn) { const startTime = Date.now(); fn(); const endTime = Date.now(); return endTime - startTime; } function spaces(n) { let ss = ''; while (n-- > 0) { ss += ' '; } return ss; } // Declare some variables to keep stats, etc. const parseTimes = []; const getExpectedTextTimes = []; function updateStats() { const totalParseTime = parseTimes.reduce((x, y) => x + y, 0); msPerParseSpan.innerText = (totalParseTime / parseTimes.length).toFixed(2); msForLastParseSpan.innerText = parseTimes[parseTimes.length - 1]; parseTimesSparkline.setAttribute('data-values', parseTimes); const totalGetExpectedTextTime = getExpectedTextTimes.reduce((x, y) => x + y, 0); numGetExpectedTextCallsSpan.innerText = getExpectedTextTimes.length; totalGetExpectedTextTimeSpan.innerText = totalGetExpectedTextTime; msPerGetExpectedTextSpan.innerText = (totalGetExpectedTextTime / getExpectedTextTimes.length).toFixed(2); getExpectedTextTimesSparkline.setAttribute('data-values', getExpectedTextTimes); updateSparklines(); } // Set up our CodeMirror instance, and react to changes in the input const editor = CodeMirror.fromTextArea(myTextArea, { lineNumbers: true }); const g = ohm.grammar(grammarSource); const m = g.matcher(); let parseErrorWidget; editor.on('beforeChange', function(cmInstance, changeObj) { const insertedText = changeObj.text.join('\n'); const fromIdx = editor.indexFromPos(changeObj.from); const toIdx = editor.indexFromPos(changeObj.to); m.replaceInputRange(fromIdx, toIdx, inserte ``` -------------------------------- ### Instantiating Grammars with Inheritance Source: https://github.com/ohmjs/ohm/blob/main/doc/api-reference.md Example of instantiating a new grammar, Child, that inherits from the Parent grammar using ohm.grammars. ```javascript const childDef = String.raw` Child <: Parent { start := "child" } `; const childGrammar = ohm.grammars(childDef, {Parent: parentGrammar}); console.log(Object.keys(childGrammar)); // > [ 'Child' ] ``` -------------------------------- ### Exporting grammars and semantics Source: https://github.com/ohmjs/ohm/blob/main/doc/publishing-grammars.md Example of how to export grammars and semantics from a module, and how to use them. ```javascript const {python2} = require('./your-python-package'); const result = python2.grammar.match('print 3'); python2.semantics(result).eval(); ``` -------------------------------- ### Node Methods and Properties Source: https://github.com/ohmjs/ohm/blob/main/doc/api-reference.md Examples of using various methods and properties of a parse node. ```javascript n.child(idx: number) => Node n.isTerminal() => boolean n.isIteration() => boolean n.children: Array n.ctorName: string n.source: Interval n.sourceString: string n.numChildren: number n.isOptional() => boolean ``` -------------------------------- ### Analyzing image size from inside the container Source: https://github.com/ohmjs/ohm/blob/main/doc/docker.md Steps to install and run `ncdu` inside the container to analyze disk usage. ```sh apt-get update apt-get install -y ncdu ncdu / ``` -------------------------------- ### Operator precedence with left-recursive rules Source: https://github.com/ohmjs/ohm/blob/main/doc/patterns-and-pitfalls.md Example demonstrating how to handle operator precedence in Ohm using left-recursive rules. ```ohm exp = addExp addExp = addExp "+" mulExp -- plus | addExp "-" mulExp -- minus | mulExp mulExp = mulExp "*" priExp -- times | mulExp "/" priExp -- divide | priExp ``` -------------------------------- ### C-style comments Source: https://github.com/ohmjs/ohm/blob/main/doc/patterns-and-pitfalls.md Example of defining C-style multiline comments. ```ohm comment = "/*" (~"*/" any)* "*/" ``` -------------------------------- ### Example Grammar Source: https://github.com/ohmjs/ohm/blob/main/doc/api-reference.md A simple grammar defining a Name and FullName structure. ```ohm Name { FullName = name name name = (letter | "-" | ".")+ } ``` -------------------------------- ### Basic Grammar Example Source: https://github.com/ohmjs/ohm/blob/main/doc/syntax-reference.md A simple Ohm grammar named 'Arithmetic' with a single rule 'Expr' that matches the literal string '1 + 1'. ```ohm Arithmetic { Expr = "1 + 1" } ``` -------------------------------- ### Trailer code for _PyPegen_parse Source: https://github.com/ohmjs/ohm/blob/main/packages/lang-python/python-peg-grammar.txt This is a C code snippet that initializes keywords and runs the parser based on the start rule. ```c void * _PyPegen_parse(Parser *p) { // Initialize keywords p->keywords = reserved_keywords; p->n_keyword_lists = n_keyword_lists; p->soft_keywords = soft_keywords; // Run parser void *result = NULL; if (p->start_rule == Py_file_input) { result = file_rule(p); } else if (p->start_rule == Py_single_input) { result = interactive_rule(p); } else if (p->start_rule == Py_eval_input) { result = eval_rule(p); } else if (p->start_rule == Py_func_type_input) { result = func_type_rule(p); } return result; } ``` -------------------------------- ### Instantiating and Using the Grammar Source: https://github.com/ohmjs/ohm/blob/main/examples/math/index.html Demonstrates how to instantiate an Ohm grammar from a source string and use its match() method to recognize inputs. ```javascript const g = ohm.grammar(source); g.match('1+2*3').succeeded(); // evaluates to `true` g.match('1+2*3').failed(); // evaluates to `false` g.match('I CAN HAS CHEEZBURGER?').succeeded(); // evaluates to `false` g.match('I CAN HAS CHEEZBURGER?').failed(); // evaluates to `true` ``` -------------------------------- ### Use Ohm with Deno Source: https://github.com/ohmjs/ohm/blob/main/README.md Import Ohm from an unpkg URL for use with Deno. ```js import * as ohm from 'https://unpkg.com/ohm-js@17'; ``` -------------------------------- ### Using the match() method Source: https://github.com/ohmjs/ohm/blob/main/README.md This example shows how to use the `match()` method of an instantiated grammar object to recognize input and check if the match was successful. ```javascript const userInput = 'Hello'; const m = myGrammar.match(userInput); if (m.succeeded()) { console.log('Greetings, human.'); } else { console.log("That's not a greeting!"); } ``` -------------------------------- ### Undeclared Grammar Example Source: https://github.com/ohmjs/ohm/blob/main/doc/errors.md Example demonstrating how to fix an UndeclaredGrammar error by passing a namespace argument to ohm.grammar(). ```javascript const ns = {}; ns.G1 = ohm.grammar('G1 {}'); const g2 = ohm.grammar('G2 <: G1 {}', ns); ``` -------------------------------- ### Invalid Lambda Syntax Examples Source: https://github.com/ohmjs/ohm/blob/main/packages/lang-python/python-peg-grammar.txt Examples of invalid syntax related to lambda parameters, including default values, bare '*', and double '**'. ```python invalid_lambda_star_etc: | '*' (':' | ',' (':' | '**')) { RAISE_SYNTAX_ERROR("named parameters must follow bare *") } | '*' lambda_param a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "var-positional parameter cannot have default value") } | '*' (lambda_param_no_default | ',') lambda_param_maybe_default* a='*' (lambda_param_no_default | ',') { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "* may appear only once") } invalid_lambda_kwds: | '**' lambda_param a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "var-keyword parameter cannot have default value") } | '**' lambda_param ',' a=lambda_param { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "parameters cannot follow var-keyword parameter") } | '**' lambda_param ',' a[Token*]=('*'|'**'|'/') { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "parameters cannot follow var-keyword parameter") } ``` -------------------------------- ### Multiline comments Source: https://github.com/ohmjs/ohm/blob/main/doc/syntax-reference.md Example of multiline comments in Ohm grammars. ```ohm /* Note: Punctuator and DivPunctuator (see https://es5.github.io/x7.html#x7.7) are not currently used by this grammar. */ ``` -------------------------------- ### Single-line comments Source: https://github.com/ohmjs/ohm/blob/main/doc/syntax-reference.md Example of single-line comments in Ohm grammars. ```ohm booleanLiteral = ("true" | "false") // TODO: Should we support "True"/"False" as well? ``` ```ohm // For semantics on how decimal literals are constructed, see section 7.8.3 ``` -------------------------------- ### Memoization Visualization Canvas Setup Source: https://github.com/ohmjs/ohm/blob/main/packages/memoviz-demo/index.html Sets up the canvas element for drawing the memoization visualization, adjusting for device pixel ratio and screen size. ```javascript const canvas = document.querySelector("canvas"); const ctx = canvas.getContext("2d"); // Get the DPR and size of the canvas const dpr = window.devicePixelRatio; // const rect = canvas.getBoundingClientRect(); // Set the "actual" size of the canvas canvas.width = window.innerWidth * dpr; canvas.height = window.innerHeight * dpr; canvas.style.width = `${window.innerWidth}px`; canvas.style.height = `${window.innerHeight}px`; // prettier-ignore const data = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [1,1,0,0,0,1,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ]; ``` -------------------------------- ### Testing asIteration Example Source: https://github.com/ohmjs/ohm/blob/main/doc/api-reference.md Assertion to verify the output of the asIteration operation. ```javascript assert.deepEqual( s(g_asIteration.match('a, b, c')).upper(), ['A', 'B', 'C'] ); ``` -------------------------------- ### Semantics for asIteration Example Source: https://github.com/ohmjs/ohm/blob/main/doc/api-reference.md An operation added to a semantics to process a ListOf expression using asIteration. ```javascript s.addOperation('upper()', { Start(list) { return list.asIteration().children.map(c => c.upper()); }, letter(l) { return this.sourceString.toUpperCase(); } }); ``` -------------------------------- ### Ohm-js Demo Page Source: https://github.com/ohmjs/ohm/blob/main/packages/memoviz-demo/index.html This HTML file serves as a demo page for the Ohm-js library, demonstrating its usage and features. ```html Ohm Demo

Ohm-js Demo

This page demonstrates the capabilities of the Ohm-js library.

Grammar