Beginning to add some functionality to the parser
This commit is contained in:
+1
-1
@@ -1,3 +1,3 @@
|
||||
import parser from './parser/javascript.peg';
|
||||
import parser from './parser/javascript.js';
|
||||
|
||||
window.parser = parser;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import parser from './javascript/grammar.peg';
|
||||
|
||||
import Root from './javascript/root.js';
|
||||
import Regexp from './javascript/regexp.js';
|
||||
|
||||
parser.Parser.Root = Root;
|
||||
parser.Parser.Regexp = Regexp;
|
||||
|
||||
export default parser;
|
||||
@@ -1,8 +1,7 @@
|
||||
grammar JavascriptRegexp
|
||||
root <- regexp_literal / regexp
|
||||
regexp_literal <- "/" regexp "/" [igm]*
|
||||
regexp <- match ( "|" regexp )?
|
||||
match <- anchor_start? ( ( subexp / charset / terminal ) repeat? )* anchor_end?
|
||||
root <- ( ( "/" regexp "/" fl:[igm]* ) / regexp ) <Root>
|
||||
regexp <- match ( "|" regexp )? <Regexp>
|
||||
match <- anchor_start? ( ( subexp / charset / terminal ) repeat? )* anchor_end?
|
||||
anchor_start <- "^"
|
||||
anchor_end <- "$"
|
||||
repeat <- ( repeat_any / repeat_required / repeat_optional / repeat_spec ) repeat_greedy?
|
||||
@@ -0,0 +1,9 @@
|
||||
export default {
|
||||
matches() {
|
||||
if (this.elements[1].regexp) {
|
||||
return [this.match].concat(this.elements[1].regexp.matches());
|
||||
} else {
|
||||
return [this.match];
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
export default {
|
||||
flags() {
|
||||
var flags;
|
||||
|
||||
if (this.fl) {
|
||||
flags = this.fl.textValue;
|
||||
} else {
|
||||
flags = '';
|
||||
}
|
||||
|
||||
return {
|
||||
global: /g/.test(flags),
|
||||
ignore_case: /i/.test(flags),
|
||||
multiline: /m/.test(flags)
|
||||
};
|
||||
},
|
||||
|
||||
expression() {
|
||||
if (this.regexp) {
|
||||
return this.regexp;
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user