Grammar¶
This page is generated from the PhiSQL spec artifacts for v1.0. Do not edit it by hand; change the artifact and rebuild.
PhiSQL's grammar is defined in two equivalent forms. The ANTLR4 grammar is the executable normative reference that the reference implementation generates its parser from. The ISO 14977 EBNF below is a tool-independent presentation, cross-validated against the ANTLR4 grammar.
Keywords and entity-type identifiers are case-insensitive. User-defined names (policy names, dictionary names, custom-identifier classifications) are case-sensitive.
Production rules¶
| Rule | Defined in |
|---|---|
document |
EBNF |
statement |
EBNF |
policy decl |
EBNF |
configure stmt |
EBNF |
setting list |
EBNF |
setting |
EBNF |
setting key |
EBNF |
setting value |
EBNF |
object value |
EBNF |
array value |
EBNF |
options clause |
EBNF |
redact stmt |
EBNF |
deidentify stmt |
EBNF |
entity assignment |
EBNF |
ignore stmt |
EBNF |
define identifier stmt |
EBNF |
define dictionary stmt |
EBNF |
define section stmt |
EBNF |
detect stmt |
EBNF |
discovery stmt |
EBNF |
in clause |
EBNF |
where discovery |
EBNF |
discovery predicate |
EBNF |
projection list |
EBNF |
projection |
EBNF |
aggregate |
EBNF |
column ref |
EBNF |
findings ref |
EBNF |
group by clause |
EBNF |
limit clause |
EBNF |
entity list |
EBNF |
entity type |
EBNF |
strategy expr |
EBNF |
strategy name |
EBNF |
strategy args |
EBNF |
named arg |
EBNF |
predicate |
EBNF |
confidence predicate |
EBNF |
compare op |
EBNF |
string list |
EBNF |
literal |
EBNF |
id |
EBNF |
string literal |
EBNF |
string char |
EBNF |
string escape |
EBNF |
numeric literal |
EBNF |
boolean literal |
EBNF |
letter |
EBNF |
digit |
EBNF |
line comment |
EBNF |
block comment |
EBNF |
whitespace |
EBNF |
Full grammar¶
document¶
statement¶
statement = policy decl
| configure stmt
| redact stmt
| deidentify stmt
| ignore stmt
| define identifier stmt
| define dictionary stmt
| define section stmt
| detect stmt
| discovery stmt ;
policy decl¶
configure stmt¶
configure stmt = "CONFIGURE"
, ( "CRYPTO" , "KEY" , "FROM" , "ENV" , string literal
| "FPE" , "KEY" , "FROM" , "ENV" , string literal
, "TWEAK" , "FROM" , "ENV" , string literal
| ( "SPLITTING" | "PDF" | "POSTFILTERS" | "ANALYSIS" )
, "(" , setting list , ")"
| "GRAPHICAL" , "BOX" , "(" , setting list , ")" ) ;
setting list¶
setting¶
setting key¶
setting value¶
object value¶
array value¶
options clause¶
redact stmt¶
redact stmt = "REDACT" , entity list
, [ "WITH" , strategy expr ]
, [ "WHERE" , predicate ]
, [ options clause ] ;
deidentify stmt¶
entity assignment¶
ignore stmt¶
ignore stmt = "IGNORE"
, ( "TERMS" , string list
| "PATTERN" , string literal )
, [ "FOR" , entity list ]
, [ options clause ] ;
define identifier stmt¶
define identifier stmt
= "DEFINE" , "IDENTIFIER" , string literal
, "MATCHING" , string literal
, [ "GROUP" , numeric literal ]
, [ "CASE" , ( "SENSITIVE" | "INSENSITIVE" ) ]
, "WITH" , strategy expr
, [ "WHERE" , predicate ]
, [ options clause ] ;
define dictionary stmt¶
define dictionary stmt
= "DEFINE" , "DICTIONARY" , string literal
, "TERMS" , string list
, [ "FUZZY" , [ "SENSITIVITY" , id ] ]
, [ "CAPITALIZED" ]
, "WITH" , strategy expr
, [ options clause ] ;
define section stmt¶
define section stmt
= "DEFINE" , "SECTION"
, "START" , string literal
, "END" , string literal
, "WITH" , strategy expr
, [ options clause ] ;
detect stmt¶
detect stmt = "DETECT" , "PHEYE"
, [ "LABELS" , string list ]
, [ "ENDPOINT" , string literal ]
, [ "MODEL" , string literal ]
, "WITH" , strategy expr
, [ "WHERE" , predicate ]
, [ options clause ] ;
discovery stmt¶
discovery stmt = ( "FIND" , "PII" , in clause , [ where discovery ] )
| ( "DISCOVER" , "ENTITIES" , in clause , [ where discovery ] )
| ( "SCAN" , in clause , [ where discovery ] )
| ( "SELECT" , projection list , "FROM" , findings ref
, [ where discovery ]
, [ group by clause ]
, [ limit clause ] ) ;
in clause¶
where discovery¶
discovery predicate¶
discovery predicate
= ( column ref , "IN" , string list )
| ( column ref , compare op , ( string literal | numeric literal | boolean literal ) )
| ( "(" , discovery predicate , ")" )
| ( discovery predicate , ( "AND" | "OR" ) , discovery predicate ) ;
projection list¶
projection¶
aggregate¶
column ref¶
findings ref¶
group by clause¶
limit clause¶
entity list¶
entity type¶
strategy expr¶
strategy name¶
strategy name = "MASK"
| "REDACT"
| "ENCRYPT"
| "FPE_ENCRYPT"
| "HASH_SHA256"
| "RANDOM_REPLACE"
| "STATIC_REPLACE"
| "LAST_4"
| "TRUNCATE"
| "TRUNCATE_TO_YEAR"
| "SHIFT"
| "RELATIVE"
| "ABBREVIATE" ;
strategy args¶
named arg¶
predicate¶
predicate = confidence predicate
| "(" , predicate , ")"
| predicate , ( "AND" | "OR" ) , predicate ;
confidence predicate¶
compare op¶
string list¶
literal¶
id¶
string literal¶
string char¶
string escape¶
numeric literal¶
boolean literal¶
letter¶
letter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J"
| "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T"
| "U" | "V" | "W" | "X" | "Y" | "Z"
| "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j"
| "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t"
| "u" | "v" | "w" | "x" | "y" | "z"
| "_" ;