wireshark/epan/dfilter
João Valverde 6d520addd1 dfilter: Add special syntax for literals and names
The syntax for protocols and some literals like numbers
and bytes/addresses can be  ambiguous. Some protocols can
be parsed as a literal, for example the protocol "fc"
(Fibre Channel) can be parsed as 0xFC.

If a numeric protocol is registered that will also take
precedence over any literal, according to the current
rules, thereby breaking numerical comparisons to that
number. The same for an hypothetical protocol named "true",
etc.

To allow the user to disambiguate this meaning introduce
new syntax.

Any value prefixed with ':' or enclosed in <,> will be treated
as a literal value only. The value :fc or <fc> will always
mean 0xFC, under any context. Never a protocol whose filter
name is "fc".

Likewise any value prefixed with a dot will always be parsed
as an identifier (protocol or protocol field) in the language.
Never any literal value parsed from the token "fc".

This allows the user to be explicit about the meaning,
and between the two explicit methods plus the ambiguous one
it doesn't completely break any one meaning.

The difference can be seen in the following two programs:

    Filter: frame == fc

    Constants:

    Instructions:
    00000 READ_TREE		frame -> reg#0
    00001 IF-FALSE-GOTO	5
    00002 READ_TREE		fc -> reg#1
    00003 IF-FALSE-GOTO	5
    00004 ANY_EQ		reg#0 == reg#1
    00005 RETURN

    --------

    Filter: frame == :fc

    Constants:
    00000 PUT_FVALUE	fc <FT_PROTOCOL> -> reg#1

    Instructions:
    00000 READ_TREE		frame -> reg#0
    00001 IF-FALSE-GOTO	3
    00002 ANY_EQ		reg#0 == reg#1
    00003 RETURN

The filter "frame == fc" is the same as "filter == .fc",
according to the current heuristic, except the first form
will try to parse it as a literal if the name does not
correspond to any registered protocol.

By treating a leading dot as a name in the language we
necessarily disallow writing floats with a leading dot. We
will also disallow writing with an ending dot when using
unparsed values. This is a backward incompatibility but has
the happy side effect of making the expression {1...2}
unambiguous.

This could either mean "1 .. .2" or "1. .. 2". If we require
a leading and ending digit then the meaning is clear:
    1.0..0.2 -> 1.0 .. 0.2

Fixes #17731.
2022-03-05 11:10:54 +00:00
..
.editorconfig dfilter: Improve grammar to parse ranges 2021-10-08 19:18:56 +01:00
CMakeLists.txt dfilter: Improve grammar to parse ranges 2021-10-08 19:18:56 +01:00
dfilter-int.h dfilter: Add special syntax for literals and names 2022-03-05 11:10:54 +00:00
dfilter-macro.c epan: Convert to use stdio.h from GLib 2021-12-19 19:29:53 +00:00
dfilter-macro.h Add files with WS_DLL_PUBLIC to Doxygen part2 2021-11-30 06:47:35 +00:00
dfilter.c dfilter: Add special syntax for literals and names 2022-03-05 11:10:54 +00:00
dfilter.h Add files with WS_DLL_PUBLIC to Doxygen part2 2021-11-30 06:47:35 +00:00
dfunctions.c ftypes: Internal headers need to be internal 2021-11-11 03:15:31 +00:00
dfunctions.h epan: Add header files to Doxygen 2021-11-30 08:46:49 +00:00
dfvm.c dfilter: Fix dfvm dump display 2022-02-27 19:12:02 +00:00
dfvm.h dfilter: Add an "all equal" operator 2021-12-22 14:32:32 +00:00
drange.c epan: Convert to use stdio.h from GLib 2021-12-19 19:29:53 +00:00
drange.h epan: Convert to use stdio.h from GLib 2021-12-19 19:29:53 +00:00
gencode.c dfilter: Add an "all equal" operator 2021-12-22 14:32:32 +00:00
gencode.h epan: Add header files to Doxygen 2021-11-30 08:46:49 +00:00
grammar.lemon dfilter: Add special syntax for literals and names 2022-03-05 11:10:54 +00:00
scanner.l dfilter: Add special syntax for literals and names 2022-03-05 11:10:54 +00:00
semcheck.c dfilter: Add more debug code 2022-02-27 23:35:57 +00:00
semcheck.h epan: Add header files to Doxygen 2021-11-30 08:46:49 +00:00
sttype-function.c Remove some unnecessary casts. 2021-10-27 10:24:20 +01:00
sttype-function.h epan: Add header files to Doxygen 2021-11-30 08:46:49 +00:00
sttype-pointer.c epan: Convert to use stdio.h from GLib 2021-12-19 19:29:53 +00:00
sttype-range.c epan: Convert to use stdio.h from GLib 2021-12-19 19:29:53 +00:00
sttype-range.h epan: Add header files to Doxygen 2021-11-30 08:46:49 +00:00
sttype-set.c Remove some unnecessary casts. 2021-10-27 10:24:20 +01:00
sttype-set.h epan: Add header files to Doxygen 2021-11-30 08:46:49 +00:00
sttype-string.c dfilter: Parse character constants in lexer 2021-11-24 08:40:20 +00:00
sttype-test.c dfilter: Add an "all equal" operator 2021-12-22 14:32:32 +00:00
sttype-test.h dfilter: Save lexical token value to syntax tree 2021-12-01 13:34:01 +00:00
syntax-tree.c dfilter: Add special syntax for literals and names 2022-03-05 11:10:54 +00:00
syntax-tree.h dfilter: Add more debug code 2022-02-27 23:35:57 +00:00