Skip to content

C# demo project for how to use parsers generated by the parol parser generator in C#

Notifications You must be signed in to change notification settings

jsinger67/FilterQueryDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FilterQueryDemo

Small C# demo project for the second video example.

Who this is for: developers who want a compact, practical starting point for using parsers generated by the parol parser generator in C#.

It demonstrates how to parse and evaluate simple human-readable filter expressions (for example status, owner, priority, or score checks) as a foundation for ideas like search filters, rule-based views, and API query conditions.

Build

pwsh

Set-Location "<Path to repository>\FilterQueryDemo"
dotnet build filter_query_demo.csproj  

bash

cd "<Path to repository>/FilterQueryDemo"
dotnet build filter_query_demo.csproj

Demo commands (for recording)

Example 1 (expected: true)

pwsh

Set-Content -Path .\test1.txt -Value 'status = "open" and owner = "sam"'
dotnet run -- .\test1.txt

bash

printf '%s' 'status = "open" and owner = "sam"' > ./test1.txt
dotnet run -- ./test1.txt

Expected output line:

Evaluation result: true

Example 2 (expected: true)

pwsh

Set-Content -Path .\test2.txt -Value 'priority >= 3 or score > 90'
dotnet run -- .\test2.txt

bash

printf '%s' 'priority >= 3 or score > 90' > ./test2.txt
dotnet run -- ./test2.txt

Expected output line:

Evaluation result: true

Example 3 (expected: false)

pwsh

Set-Content -Path .\test3.txt -Value 'not archived and (priority >= 3 or owner = "max")'
dotnet run -- .\test3.txt

bash

printf '%s' 'not archived and (priority >= 3 or owner = "max")' > ./test3.txt
dotnet run -- ./test3.txt

Expected output line:

Evaluation result: false

Notes

  • Parsing is still performed by the generated parol parser.
  • The boolean result is printed by the demo evaluator in FilterQueryEvaluator.cs.
  • The types FilterIdentifier, FilterNumber and FilterString are used to demonstrate the use of the %nt_type directive to provide conversion to user provided types in the generated parser. Please look for these directives in filter_query_demo.par
  • The default evaluation context is defined in filter_query_demo_actions.cs.

Run all demo cases

pwsh

.\run_demo_cases.ps1

bash

bash ./run_demo_cases.sh

Run all demo cases (clean output)

pwsh

.\run_demo_cases_clean.ps1

bash

bash ./run_demo_cases_clean.sh

About

C# demo project for how to use parsers generated by the parol parser generator in C#

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors