Skip to content

v2.0.0 - bug fixes and core/udl/expr improvements - #64

Merged
hkimura-intersys merged 9 commits into
intersystems:mainfrom
hkimura-intersys:v2.0.0-updates
Nov 25, 2026
Merged

hkimura-intersys merged 9 commits into
intersystems:mainfrom
hkimura-intersys:v2.0.0-updates

Conversation

@hkimura-intersys

Copy link
Copy Markdown
Member

This PR includes major changes to the core/expr/udl grammar and scanners. Many of these changes alter the shape of the resulting trees, and the query files have been updated to support the new tree shapes. I will detail each change below. Many of these changes address bugs that were found when parsing over 18,000 HealthShare and SYS classes. The biggest changes have to do with how macros/preprocessors are parsed and how the language of a class member body is determined. Additionally, these changes decreased the parser.c size for all the grammars, and the largest grammar (objectscript playground) is now 38M, which is 11M smaller than the previous version. This speeds up compilation of the grammars significantly.

Core Grammar Changes

  1. #if, #ifdef, and #ifndef nodes now only contain their directive and expression

This is how tags are treated. The code that is associated with these directives should be determined separately. This makes it so an #if within a block (ex: an else block) doesn't break the tree. Before, statements were grouped into a pound_if node until that #if was closed with an #endif or EOF.
Here's an example that highlights how this changes the tree shape.
Before, the statements until the #endif would be children of the first statement node.

Now, they are siblings:
image

Why this change was needed:
It is valid to have nested #if within a block that has a } finished after the block, but before, everything after an #if and before the thing that closes that #if, all those statements had to be parsed as a chunk (so they couldn't be individually queried). One other error was it required an #endif to close, but that isn't required (EOF works to close it too).

OLD VERSION: Here's an example of valid code that failed before :
image
NEW VERSION: This now parses correctly:
image

OLD VERSION: In the case where the #if started in a block, all the info about statements after that was lost as the scanner had to parse it:
image

With the changes, this now parses without losing any info about those statements:
image

  1. ##lit(;) and ##lit(;;) parsing added
image The value after the ##lit(;) is parsed with the scanner. It finishes if it sees a new line or a new ##lit (whichever comes first).
  1. a space between # and dim is allowed
image
  1. an else block is allowed without being a part of an if node IFF it is in an #if, #ifdef, and #ifndef.
    image

  2. allow #endif in between dotted statements
    Before, this would incorrectly break the tree:
    OLD VERSION:

image

With the changes to allow this, the tree is as expected:
image

  1. command_macro now references the _macro node from the expression grammar instead of redefining things

