Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line breaks shouldn't fail parsing #197

Closed
mttrbrts opened this issue Sep 2, 2018 · 3 comments
Closed

Line breaks shouldn't fail parsing #197

mttrbrts opened this issue Sep 2, 2018 · 3 comments

Comments

@mttrbrts
Copy link
Member

mttrbrts commented Sep 2, 2018

As per a thread in the AP #technology-wg channel. It is confusing to users who edit files with editors that automatically change the line break format.

The behaviour can be replicated by opening the helloworld sample.txt file in VSCode, and changing the line break format from LF to CRLF and saving.

Parsing the original sample works, parsing the changed sample fails with:

mattmbp:helloworld matt$ cicero parse
14:09:32 - info: Using current directory as template folder
14:09:32 - info: Loading a default sample.txt file.
14:09:33 - error: invalid syntax at line 1 col 43:

  Name of the person to greet: "Fred Blogs".
                                            ^
Unexpected "\r"

Error: invalid syntax at line 1 col 43:

  Name of the person to greet: "Fred Blogs".
                                            ^
Unexpected "\r"

    at Parser.feed (/Users/matt/.nvm/versions/node/v8.11.1/lib/node_modules/@accordproject/cicero-cli/node_modules/nearley/lib/nearley.js:317:27)
    at Clause.parse (/Users/matt/.nvm/versions/node/v8.11.1/lib/node_modules/@accordproject/cicero-cli/node_modules/@accordproject/cicero-core/lib/templateinstance.js:97:16)
    at Template.fromDirectory.then (/Users/matt/.nvm/versions/node/v8.11.1/lib/node_modules/@accordproject/cicero-cli/lib/commands.js:54:24)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
14:09:33 - info: undefined

@jeromesimeon
Copy link
Member

Fixed in Cicero 0.13.5

@lamqson
Copy link

lamqson commented Oct 27, 2019

I just tried it on 0.13.5. It still broken:

Sons-MacBook-Pro:cicero sonlam$ cat sample.txt
Name of the person to greet: "Fred Blogs".
Thank you!
Sons-MacBook-Pro:cicero sonlam$ cicero --version
0.13.5
Sons-MacBook-Pro:cicero sonlam$ cicero parse --template [email protected] --sample sample.txt
4:53:46 PM - error: invalid syntax at line 3 col 0:

  
  ^
Unexpected "\n"

Sons-MacBook-Pro:cicero sonlam$

@jeromesimeon
Copy link
Member

jeromesimeon commented Oct 28, 2019

@lamqson See my answer to that same comment in #219

You most likely have an extra new line at the end of your sample (some editors add new lines on save, so you may want to check the configuration for your editor as well).

bash-3.2$ cicero --version
0.13.5
bash-3.2$ cat sample.txt 
Name of the person to greet: "Fred Blogs".
Thank you!bash-3.2$ cicero parse
10:03:34 - info: Using current directory as template folder
10:03:34 - info: Loading a default sample.txt file.
10:03:36 - info:
{
  "$class": "org.accordproject.helloworld.HelloWorldClause",
  "clauseId": "e5347c29-72b0-4b6d-a67d-530b715a7026",
  "name": "Fred Blogs"
}
bash-3.2$ 

Note there is no new line after the Thank you!:

bash-3.2$ cat sample.txt 
Name of the person to greet: "Fred Blogs".
Thank you!bash-3.2$
^^^^^^^^^^^^^^^^^^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants