sqlish.pegjs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. Expression
  2. = tokens:Token*
  3. Token
  4. = Whitespace / Keyword / Parameter / CollapsedColumns / GenericToken
  5. Keyword
  6. = Keyword:("SELECT"i / "INSERT"i / "DELETE"i / "FROM"i / "ON"i / "WHERE"i / "AND"i / "ORDER BY"i / "LIMIT"i / "GROUP BY"i / "OFFSET"i / "VALUES"i / "RETURNING"i / JoinKeyword) {
  7. return { type: 'Keyword', content: Keyword }
  8. }
  9. JoinKeyword
  10. = JoinDirection:JoinDirection? Whitespace? JoinType:JoinType? Whitespace "JOIN"i {
  11. return (JoinDirection || '') + (JoinDirection ? " " : '') + JoinType + " " + "JOIN"
  12. }
  13. JoinDirection
  14. = "LEFT"i / "RIGHT"i / "FULL"i
  15. JoinType
  16. = "OUTER"i / "INNER"i
  17. Parameter
  18. = Parameter:("%s" / ":c" [0-9]) { return { type: 'Parameter', content: Array.isArray(Parameter) ? Parameter.join('') : Parameter } }
  19. CollapsedColumns
  20. = ".." { return { type: 'CollapsedColumns', content: '..' } }
  21. Whitespace
  22. = Whitespace:[\n\t ]+ { return { type: 'Whitespace', content: Whitespace.join("") } }
  23. GenericToken
  24. = GenericToken:[a-zA-Z0-9"'`_\-.()=><:,*;!\[\]?$%|/]+ { return { type: 'GenericToken', content: GenericToken.join('') } }