Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
66 lines (54 sloc) 2.53 KB
# https://dev.twitter.com/rest/public/search
grammar Query
# Query Shape Rules
# One or more operators makes up a query
root <- __* value:query __* <Value>
query <- (value:operator __*)+ <And>
# There are realy only two kinds of operator: include and exclude
operator <- excluding
/ including
# To exclude, you use a "-" before the query. OR cannot be negated unless it's in a group.
excluding <- "-" value:base <Excluding>
including <- "" value:(or / base) <Including>
# Operators can be grouped with an OR keyword in groups of two or more.
# I'm not sure if this is the ideal way to do this with PEG but it works for now.
or <- value:orable or_groups <Or>
or_groups <- (or_sep value:orable)+ <Values>
orable <- "" value:base <Including>
# The base operators are the things that make up the query itself.
# Filters, hashtags, text etc.
base <- group
/ list
/ url
/ pair
/ exact
/ hashtag
/ mention
/ word
# A group is a complete subquery. Recursion!
group <- "(" root ")" <Group>
# Query Syntax Rules
# These outline the specifics of the syntax
url <- k:slug url_sep v:word <Text>
pair <- k:slug sep v:word <Pair>
list <- "list" sep list_name <List>
exact <- '"' value:([^\"]*) '"' <Exactly>
hashtag <- "#" tag <Text>
cashtag <- "$" tag <Text>
mention <- "" screen_name <Text>
word <- "+"? [^\s\)\(]+ <Text>
# Utility Rules
or_sep <- __+ "OR" __+
list_name <- screen_name "/" list_slug
list_slug <- [a-z-]+
screen_name <- "@"? slug
# There's probably a better way to do this
date <- d d d d "-" d d "-" d d
# This is clearly wrong — needs to account for unicode
tag <- slug
slug <- [a-zA-Z0-9_]+
url_sep <- "://"
sep <- ":"
integer <- d d*
d <- [0-9]
__ <- [\s]