Skip to content

Commit

Permalink
antlr: Add PackageSize recognition.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvc94ch committed Jan 21, 2018
1 parent cea8c7d commit 3a6b1d3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/ElectroGrammar.g4
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,10 @@
*/

grammar ElectroGrammar;
import Alphabet;
import PackageSize, Units;

electro_grammar : capacitance;
electro_grammar : capacitor;

capacitance : NUMBER CPREFIX FARAD?;

fragment DIGIT: [0-9];
NUMBER: DIGIT* '.'? DIGIT+ | DIGIT+ '.'? DIGIT*;

fragment NANO: 'n' | N A N O;
fragment PICO: 'p' | P I C O;
fragment MICRO: 'u' | M I C R O;
CPREFIX: MICRO | NANO | PICO;

FARAD: F | F A R A D;
capacitor : capacitance package_size?;

WHITESPACE : [\p{White_Space}] -> skip;
33 changes: 33 additions & 0 deletions src/PackageSize.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
grammar PackageSize;
import Alphabet;

package_size: IMPERIAL_SIZE | METRIC_SIZE;

IMPERIAL_SIZE: '01005'
| '0201'
| '0805'
| '1008'
| '1206'
| '1806'
| '2010'
| '2512'
| IMPERIAL AMBIGUOUS_SIZE
| AMBIGUOUS_SIZE IMPERIAL;

METRIC_SIZE : '1005'
| '1608'
| '2012'
| '2520'
| '3216'
| '3225'
| '4516'
| '5025'
| '6332'
| METRIC AMBIGUOUS_SIZE
| AMBIGUOUS_SIZE METRIC;

AMBIGUOUS_SIZE : '0402'
| '0603';

METRIC : M | M E T R I C;
IMPERIAL : I | I M P E R I A L;
14 changes: 14 additions & 0 deletions src/Units.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
grammar Units;
import Alphabet;

capacitance: NUMBER CPREFIX FARAD?;

fragment DIGIT: [0-9];
NUMBER: DIGIT* '.'? DIGIT+ | DIGIT+ '.'? DIGIT*;

fragment NANO: 'n' | N A N O;
fragment PICO: 'p' | P I C O;
fragment MICRO: 'u' | M I C R O;
CPREFIX: MICRO | NANO | PICO;

FARAD: F | F A R A D;

0 comments on commit 3a6b1d3

Please sign in to comment.