Core Scanner Changes

  1. added handling for parsing regex in javascript : before, something like / was counted when it should have been escaped.
  2. adjusted how html is parsed (a < in a string still counts)
  3. keep track of if we are in a conditional directive at a given spot (#if, #ifdef, and #ifndef). the scanner now holds the number of directives still open.
  4. allow the following syntax if {ROUTINE_TEST} = "SQL" {}

Changes to Macro Processing (this change mainly affects the core and expr grammar)

Before, macro functions were redefined in the core grammar and expr grammar (because the arguments are sometimes statements, which the expr grammar has no knowledge of). This led to errors, because when a macro was used as an expression, it didn't have access to that syntax. Additionally, sometimes macro definitions contain an extra ), and the scanner now accounts for some of these cases. These changes required adding a scanner to expr, and using that to parse the arguments (as if they were an external language). See common/expr-scanner.h for the actual function that parses this. Now, here are a few examples of things that parse that before caused failures:
image
image

Expr Additional Grammar Changes

  1. allowed class refs shaped like: ##class({%%CLASSNAME}).getName({ID})
  2. allow ^ followed by a macro function

Udl Grammar Changes

  1. added SoapTypeNameSpace keyword
  2. allow compileafter = with nothing after the =
  3. allow expression method to be empty (for parsing deployed classes)
  4. allow string literals for sql name and sql table name keywords
  5. added enumedit keyword for property flags
  6. added byval keyword for methods
  7. added vector and POSIXTS as a possibility for sqlcategory
  8. added guid as a possibility for odbc type
  9. added mvdate as a possibility for clientdatatype
  10. added mvbasic as a possible language for methods
  11. added nocontext keyword to methods and classes
  12. allow numbers for constraint keyword
  13. extends allows a comma before a class name ex: Extends (, Hi)
  14. removed all grammar conflicts, since the scanner now handles figuring out what language a method/trigger body is.

Udl Scanner Change: Determining a Class Member Body Language

In ObjectScript, if a class declares Language = Tsql, the methods are this language by default, and can only differ if they themselves specify a different language. Before, the languages of a method (or trigger) were determined by keywords. If the Language keyword was set to something other than objectscript, that method was external, otherwise it was an objectscript method. This method would wrongfully classify the method as objectscript in the scenario where the class sets language to tsql and the method specifies nothing. To fix this, I use the scanner to store what the class state is (external or regular). Then, for each method, if a keyword that affects the method type (call, expression, external, or core) is specified, that triggers the scanner to set curr_method_kind to that type. The scanner returns specific tokens (or lack of) for each method type, and that determines what body the method should have. At the end of the method, the curr_method_kind is reset to core (the default objectscript method).

Testing

These changes were tested on over 18,000 healthshare/SYS classes, and on the SYS .inc and .int files.
image
image

udl grammar changes:
- added SoapTypeNameSpace keyword
- allow compileafter = with nothing after the =
- allow expression method to be empty (for parsing deployed classes)
- allow string literals for sql name and sql table name keywords
- added enumedit keyword for property flags
- added byval keyword for methods
- added vector and POSIXTS as a possibility for sqlcategory
- added guid as a possibility for odbc type
- added mvdate as a possibility for clientdatatype
- added mvbasic as a possible language for methods
- added nocontext keyword to methods and classes
- allow numbers for constraint keyword
- extends allows a comma before a class name ex: Extends (, Hi)
- removed all grammar conflicts, since the scanner now handles figuring out what language a method/trigger body is.
- decreased the parser.c size from 47M to 36M!

udl scanner changes:
- I now determine the language of a class member body (trigger or method) entirely using the scanner
- I persist the declared class language (default = objectscript), and if it is set and not specified in the
  method, then the method gets that language.

These changes also effect the shape of the udl tree, and the query files have been updated to show this change.
expr grammar changes:
- the arguments within a macro function are now parsed with the scanner. these arguments can sometimes contain incomplete
  code or statements, so the scanner is needed to determine when it is complete.
- allowed class refs shaped like: ##class({%%CLASSNAME}).getName({ID})
- allow ^ followed by a macro function

expr scanner:
the expr scanner is extended by the core scanner. it is used to scan macro functions. this is needed
because macro functions are valid expressions, but the expr grammar is not yet aware of statements (which
get defined in the core grammar). Additionally, incomplete expressions or statements are allowed as arguments
because it is really just code that gets pasted into a specific section (and once pasted it isn't incomplete
anymore).
core grammar changes:
- #if, #ifdef, and #ifndef nodes only contain their directive and expression.
  this is how tags are treated. the code that is associated with these directives
  should be determined separately. this makes it so an #if within a block (ex: an else block)
  doesn't break the tree.
- ##lit(;) and ##lit(;;) parsing added
- # dim allowed (the space between # and d)
- an else block is allowed without being a part of an if node IFF it is in an #if, #ifdef, and #ifndef.
- allow #endif in between dotted statements

scanner changes:
- added handling for parsing regex in javascript
- adjusted how html is parsed (a < in a string still counts)
- keep track of if we are in a conditional directive at a given spot (#if, #ifdef, and #ifndef)
- allow the follow syntax if {ROUTINE_TEST} = "SQL" {}
- command_macro now references the _macro node from the expression grammar instead of redefining things
@hkimura-intersys
hkimura-intersys merged commit 601a19d into intersystems:main Nov 25, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant