Skip to content

egberts/nft-token-first

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is about the Netfilter nft CLI terminal app.

Given a token, list all the next valid tokens at the NFT command prompt, given a certain point in the syntax tree.

For example, Bison input symbol would produce the following token:

    'include'
    'undefine'
    'error'
    'define'
    'redefine'
    '\n'
    ';'
    'add'
    'table'
    'chain'
    'rule'
    <identifier>
    'last'
    'ip'
    'ip6'
    'inet'
    'netdev'
    'bridge'
    'arp'
    'accept'
    'drop'
    'continue'
    'jump'
    'goto'
    'return'
    'limit'
    'secmark'
    'synproxy'
    'replace'
    'create'
    'insert'
    'delete'
    'get'
    'list'
    'reset'
    'flush'
    'rename'
    'import'
    'export'
    'monitor'
    'describe'
    'destroy'

dhcparser_nexus/dhparse-working.py is that starting Python point.

Changing the variable 'vim_syntax_group_name_target' gets you your different objective.

WHY

I needed to study autocompletion of Netfilter 'nft' CLI tool, which is not much (at the moment).

HOW

In Netfilter NFT CLI parse table, there are over 1,400 edge-state transitions. It makes zero sense to code that up manually.

I leveraged Bison tool into reading Netfilter nftables' and outputting a rudimentary EBNF (Extended Backus-Naur Form) syntax.

And used a two-stage parser.

MORE DEETS

I designed a two-stage parser:

  1. how to read EBNF (in DHParse-format)
  2. how to read Netfilter nft CLI (in EBNF-format)

For the first-stage, I leveraged DHParser, a PEG parser to read a parser file.

I used a EBNF syntax file that enables reading of any EBNF file (a file that describes EBNF, ... in EBNF): That file format is for DHParse-only.

For the second-stage, I shoehorned Netfilter NFT CLI EBNF ... AGAIN ... thru the Python DHParser("EBNF") but this time using Netfilter NFT EBNF (supplied by Bison and bison_parse.y source file).

Then I wrote a leaf-tree navigator to look for only the first following token(s) (and not to go down any deeper).

OTHERS

dhparser_project subdirectory and its development files were made by executing:

~/work/github/DHParser/scripts/dhparser.py
# and selecting option 1 to create a project and entering in `dhparser_project` 

About

Show what the next tokens are from anywhere in the Netfilter NFT CLI syntax tree

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published