mirror of
https://github.com/chenasraf/redar-browser.git
synced 2026-05-17 17:58:04 +00:00
Use pegjs loader
This commit is contained in:
@@ -209,6 +209,10 @@ module.exports = {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
test: /\.pegjs$/,
|
||||
loader: 'pegjs-loader'
|
||||
},
|
||||
// "file" loader makes sure those assets get served by WebpackDevServer.
|
||||
// When you `import` an asset, you get its (virtual) filename.
|
||||
// In production, they would get copied to the `build` folder.
|
||||
|
||||
@@ -233,6 +233,10 @@ module.exports = {
|
||||
),
|
||||
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
|
||||
},
|
||||
{
|
||||
test: /\.pegjs$/,
|
||||
loader: 'pegjs-loader'
|
||||
},
|
||||
// "file" loader makes sure assets end up in the `build` folder.
|
||||
// When you `import` an asset, you get its filename.
|
||||
// This loader don't uses a "test" so it will catch all modules
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
"immutable": "^3.8.2",
|
||||
"jest": "20.0.4",
|
||||
"object-assign": "4.1.1",
|
||||
"pegjs": "^0.10.0",
|
||||
"pegjs-loader": "^0.5.4",
|
||||
"postcss-flexbugs-fixes": "3.2.0",
|
||||
"postcss-import": "^11.0.0",
|
||||
"postcss-loader": "2.0.6",
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as I from './ResponseRepr.module'
|
||||
import * as D from 'common/Dispatcher'
|
||||
import RObject from 'components/RObject/RObject'
|
||||
import * as classNames from 'classnames'
|
||||
import { parse } from '../../filter-parser/parser'
|
||||
import { parse } from '../../filter-parser/filter.pegjs'
|
||||
|
||||
class ResponseRepr extends React.Component<I.IProps, I.IState> {
|
||||
private listeners: string[]
|
||||
|
||||
54
src/filter-parser/filter-new.pegjs
Normal file
54
src/filter-parser/filter-new.pegjs
Normal file
@@ -0,0 +1,54 @@
|
||||
Operator "comparison operator =, !=, >, >=, <, or <="
|
||||
= eq:"="
|
||||
/ neq1:[\<\>!]"=" { return neq1 + '=' }
|
||||
/ neq2:[\<\>]
|
||||
|
||||
Filter "field name"
|
||||
= $ [a-z0-9_.]i+
|
||||
|
||||
Value "string or number"
|
||||
= Number
|
||||
/ StringValue
|
||||
|
||||
Number
|
||||
= int:([0-9]+) "." dec:([0-9]+) {
|
||||
return parseFloat([int.join(''), dec.join('') || '0'].join('.'))
|
||||
}
|
||||
/ int:([0-9]+) { return parseInt(int.join('')) }
|
||||
|
||||
StringValue
|
||||
= '"' chars:DoubleStringCharacter* '"' { return chars.join(''); }
|
||||
/ "'" chars:SingleStringCharacter* "'" { return chars.join(''); }
|
||||
|
||||
DoubleStringCharacter
|
||||
= !('"' / "\\") char:. { return char; }
|
||||
/ "\\" sequence:EscapeSequence { return sequence; }
|
||||
|
||||
SingleStringCharacter
|
||||
= !("'" / "\\") char:. { return char; }
|
||||
/ "\\" sequence:EscapeSequence { return sequence; }
|
||||
|
||||
EscapeSequence
|
||||
= "'"
|
||||
/ '"'
|
||||
/ "\\"
|
||||
|
||||
_ "whitespace"
|
||||
= $ [ \t]*
|
||||
|
||||
LogicalOr
|
||||
= left:Equals "||" right:Equals { return { left, right, oper: 'or' } }
|
||||
/ LogicalAnd
|
||||
|
||||
LogicalAnd
|
||||
= left:Equals "&&" right:Equals { return { left, right, oper: 'and' } }
|
||||
/ Primary
|
||||
|
||||
Primary
|
||||
= Equals
|
||||
/ "(" or:LogicalOr ")" { console.log(or); return or }
|
||||
|
||||
Equals
|
||||
= _ key:Filter _ oper:Operator _ value:Value _ {
|
||||
return { key, oper, value }
|
||||
}
|
||||
@@ -1,3 +1,15 @@
|
||||
Chain
|
||||
= all:Equals+ {
|
||||
let filters = {}
|
||||
all.forEach(i => filters[i[0]] = { oper: i[1], value: i[2] })
|
||||
return filters
|
||||
}
|
||||
|
||||
Equals
|
||||
= _ key:Filter _ operator:Operator _ value:Value _ {
|
||||
return [key, operator, value]
|
||||
}
|
||||
|
||||
Operator "comparison operator =, !=, >, >=, <, or <="
|
||||
= eq:"="
|
||||
/ neq1:[\<\>!]"=" { return neq1 + '=' }
|
||||
@@ -35,20 +47,3 @@ EscapeSequence
|
||||
|
||||
_ "whitespace"
|
||||
= $ [ \t]*
|
||||
|
||||
LogicalOr
|
||||
= left:Equals "||" right:Equals { return { left, right, oper: 'or' } }
|
||||
/ LogicalAnd
|
||||
|
||||
LogicalAnd
|
||||
= left:Equals "&&" right:Equals { return { left, right, oper: 'and' } }
|
||||
/ Primary
|
||||
|
||||
Primary
|
||||
= Equals
|
||||
/ "(" or:LogicalOr ")" { console.log(or); return or }
|
||||
|
||||
Equals
|
||||
= _ key:Filter _ oper:Operator _ value:Value _ {
|
||||
return { key, oper, value }
|
||||
}
|
||||
|
||||
12
yarn.lock
12
yarn.lock
@@ -3423,7 +3423,7 @@ loader-utils@0.2.16:
|
||||
json5 "^0.5.0"
|
||||
object-assign "^4.0.1"
|
||||
|
||||
loader-utils@^0.2.15, loader-utils@^0.2.16, loader-utils@~0.2.2:
|
||||
loader-utils@^0.2.15, loader-utils@^0.2.16, loader-utils@^0.2.5, loader-utils@~0.2.2:
|
||||
version "0.2.17"
|
||||
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-0.2.17.tgz#f86e6374d43205a6e6c60e9196f17c0299bfb348"
|
||||
dependencies:
|
||||
@@ -4164,6 +4164,16 @@ pbkdf2@^3.0.3:
|
||||
safe-buffer "^5.0.1"
|
||||
sha.js "^2.4.8"
|
||||
|
||||
pegjs-loader@^0.5.4:
|
||||
version "0.5.4"
|
||||
resolved "https://registry.yarnpkg.com/pegjs-loader/-/pegjs-loader-0.5.4.tgz#3921ed6b454e82d36029b896cec6f8a6c2f6b098"
|
||||
dependencies:
|
||||
loader-utils "^0.2.5"
|
||||
|
||||
pegjs@^0.10.0:
|
||||
version "0.10.0"
|
||||
resolved "https://registry.yarnpkg.com/pegjs/-/pegjs-0.10.0.tgz#cf8bafae6eddff4b5a7efb185269eaaf4610ddbd"
|
||||
|
||||
performance-now@^0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-0.2.0.tgz#33ef30c5c77d4ea21c5a53869d91b56d8f2555e5"
|
||||
|
||||
Reference in New Issue
Block a user