Skip to content

Commit

Permalink
sway-parse initial PR (FuelLabs#1286)
Browse files Browse the repository at this point in the history
* remove pest::Span from sway_types::Span

* Add new parser implementation

* use new parser in sway-core

* Proper error handling in convert_parse_tree

* rename new-parser-again to sway-parse

* remove redundant test bin from sway-parse

* fix dependencies in sway-parse

* fix clippy lints

* put dependencies in alphabetical order

* run rustfmt

* record full span in TokenStream

* remove an unused function

* alphabetically sort workspace members

* add --use-orig-parser cli option

* rust rustfmt

* update crate metadata for sway-parse

* update forc docs for --use-orig-parser
  • Loading branch information
canndrew authored Apr 21, 2022
1 parent 30e105e commit 6b8a46b
Show file tree
Hide file tree
Showing 113 changed files with 8,466 additions and 1,497 deletions.
336 changes: 154 additions & 182 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ members = [
"forc-lsp",
"forc-pkg",
"forc-util",
"parser",
"scripts/forc-documenter",
"sway-core",
"sway-fmt",
"sway-ir",
"sway-lsp",
"sway-parse",
"sway-types",
"sway-utils",
"test",
"test-sig-gen-util",
"scripts/forc-documenter"
]
exclude = [
"examples/fizzbuzz",
Expand Down
6 changes: 6 additions & 0 deletions docs/src/forc/commands/forc_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ Silent mode. Don't output any warnings or errors to the command line

Whether to compile using the original (pre- IR) pipeline


`--use-orig-parser`


Whether to compile using the original (pest based) parser

## EXAMPLES:

Compile the sway files of the current project.
Expand Down
6 changes: 6 additions & 0 deletions docs/src/forc/commands/forc_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ Silent mode. Don't output any warnings or errors to the command line

Whether to compile using the original (pre- IR) pipeline


`--use-orig-parser`


Whether to compile using the original (pest based) parser

## EXAMPLES:

Deploy contract project. Crafts a contract deployment transaction then sends it to a running node.
Expand Down
8 changes: 7 additions & 1 deletion docs/src/forc/commands/forc_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,10 @@ Silent mode. Don't output any warnings or errors to the command line
`--use-orig-asm`


Whether to compile using the original (pre- IR) pipeline
Whether to compile using the original (pre- IR) pipeline


`--use-orig-parser`


Whether to compile using the original (pest based) parser
2 changes: 2 additions & 0 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ pub struct BuildPlan {
/// Parameters to pass through to the `sway_core::BuildConfig` during compilation.
pub struct BuildConfig {
pub use_orig_asm: bool,
pub use_orig_parser: bool,
pub print_ir: bool,
pub print_finalized_asm: bool,
pub print_intermediate_asm: bool,
Expand Down Expand Up @@ -942,6 +943,7 @@ pub fn sway_build_config(
manifest_dir.to_path_buf(),
)
.use_orig_asm(build_conf.use_orig_asm)
.use_orig_parser(build_conf.use_orig_parser)
.print_finalized_asm(build_conf.print_finalized_asm)
.print_intermediate_asm(build_conf.print_intermediate_asm)
.print_ir(build_conf.print_ir);
Expand Down
8 changes: 4 additions & 4 deletions forc-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ fn println_with_color(txt: &str, color: TermColor, stream: StandardStream) {

fn format_err(err: &sway_core::CompileError) {
let input = err.internal_span().input();
let path = err.path();
let path = err.path_str();

let (mut start_pos, mut end_pos) = err.span();
if start_pos == end_pos {
Expand All @@ -281,7 +281,7 @@ fn format_err(err: &sway_core::CompileError) {
slices: vec![Slice {
source: input,
line_start: start.line,
origin: Some(&path),
origin: path.as_deref(),
fold: false,
annotations: vec![SourceAnnotation {
label: &friendly_str,
Expand All @@ -299,7 +299,7 @@ fn format_err(err: &sway_core::CompileError) {

fn format_warning(err: &sway_core::CompileWarning) {
let input = err.span.input();
let path = err.path();
let path = err.path_str();

let friendly_str = maybe_uwuify(&err.to_friendly_warning_string());
let (mut start_pos, mut end_pos) = err.span();
Expand All @@ -320,7 +320,7 @@ fn format_warning(err: &sway_core::CompileWarning) {
slices: vec![Slice {
source: input,
line_start: start.line,
origin: Some(&path),
origin: path.as_deref(),
fold: false,
annotations: vec![SourceAnnotation {
label: &friendly_str,
Expand Down
3 changes: 3 additions & 0 deletions forc/src/cli/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub struct Command {
/// Whether to compile using the original (pre- IR) pipeline.
#[clap(long)]
pub use_orig_asm: bool,
/// Whether to compile using the original (pest based) parser.
#[clap(long)]
pub use_orig_parser: bool,
/// Whether to compile to bytecode (false) or to print out the generated ASM (true).
#[clap(long)]
pub print_finalized_asm: bool,
Expand Down
3 changes: 3 additions & 0 deletions forc/src/cli/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub struct Command {
/// Whether to compile using the original (pre- IR) pipeline.
#[clap(long)]
pub use_orig_asm: bool,
/// Whether to compile using the original (pest based) parser.
#[clap(long)]
pub use_orig_parser: bool,
/// Whether to compile to bytecode (false) or to print out the generated ASM (true).
#[clap(long)]
pub print_finalized_asm: bool,
Expand Down
4 changes: 4 additions & 0 deletions forc/src/cli/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ pub struct Command {
#[clap(long)]
pub use_orig_asm: bool,

/// Whether to compile using the original (pest based) parser.
#[clap(long)]
pub use_orig_parser: bool,

/// Only craft transaction and print it out.
#[clap(long)]
pub dry_run: bool,
Expand Down
2 changes: 2 additions & 0 deletions forc/src/ops/forc_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn build(command: BuildCommand) -> Result<pkg::Compiled> {
path,
binary_outfile,
use_orig_asm,
use_orig_parser,
debug_outfile,
print_finalized_asm,
print_intermediate_asm,
Expand All @@ -24,6 +25,7 @@ pub fn build(command: BuildCommand) -> Result<pkg::Compiled> {

let config = pkg::BuildConfig {
use_orig_asm,
use_orig_parser,
print_ir,
print_finalized_asm,
print_intermediate_asm,
Expand Down
2 changes: 2 additions & 0 deletions forc/src/ops/forc_deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub async fn deploy(command: DeployCommand) -> Result<fuel_tx::ContractId> {
let DeployCommand {
path,
use_orig_asm,
use_orig_parser,
print_finalized_asm,
print_intermediate_asm,
print_ir,
Expand All @@ -38,6 +39,7 @@ pub async fn deploy(command: DeployCommand) -> Result<fuel_tx::ContractId> {
let build_command = BuildCommand {
path,
use_orig_asm,
use_orig_parser,
print_finalized_asm,
print_intermediate_asm,
print_ir,
Expand Down
1 change: 1 addition & 0 deletions forc/src/ops/forc_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub async fn run(command: RunCommand) -> Result<Vec<fuel_tx::Receipt>> {
let build_command = BuildCommand {
path: command.path,
use_orig_asm: command.use_orig_asm,
use_orig_parser: command.use_orig_parser,
print_finalized_asm: command.print_finalized_asm,
print_intermediate_asm: command.print_intermediate_asm,
print_ir: command.print_ir,
Expand Down
10 changes: 0 additions & 10 deletions parser/Cargo.toml

This file was deleted.

62 changes: 0 additions & 62 deletions parser/src/lexer.rs

This file was deleted.

7 changes: 0 additions & 7 deletions parser/src/lib.rs

This file was deleted.

Loading

0 comments on commit 6b8a46b

Please sign in to comment.