-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
323 additions
and
120 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,8 +131,10 @@ ometa Ometa { | |
rule | ||
equal | ||
|
||
times | ||
token | ||
times | ||
not | ||
bind | ||
project | ||
range | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,30 @@ | ||
export namespace GrammarAst { | ||
export namespace Ast { | ||
export type Grammar = Rule[] | ||
export type Rule = [string, Expr] | ||
export type Expr = ExSeq | ExAlt | ExAtom | ExRule | ExNotLess | ||
export type ExSeq = ['seq', Expr[]] | ||
export type ExAlt = ['alt', Expr[]] | ||
|
||
export type Expr = | ||
Ex.Seq | ||
| Ex.Alt | ||
| Ex.Atom | ||
| Ex.Rule | ||
| Ex.Times | ||
| Ex.Token | ||
| Ex.Not | ||
| Ex.Project | ||
| Ex.Regex | ||
| Ex.Range | ||
|
||
export type ExAtom = ['equal', string] | ||
export type ExRule = ['rule', string] | ||
export type ExNotLess = ['notLess', number, Expr] | ||
export namespace Ex { | ||
export type Seq = ['seq', Expr[]] | ||
export type Alt = ['alt', Expr[]] | ||
export type Atom = ['equal', string] | ||
export type Rule = ['rule', string] | ||
export type Times = ['times', number, number, Expr] | ||
|
||
export type Token = ['token', string] | ||
export type Not = ['not', Expr] | ||
export type Project = ['project', string, Expr] | ||
export type Regex = ['regex', string] | ||
export type Range = ['range', string, string] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
import { IProjectors } from 'step2/types' | ||
import { Ast as AST } from '../grammar-ast' | ||
|
||
/* | ||
Выражения располагаются в порядке приоритета (внизу - наибольший приоритет) | ||
ometa Ometa1 { | ||
ometa = "ometa" ident "{" eRule* "}", | ||
eRule = ident "=" "|"? eTop inlSpaces* ',' newline, | ||
eTop = eAlt, | ||
eAlt = eProj ("|" eProj)*, | ||
eProj = eSeq ("->" ident)?, | ||
eSeq = eQuant (spaces quant)*, | ||
eQuant = eNot ('?' | '*' | '+')?, | ||
eNot = '~'? operand, | ||
operand = | ||
| '(' eTop ') -> op_group | ||
| eRange -> op_range | ||
| eStr -> op_str | ||
| eToken -> op_token | ||
| eRegex -> op_regex | ||
| ident -> op_rule, | ||
eRange = alphanum '-' alphanum, | ||
eStr = "'" (~'\'' anything)* '\'', | ||
eToken = "\"" (~'"' anything)* '"', | ||
eRegex = "/" (~'/' anything)* '/' a-z*, | ||
ident = letter alphanum*, | ||
alphanum = letter | digit, | ||
digit = 0-9, | ||
letter = A-Z | a-z, | ||
spaces = /\s+/, | ||
space = /\s/, | ||
inlSpaces = /[ \t]+/, | ||
inlSpace = /[ \t]/, | ||
newline = /(\r\n)|\n/, | ||
} | ||
*/ | ||
|
||
export const ometaExpr: AST.Grammar = [ | ||
['ometa', ['seq', [ | ||
['token', 'ometa'], | ||
['rule', 'ident'], | ||
['token', '{'], | ||
['times', 0, null, ['rule', 'eRule']], | ||
['token', '}'], | ||
]]], | ||
|
||
['rule', ['seq', [ | ||
['rule', 'ident'], | ||
['token', '='], | ||
['times', 0, 1, ['token', '|']], | ||
['rule', 'eTop'], | ||
['times', 0, null, ['rule', 'inlSpaces']], | ||
['equal', ','], | ||
['rule', 'newline'], | ||
]]], | ||
|
||
['eTop', ['rule', 'eAlt']], | ||
|
||
['eAlt', ['seq', [ | ||
['rule', 'eProj'], | ||
['times', 0, null, ['seq', [['equal', '|'], ['rule', 'eProj']]]] | ||
]]], | ||
|
||
['eProj', ['seq', [ | ||
['rule', 'eSeq'], | ||
['times', 0, 1, ['seq', [['equal', '->'], ['rule', 'ident']]]], | ||
]]], | ||
|
||
['eSeq', ['seq', [ | ||
['rule', 'eQuant'], | ||
['times', 0, null, ['seq', [['rule', 'spaces'], ['rule', 'eQuant']]]], | ||
]]], | ||
|
||
['eQuant', ['seq', [ | ||
['rule', 'not'], | ||
['times', 0, 1, ['alt', [ | ||
['equal', '?'], | ||
['equal', '*'], | ||
['equal', '+'], | ||
]]] | ||
]]], | ||
|
||
['eNot', ['seq', [ | ||
['times', 0, 1, ['equal', '~']], | ||
['rule', 'operand'] | ||
]]], | ||
|
||
['operand', ['alt', [ | ||
['project', 'op_group', ['seq', [ | ||
['equal', '('], | ||
['rule', 'eTop'], | ||
['equal', ')'], | ||
]]], | ||
['project', 'op_range', ['rule', 'eRange']], | ||
['project', 'op_str', ['rule', 'eStr']], | ||
['project', 'op_token', ['rule', 'eToken']], | ||
['project', 'op_regex', ['rule', 'eRegex']], | ||
['project', 'op_rule', ['rule', 'ident']], | ||
]]], | ||
|
||
['eRange', ['seq', [ | ||
['rule', 'alphanum'], | ||
['equal', '-'], | ||
['rule', 'alphanum'], | ||
]]], | ||
|
||
['eStr', ['seq', [ | ||
['token', '\''], | ||
['times', 0, null, ['seq', [['not', ['equal', '\'']], ['rule', 'anything']]]], | ||
['equal', '\''], | ||
]]], | ||
|
||
['eToken', ['seq', [ | ||
['token', '"'], | ||
['times', 0, null, ['seq', [['not', ['equal', '"']], ['rule', 'anything']]]], | ||
['equal', '"'], | ||
]]], | ||
|
||
['eRegex', ['seq', [ | ||
['token', '/'], | ||
['times', 0, null, ['seq', [['not', ['equal', '/']], ['rule', 'anything']]]], | ||
['equal', '/'], | ||
['times', 0, null, ['range', 'a', 'z']], | ||
]]], | ||
|
||
['ident', ['seq', [ | ||
['rule', 'letter'], | ||
['times', 0, null, ['rule', 'alphanum']] | ||
]]], | ||
|
||
['alphanum', ['alt', [['rule', 'letter'], ['rule', 'digit']]]], | ||
|
||
['digit', ['range', '0', '9'],], | ||
|
||
['letter', ['alt', [ | ||
['range', 'A', 'Z'], | ||
['range', 'a', 'z'], | ||
]]], | ||
|
||
['spaces', ['regex', '\\s+']], | ||
|
||
['space', ['regex', '\\s']], | ||
|
||
['inlSpaces', ['regex', '[ \\t]+']], | ||
|
||
['inlSpace', ['regex', '[ \\t]']], | ||
|
||
['newline', ['regex', '(\\r\\n)|\\n']], | ||
] | ||
|
||
|
||
export const proj: IProjectors = { | ||
|
||
} |
Oops, something went wrong.