You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
highlevel_action_parser does not parse # properly #296
importpyparsingasppfromtypingimportAnyfrombrowsergym.core.action.parsersimporthighlevel_action_parser, NamedArgumenthighlevel_code='send_msg_to_user("Personalization is a powerful driver of sales in the retail industry, especially for regional players like Lee\'s Market that serve diverse and culturally \\"specific\\" communities. Here’s how personalization can drive sales and actionable strategies tailored for Lee’s Market:\n\n## How Personalization Drives Sales in Retail\n")'print("highlevel (original):", highlevel_action_parser.search_string(highlevel_code))
changed the title [-]`highlevel_action_parser` does not parse \' and \" properly[/-][+]`highlevel_action_parser` does not parse # properly[/+]on Sep 16, 2025
importastimportpyparsingasppfromdataclassesimportdataclassfromtypingimportAnyfrombrowsergym.core.action.parsersimporthighlevel_action_parserhighlevel_code='send_msg_to_user("Personalization is a powerful driver of sales in the retail industry, especially for regional players like Lee\'s Market that serve diverse and culturally \\"specific\\" communities. Here’s how personalization can drive sales and actionable strategies tailored for Lee’s Market:\n\n## How Personalization Drives Sales in Retail\n")'print("highlevel (original):", highlevel_action_parser.search_string(highlevel_code))
@dataclassclassNamedArgument:
name: strvalue: Anydef__repr__(self):
returnf"{self.name}={repr(self.value)}"def_build_highlevel_action_parser_fixed() ->pp.ParserElement:
defmake_keyword(kwd_str, kwd_value):
returnpp.Keyword(kwd_str).set_parse_action(pp.replace_with(kwd_value))
TRUE=make_keyword("True", True)
FALSE=make_keyword("False", False)
NONE=make_keyword("None", None)
LBRACK, RBRACK, LBRACE, RBRACE, LPAREN, RPAREN, COLON=map(pp.Suppress, "[]{}():")
# strings: support multiline contents inside quotes (messages often span lines)string= (
pp.QuotedString('"', escChar='\\', unquoteResults=True, multiline=True)
|pp.QuotedString("'", escChar='\\', unquoteResults=True, multiline=True)
)
# numbers and other python-like literalsnumber=pp.pyparsing_common.number()
dict_=pp.Forward().set_name("dict")
list_=pp.Forward().set_name("list")
_tuple=pp.Forward().set_name("tuple")
element= (string|number|dict_|list_|_tuple|TRUE|FALSE|NONE).set_name("element")
list_items=pp.DelimitedList(element, allow_trailing_delim=True).set_name(None)
list_<<pp.Group(LBRACK+pp.Optional(list_items) +RBRACK, aslist=True)
_tuple<<pp.Group(LPAREN+pp.Optional(list_items) +RPAREN, aslist=True).set_parse_action(
lambdatokens: tuple(tokens[0])
)
dict_item=pp.Group(string+COLON+element, aslist=True).set_name("dict item")
dict_items=pp.DelimitedList(dict_item, allow_trailing_delim=True).set_name(None)
dict_<<pp.Dict(LBRACE+pp.Optional(dict_items) +RBRACE, asdict=True)
# named arg -> NamedArgument; use Suppress on '=' so token list is stablenamed_arg= (pp.pyparsing_common.identifier() +pp.Suppress(pp.Literal("=")) +element).set_parse_action(
lambdatokens: NamedArgument(name=tokens[0], value=tokens[1])
)
arg_item=named_arg|elementargs=pp.Optional(pp.DelimitedList(arg_item, allow_trailing_delim=True)).set_name("args")
# function call: group name and a grouped args-listfunction_call=pp.Group(pp.pyparsing_common.identifier("fname") +pp.Group(LPAREN+args+RPAREN)("args_grp"))
# accept one or more function callsmultiple_function_calls=pp.OneOrMore(function_call)
multiple_function_calls.ignore(pp.python_style_comment())
returnmultiple_function_calls# this one will be used to extract python-like function callshighlevel_action_parser_fixed: pp.ParserElement=_build_highlevel_action_parser_fixed()
print("highlevel (fixed):", highlevel_action_parser_fixed.search_string(highlevel_code))
Results:
highlevel (original): []
highlevel (fixed): [[['send_msg_to_user', ['Personalization is a powerful driver of sales in the retail industry, especially for regional players like Lee\'s Market that serve diverse and culturally "specific" communities. Here’s how personalization can drive sales and actionable strategies tailored for Lee’s Market:\n\n## How Personalization Drives Sales in Retail\n']]]]
Hi @xhluca@amanjaiswal73892 , I'd like to pick this up since the fix is already written and verified, I'll write the unit test covering the repro case (the # and escaped-quote parsing in multiline strings) and open a PR with the fix + test together. Will reference this issue in the PR.
I've opened a PR with the fix + regression test: ServiceNow/BrowserGym#394. Since highlevel_action_parser is defined in BrowserGym, I filed it there. Used @xhluca suggested approach (explicit QuotedString variants handling multiline, #, and escaped quotes) and added the unit test @amanjaiswal73892 requested.
Activity
[-]`highlevel_action_parser` does not parse \' and \" properly[/-][+]`highlevel_action_parser` does not parse # properly[/+]xhluca commentedon Sep 16, 2025
Here's a fix:
Results:
amanjaiswal73892 commentedon Oct 2, 2025
Hey! @xhluca, Thank you for reporting this. It would be great if you can make a simple unit test for this.
xhluca commentedon Oct 2, 2025
@amanjaiswal73892 i'm quite busy until end of november, happy to revisit this later
shreyas1903 commentedon Jun 30, 2026
Hi @xhluca @amanjaiswal73892 , I'd like to pick this up since the fix is already written and verified, I'll write the unit test covering the repro case (the # and escaped-quote parsing in multiline strings) and open a PR with the fix + test together. Will reference this issue in the PR.
fix(core): parse strings with # and escaped quotes in highlevel_actio…
shreyas1903 commentedon Jul 8, 2026
I've opened a PR with the fix + regression test: ServiceNow/BrowserGym#394. Since highlevel_action_parser is defined in BrowserGym, I filed it there. Used @xhluca suggested approach (explicit QuotedString variants handling multiline, #, and escaped quotes) and added the unit test @amanjaiswal73892 requested.