Comments (5)
Cool! Confirming the fix! Thanks much.
from lark.
Hi Gerases,
You are not doing anything wrong! Thanks to your simple example, I fixed a long-standing bug related to %ignore.
Check out the latest master
branch and let me know if it works.
( using %ignore /^#.*$/m
should work just fine as well )
from lark.
I think something got broken with the fix though.
Because of the amount of the input it's hard to pinpoint what exactly is happening but the symptom is that what is a Cmnd_Alias in the file somehow became a host alias. I would need to reduce the input data to an absolute minimum to see exactly what is happening but what is definitely helping is going back to the previous commit :(
from lark.
After quite a bit of reducing, I've established the minimum input to trigger the issue:
Cmnd_Alias C_AL1 = CMD1, \
CMD2
#COMMENT1
Cmnd_Alias C_AL2 = CMD3
# ======> BLAH
# COMMENT2
Host_Alias H_AL = SOME_HOSTS
User_Alias U_AL = me, you, him
Removing the last line, for example, hides the issue. And the issue is that C_AL2
starts being part of the user_spec
rule instead of a Command_Alias
. Removing one of the comment lines also fixes the issue. Here's the grammar for reference one more time:
sudo_parser = Lark(r"""
sudo_item : (alias | user_spec)*
alias : "User_Alias" user_alias (":" user_alias)*
| "Runas_Alias" runas_alias (":" runas_alias)*
| "Host_Alias" host_alias (":" host_alias)*
| "Cmnd_Alias" cmnd_alias (":" cmnd_alias)*
user_alias : ALIAS_NAME "=" user_list
host_alias : ALIAS_NAME "=" host_list
runas_alias : ALIAS_NAME "=" runas_list
cmnd_alias : ALIAS_NAME "=" cmnd_list
user_spec : user_list host_list "=" cmnd_spec_list (":" host_list "=" cmnd_spec_list)*
cmnd_spec_list : cmnd_spec ("," cmnd_spec)*
cmnd_spec : runas_spec? tag_spec? negator? command
runas_spec : "(" runas_list? (":" runas_list)? ")"
tag_spec : (tag_nopwd
| tag_pwd
| tag_noexec
| tag_exec
| tag_setenv
| tag_nosetenv
| tag_log_output
| tag_nolog_output) ":"
?command : command_name | cmnd_alias_name
command_name : all | file_name (args)*
all : "ALL"
file_name : FILENAME
args : (arg)* | star | no_arg_string
arg : ARG
star : "*"
no_arg_string : "\"\""
negator : NEGATOR
cmnd_alias_name : ALIAS_NAME
host_list : host ("," host)*
user_list : user ("," user)*
runas_list : user ("," user)*
cmnd_list : command ("," command)*
host : HOST_NAME
user : "!"* USER_NAME
| "!"* "%" GROUP_NAME
| "!"* "#" UID
| "!"* "%#" GID
| "!"* "+" NETGROUP_NAME
| "!"* "%:" NONUNIX_GROUP_NAME
| "!"* "%:#" NONUNIX_GID
| "!"* user_alias
tag_pwd : "PASSWD"
tag_nopwd : "NOPASSWD"
tag_exec : "EXEC"
tag_noexec : "NOEXEC"
tag_setenv : "SETENV"
tag_nosetenv : "NOSETENV"
tag_log_output : "LOG_OUTPUT"
tag_nolog_output : "NOLOG_OUTPUT"
NEGATOR : "!"
UID : /[0-9]+/
GID : /[0-9]+/
NONUNIX_GID : /[0-9]+/
USER_NAME : /[-_.a-z0-9A-Z]+/
GROUP_NAME : CNAME
NETGROUP_NAME : CNAME
NONUNIX_GROUP_NAME : CNAME
ALIAS_NAME : CNAME
HOST_NAME : /[-_.a-z0-9A-Z\[\]*]+/
FILENAME : /\/[-._a-zA-Z0-9\/]+/
ARG : /[-{}\\\\:@;_.\/a-zA-Z0-9]+/
%import common.CNAME
%import common.WS
%ignore /[\\\\]$/m
%ignore /^#.*$/m
%ignore /^Defaults.*$/m
%ignore WS
""", start='sudo_item')
from lark.
When I run it, it seems just fine.
If you're encountering a problem, it's probably because your grammar is ambiguous (it can be parsed in more than one correct way), and the latest commit has shifted the default interpretation.
Try instanciating Lark with Lark(..., ambiguity='explicit')
to see all the possible interpretations. If one of them is incorrect (or undesirable), you have two options:
- Correct the grammar to allow only the desirable interpretation (the recommended way)
- Get the full tree, and choose the correct one yourself.
Let me know if this helps.
from lark.
Related Issues (20)
- Please remove the duplicate PYPI record HOT 1
- Transformer raises AttributeError when a tree is only a token HOT 1
- Import lark grammar written in one python project into another HOT 2
- Need help figuring out why some characters are captured in __ANON_ HOT 2
- Need help with terminals not showing up as expected
- Transforming tree after standalone parser results in different AST HOT 4
- Making a comment by using regular expression HOT 5
- earley very, very slow HOT 24
- Cant read `meta` from Tree or Token? HOT 5
- How to define lark grammar for best parsing performance HOT 8
- Unable to parse Arabic text HOT 3
- Incorrect start_pos / end_pos in the tree HOT 8
- Add `outlines` in the list of projects using Lark HOT 2
- Lark.open_from_package() does not support namespace packages HOT 2
- Stand-alone program cannot be run HOT 4
- Issue of installing lark in Python HOT 1
- Pipe in terminal regex not working as expected HOT 1
- Transformer Not Applying Expected Transformations in Lark Parser HOT 3
- Deprecation Warning HOT 6
- accepts() vs choices() in InteractiveParser HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lark.