RESOStandards / transport

RESO Transport Workgroup - Specifications and Change Proposals
https://transport.reso.org
Other
18 stars 15 forks source link

RCP-019 Grammar fixes/improvements #112

Closed bryanburgers closed 8 months ago

bryanburgers commented 8 months ago

I followed both the quickstart on antlr.org and the online lab.antlr.org to validate the RCP-019 grammar, and I ran into issues.

Is antlr4 the tool that this grammar is supposed to work against?

If so, here's a series of commits that

I ran the new grammar against the following test inputs and it succeeds for all of these (when it previously only succeeded for the first section).

The script I ran to test uses antlr4-parse (I can't figure out how to get the version out of it, but it was pip installed today, so I assume it is a recent version) and is attached at the end of the PR.

# Expressions that succeed without changes

1
1+1
1=1
1>2
1<2
1>=2
1<=2

# Expressions that succeed after minor fixes in the order of the lexer

1 + 1
1 = 1
.TRUE.
.FALSE.
.EMPTY.
.TRUE. .OR. .FALSE.
.TRUE. .AND. .FALSE.
(.TRUE. .OR. .FALSE.)
IIF(ListPrice>2,1,2)
IIF(ListPrice > 2, 1, 2)
MATCH(Status,"Active")
MATCH(Status, "Active")

# Expressions that cause problems when funcExp is an alternative in exp
# because they parse the function and leave the rest of the input

IIF(ListPrice = .EMPTY., 0, ListPrice) = IIF(ListPrice = .EMPTY., 0, ListPrice) + IIF(ListPrice = .EMPTY., 0, ListPrice)
MATCH(Status, "Active") .AND. MATCH(Status, "Active|Closed")

# Expressions that only parse when allowing custom names and functions

CustomName
CustomName + CustomName
CustomNameYN .OR. CustomNameYN
CustomFunc(CustomName)
MLS_CustomField + 7
IIF(ParkingTotal = .EMPTY., 0, ParkingTotal)
IIF(ParkingTotal = .EMPTY., 0, ParkingTotal) = IIF(GarageSpaces = .EMPTY., 0, GarageSpaces) + IIF(OpenParkingSpaces = .EMPTY., 0, OpenParkingSpaces)
run-tests.sh ```sh #!/bin/bash while read line; do if [[ $line == "#"* ]]; then # if the line begins with a comment, then output # the comment with some fancy formatting. echo -e "\e[1;4m$line\e[0m" continue; fi if [[ -z $line ]]; then # if the line is empty, don't try to parse it. echo; continue; fi # OK, we have a line that we want to parse. # There are hacky ways to get the stdout and stderr into two separate # variables. But instead of hacky, we'll just run the parser twice. 🤷 stdout=$(echo $line | antlr4-parse rcp019.g4 rcp019Lexer.g4 topExp -tree 2>/dev/null) stderr=$(echo $line | antlr4-parse rcp019.g4 rcp019Lexer.g4 topExp -tree 2>&1 1>/dev/null) if [[ -z $stderr ]]; then # The parser didn't return any errors echo -e "\e[30;42m OK \e[0m $line" echo -e "\e[2m$stdout\e[0m" else # The parser DID return errors echo -e "\e[30;41m NOK \e[0m $line" echo -e "\e[2m$stdout\e[0m" echo -e "\e[31m$stderr\e[0m" fi done
darnjo commented 8 months ago

Thanks, Bryan. I'll take a look. I haven't validated the new grammars yet - I think the original should still work? Did you check that as well.

I will be writing tests as well as GitHub actions to run the tests on PR as part of the work with RCP-019. I'll follow up on this ticket once that's complete.

darnjo commented 8 months ago

Closed. Changes no longer valid.