Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add catch-all for unusable characters #64

Merged
merged 4 commits into from
Mar 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 39 additions & 13 deletions pattern_grammar/STIXPattern.g4
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ startStopQualifier
;

withinQualifier
: WITHIN (IntLiteral|FloatLiteral) SECONDS
: WITHIN (IntPosLiteral|FloatPosLiteral) SECONDS
;

repeatedQualifier
: REPEATS IntLiteral TIMES
: REPEATS IntPosLiteral TIMES
;

objectPath
Expand All @@ -81,7 +81,7 @@ firstPathComponent
objectPathComponent
: <assoc=left> objectPathComponent objectPathComponent # pathStep
| '.' (IdentifierWithoutHyphen | StringLiteral) # keyPathStep
| LBRACK (IntLiteral|ASTERISK) RBRACK # indexPathStep
| LBRACK (IntPosLiteral|IntNegLiteral|ASTERISK) RBRACK # indexPathStep
;

setLiteral
Expand All @@ -95,28 +95,44 @@ primitiveLiteral
;

orderableLiteral
: IntLiteral
| FloatLiteral
: IntPosLiteral
| IntNegLiteral
| FloatPosLiteral
| FloatNegLiteral
| StringLiteral
| BinaryLiteral
| HexLiteral
| TimestampLiteral
;

IntLiteral :
[+-]? ('0' | [1-9] [0-9]*)
IntNegLiteral :
'-' ('0' | [1-7] [0-9]*)
;

FloatLiteral :
[+-]? [0-9]* '.' [0-9]+
IntPosLiteral :
'+'? ('0' | [1-8] [0-9]*)
;

FloatNegLiteral :
'-' [0-9]* '.' [0-9]+
;

FloatPosLiteral :
'+'? [0-9]* '.' [0-9]+
;

HexLiteral :
'h' QUOTE TwoHexDigits* QUOTE
;

BinaryLiteral :
'b' QUOTE Base64Char* QUOTE
'b' QUOTE
( Base64Char Base64Char Base64Char Base64Char )*
( (Base64Char Base64Char Base64Char Base64Char )
| (Base64Char Base64Char Base64Char ) '='
| (Base64Char Base64Char ) '=='
)
QUOTE
;

StringLiteral :
Expand All @@ -129,9 +145,14 @@ BoolLiteral :

TimestampLiteral :
't' QUOTE
[0-9] [0-9] [0-9] [0-9] HYPHEN [0-9] [0-9] HYPHEN [0-9] [0-9]
[0-9] [0-9] [0-9] [0-9] HYPHEN
( ('0' [1-9]) | ('1' [012]) ) HYPHEN
( ('0' [1-9]) | ([12] [0-9]) | ('3' [01]) )
'T'
[0-9] [0-9] COLON [0-9] [0-9] COLON [0-9] [0-9] (DOT [0-9]+)?
( ([01] [0-9]) | ('2' [0-3]) ) COLON
[0-5] [0-9] COLON
([0-5] [0-9] | '60')
(DOT [0-9]+)?
'Z'
QUOTE
;
Expand Down Expand Up @@ -220,7 +241,7 @@ fragment Z: [zZ];

fragment HexDigit: [A-Fa-f0-9];
fragment TwoHexDigits: HexDigit HexDigit;
fragment Base64Char: [A-Za-z0-9+/=];
fragment Base64Char: [A-Za-z0-9+/];

// Whitespace and comments
//
Expand All @@ -234,3 +255,8 @@ COMMENT
LINE_COMMENT
: '//' ~[\r\n]* -> skip
;

// Catch-all to prevent lexer from silently eating unusable characters.
InvalidCharacter
: .
;