2022-04-20から1日間の記事一覧

シェブロテインを使ったパーザー

Stardog で使っているパーザーのインターフェイス https://github.com/stardog-union/millan/blob/master/src/helpers/chevrotain/types.ts : import { IToken, IRecognitionException, CstNode, TokenType, IRecognizerContext, } from 'chevrotain'; expo…

シェブロテインのCST構造

CstElement export declare type CstElement = IToken | CstNode IToken /** * Things to note: * - The offset range is inclusive to exclusive. * * - A lineTerminator as the last character does not effect the Token's line numbering. * In other w…

気付いた小ワザ

スプレッド構文 [...a, ...b] で Array.prototype.concat(a, b) スプレッド構文 {...a, ...b} で Object.assign(a, b) クラスなしのオブジェクト定義 let C = { add(x, y){return x + y}}; 分割〈destructuring〉代入 let {a, b} = {a:1, b:2, c:3}; オブジ…

正規表現を分かりやすく書く

https://github.com/stardog-union/millan/blob/master/src/helpers/regex.ts を少し変更する。名前を置換した: and → seq many → repeat export const regex = { or(...r: RegExp[]) { return new RegExp(r.map(({ source }) => `(${source})`).join('|'))…

他の関数の引数型を取って使う

let foo : Parameters<typeof someFunc>[2]; typeof someFunc で関数 someFunc の関数型〈アロー型〉を取る。 Parameters で、関数型の引数型配列を作る。 Parameters[2] で、関数型の引数型配列の三番目の型を取る。 変数 foo の型は、関数 someFunc の第三引数の型になる。</typeof>

シェブロテインの学習

https://github.com/witheve/Eve/blob/master/src/parser/parser.ts import * as chev from "chevrotain"; var {Lexer, tokenMatcher} = chev; export var Token = chev.Token; /* .... */ // Comments export class CommentLine extends Token { static PAT…

シェブロテインの内部規則のダンプ

const productions: Record<string, Rule> = parser.getGAstProductions(); console.dir(productions); GAstが意味不明だが、Generated AST かな? ともかく、GAstProductions が内部的に構築されればバージングが出来る状態になる。</string,>