Skip to content

Commit

Permalink
Add types that will be moved back to easyscore.ts and parser.ts.
Browse files Browse the repository at this point in the history
  • Loading branch information
ronyeh committed May 6, 2021
1 parent bb53ddc commit c90f86e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import { Vex } from './vex';
import { Grammar } from './easyscore';
import { Rule, Match, RuleFunction, TriggerFunction, TriggerState } from './types/common';

// To enable logging for this class. Set `Vex.Flow.Parser.DEBUG` to `true`.
function L(...args) {
function L(...args: any[]) {
if (Parser.DEBUG) Vex.L('Vex.Flow.Parser', args);
}

Expand All @@ -26,6 +27,8 @@ function flattenMatches(results) {
// can parse any line and execute code when specific rules are met (e.g.,
// when a string is terminated.)
export class Parser {
static DEBUG: boolean = false;

// For an example of a simple grammar, take a look at tests/parser_tests.js or
// the EasyScore grammar in easyscore.js.
constructor(grammar) {
Expand Down
22 changes: 22 additions & 0 deletions src/types/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,25 @@ export interface ModifierContextState {
text_line: number;
top_text_line: number;
}


/* TODO: Move to EasyScore / Grammar / Parser */
export type Match = string | Match[];
export interface Rule {
// Lexer Rules
token?: string; // The token property is a string that is compiled into a RegExp.
noSpace?: boolean; // TODO: None of the EasyScore rules specify noSpace, so it is not used anywhere.

// Parser Rules
expect?: RuleFunction[];
zeroOrMore?: boolean;
oneOrMore?: boolean;
maybe?: boolean;
or?: boolean;
run?: TriggerFunction;
}
export interface TriggerState {
matches: Match[];
}
export type RuleFunction = () => Rule;
export type TriggerFunction = (state?: TriggerState) => void;

0 comments on commit c90f86e

Please sign in to comment.