ldsl_grammar's People
ldsl_grammar's Issues
Add indentations to conditions in grammar using Lark
I've written grammar
`grammar = r""" ?start: value
?value: dict
| if
| array
| STRING
| VARIABLE_NAME
| operator
| action_operator
| SIGNED_NUMBER -> number
| "true" -> true
| "false" -> false
| "null" -> null
if: "если" condition "тогда:" suite ("в случае" condition ":" suite)* ["иначе:" else]
condition: variable (action_operator variable)*
variable: VARIABLE_NAME | SIGNED_NUMBER
?simple_stmt: STRING _NEWLINE
?stmt: simple_stmt | if
else: STRING _NEWLINE
suite: simple_stmt | _NEWLINE _INDENT stmt+ _DEDENT
array: "[" [value ("," value)*] "]"
dict: "{" [pair ("," pair)*] "}"
pair: STRING ":" value
?operator: OPERATOR
OPERATOR: "+:"|":"
!action_operator: "<"|">"|"="|"=="|">="|"<="|"!="|"in"
COMMENT: /#[^\n]*/
_NEWLINE: ( /\r?\n[\t ]*/ | COMMENT )+
_INDENT: /[\t]+/
VARIABLE_NAME: /[\wа-яА-Я][\wа-яА-Я0-9_.-]+/
STRING: /[\wа-яА-Я0-9_.-]+/
%import common.ESCAPED_STRING
%import common.SIGNED_NUMBER
%import common.WS
%ignore WS
_DEDENT: "<DEDENT>" """`
and I try to execute next code:
`если x >= 18 тогда:
success
в случае 16 <= x < 18:
если y > 100000 тогда:
get_more_info
иначе: fail`
but it returns
ParseError: Unexpected end of input! Expecting a terminal of: ['_NEWLINE', '_DEDENT', '__ANONSTR_3', '__ANONSTR_3', '__ANONSTR_3', 'STRING', '__ANONSTR_3']
I need to add correct indentations to code to get tree.
how can I fix that to read this text?
@erezsh , can you help with this question?
Add string from DSL like a comment to python code
@erezsh Is any way to add DSL string like a comment to python code?
For example
DSL
Если возраст < 18 то
отказ
Если возраст >= 18 то
Если зарплата > 100000 то
выдать_кредит
Python code
# Если возраст < 18 то
if age < 18:
# отказ
print('refused')
# Если возраст >= 18 то
if age >= 18:
# Если зарплата > 100000 то
if salary > 100000:
# выдать кредит
print('success')`
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.