diff --git a/common/imports.js b/common/imports.js index c6ca0298..1de91976 100644 --- a/common/imports.js +++ b/common/imports.js @@ -1,4 +1,3 @@ -const Prec = require('./precedence') const { commaSep1 } = require('./util') module.exports = { @@ -6,42 +5,36 @@ module.exports = { exported_import: ($) => seq('export', $._import_body), _import_body_constructor: (dialect) => ($) => dialect === 'tony' - ? prec.left( - Prec.Pattern, - seq( - choice( - field('default', alias($.identifier, $.identifier_pattern_name)), - seq( - optional( - seq( - field( - 'default', - alias($.identifier, $.identifier_pattern_name), - ), - ',', + ? seq( + choice( + field('default', alias($.identifier, $.identifier_pattern_name)), + seq( + optional( + seq( + field( + 'default', + alias($.identifier, $.identifier_pattern_name), ), + '@', ), - '{', - commaSep1( - field('import', choice($.import_identifier, $.import_type)), - ), - '}', ), + '{', + commaSep1( + field('import', choice($.import_identifier, $.import_type)), + ), + '}', ), - 'from', - field('source', $.raw_string), ), + 'from', + field('source', $.raw_string), ) : dialect === 'dtn' - ? prec.left( - Prec.Pattern, - seq( - '{', - commaSep1(field('import', $.import_type)), - '}', - 'from', - field('source', $.raw_string), - ), + ? seq( + '{', + commaSep1(field('import', $.import_type)), + '}', + 'from', + field('source', $.raw_string), ) : undefined, import_identifier: ($) => diff --git a/common/patterns.js b/common/patterns.js index a7c91dd8..9d8fe8e7 100644 --- a/common/patterns.js +++ b/common/patterns.js @@ -14,20 +14,17 @@ module.exports = { ), destructuring_pattern: ($) => - prec( - Prec.Pattern, - seq( - optional( - seq( - field('alias', alias($.identifier, $.identifier_pattern_name)), - '@', - ), - ), - field( - 'pattern', - choice($.struct_pattern, $.tuple_pattern, $.list_pattern), + seq( + optional( + seq( + field('alias', alias($.identifier, $.identifier_pattern_name)), + '@', ), ), + field( + 'pattern', + choice($.struct_pattern, $.tuple_pattern, $.list_pattern), + ), ), struct_pattern: ($) => diff --git a/common/precedence.js b/common/precedence.js index bae5fccf..a934e262 100644 --- a/common/precedence.js +++ b/common/precedence.js @@ -2,7 +2,6 @@ module.exports = { TaggedType: -1, SubtractionType: -1, UnionType: 0, - Assignment: 1, TypeHint: 1, CurriedType: 1, NamedInfixApplication: 1, diff --git a/common/terms.js b/common/terms.js index 4946a4a0..ba4b9ced 100644 --- a/common/terms.js +++ b/common/terms.js @@ -77,18 +77,13 @@ module.exports = { ), simple_assignment: ($) => - prec.right( - Prec.Assignment, - seq( + seq( field('pattern', $._assignable_pattern), ':=', field('value', $._simple_term), ), - ), compound_assignment: ($) => - prec.right( - Prec.Assignment, - seq( + seq( field('pattern', $._assignable_pattern), ':=', choice( @@ -96,7 +91,6 @@ module.exports = { seq($._indent, field('value', $._compound_term), $._dedent), ), ), - ), enum_: ($) => seq( diff --git a/tony/corpus/imports.txt b/tony/corpus/imports.txt new file mode 100644 index 00000000..807eb962 --- /dev/null +++ b/tony/corpus/imports.txt @@ -0,0 +1,66 @@ +================== +import +================== + +import { + a as b, + c, + Type as Type, + Type +} from 'source' +import x@{ a, b } from 'source' +import x from 'source' + +--- + +(program + import: (import + import: (import_identifier + name: (identifier_pattern_name) + as: (identifier_pattern_name)) + import: (import_identifier + as: (identifier_pattern_name)) + import: (import_type + name: (type) + as: (type)) + import: (import_type + as: (type)) + source: (raw_string)) + import: (import + default: (identifier_pattern_name) + import: (import_identifier + as: (identifier_pattern_name)) + import: (import_identifier + as: (identifier_pattern_name)) + source: (raw_string)) + import: (import + default: (identifier_pattern_name) + source: (raw_string))) + +================== +exported import +================== + +export { a, b } from 'source' +export x@{ a, b } from 'source' +export x from 'source' + +--- + +(program + import: (exported_import + import: (import_identifier + as: (identifier_pattern_name)) + import: (import_identifier + as: (identifier_pattern_name)) + source: (raw_string)) + import: (exported_import + default: (identifier_pattern_name) + import: (import_identifier + as: (identifier_pattern_name)) + import: (import_identifier + as: (identifier_pattern_name)) + source: (raw_string)) + import: (exported_import + default: (identifier_pattern_name) + source: (raw_string))) diff --git a/tony/corpus/program.txt b/tony/corpus/program.txt index 5056a607..792f3d91 100644 --- a/tony/corpus/program.txt +++ b/tony/corpus/program.txt @@ -17,58 +17,3 @@ hash bang line (program hashBangLine: (hash_bang_line)) -================== -import -================== - -import { - a as b, - c, - Type as Type, - Type -} from 'source' -import x, { a, b } from 'source' -import x from 'source' - ---- - -(program - import: (import - import: (import_identifier - name: (identifier_pattern_name) - as: (identifier_pattern_name)) - import: (import_identifier - as: (identifier_pattern_name)) - import: (import_type - name: (type) - as: (type)) - import: (import_type - as: (type)) - source: (raw_string)) - import: (import - default: (identifier_pattern_name) - import: (import_identifier - as: (identifier_pattern_name)) - import: (import_identifier - as: (identifier_pattern_name)) - source: (raw_string)) - import: (import - default: (identifier_pattern_name) - source: (raw_string))) - -================== -exported import -================== - -export x, { a, b } from 'source' - ---- - -(program - import: (exported_import - default: (identifier_pattern_name) - import: (import_identifier - as: (identifier_pattern_name)) - import: (import_identifier - as: (identifier_pattern_name)) - source: (raw_string)))