Skip to content

lucastorri/query-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Query Parser

An antlr4-based parser for a query syntax similar to Github's advanced search.

When running index.js, input can be passed in the following ways:

  • arguments
  • stdin
  • file, with -i

For instance:

./index.js 'key:value'

echo 'key:value' | ./index.js

./index.js -i <(echo 'key:value')

Syntax

Keys and values are separated by :. Keys cannot have spaces or be quoted. Values can either follow the same formats as keys, or be quoted and be JSON strings.

For example, the following file:

hi
"hi there"
hello:world
hello:"brave new world"

Will produce this output:

┌───────┬─────────────────┐
│ Key   │ Value           │
├───────┼─────────────────┤
│       │ hi              │
├───────┼─────────────────┤
│       │ hi there        │
├───────┼─────────────────┤
│ hello │ world           │
├───────┼─────────────────┤
│ hello │ brave new world │
└───────┴─────────────────┘

Test

npm test

Generate Grammar Code

antlr4 -Dlanguage=JavaScript -o lib antlr4/Query.g4

About

parse advanced search queries using antlr4

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published